›
byrcsc/laravel-payrex · 1.x
Save a payment method with a setup intent for possible future charges.
A setup intent collects and stores a payment method without charging it. Your
application keeps a PayRex pm_... identifier; card details remain with
PayRex.
A PayRex customer is required:
use ByRcsc\LaravelPayrex\Facades\Payrex;
$customer = Payrex::customers()->create(
name: 'Ada Lovelace',
email: 'ada@example.com',
);
$intent = Payrex::setupIntents()->create(
customerId: $customer->id,
paymentMethods: ['card'],
description: 'Save a card for future purchases',
metadata: ['account_id' => '1042'],
);The full signature is:
create(
string $customerId,
array $paymentMethods = [],
?string $description = null,
?array $metadata = null,
array $options = [],
): SetupIntentPass the setup intent's clientSecret and Payrex::publicKey() to PayRex
Elements to complete payment-method collection in the browser.
$intent = Payrex::setupIntents()->retrieve('seti_...');
$intent = Payrex::setupIntents()->cancel('seti_...');Useful response properties include status, clientSecret, returnUrl,
usage, nextAction, paymentMethodId, customer, metadata, and raw.
redirectUrl() returns the documented redirect URL when the next action
contains one.
After the setup intent succeeds, read methods from the customer:
$methods = Payrex::customers()->listPaymentMethods(
id: $customer->id,
limit: 25,
);
foreach ($methods as $method) {
$method->id;
$method->type;
$method->details;
$method->billingDetails;
}Delete a saved method with both identifiers:
Payrex::customers()->deletePaymentMethod(
id: $customer->id,
paymentMethodId: 'pm_...',
);Customer sessions provide short-lived client secrets for PayRex embedded components that let customers manage saved methods:
$session = Payrex::customerSessions()->create($customer->id);
$session = Payrex::customerSessions()->retrieve($session->id);The CustomerSession contains clientSecret, customerId, customer,
components, expired, and expiredAt.
Saving a payment method does not itself create a subscription or authorize unattended charges. PayRex has no subscription resource. Confirm off-session support, account eligibility, and recurring-charge consent obligations with PayRex before relying on a stored payment method for automatic billing.