Browse documentationOpen

byrcsc/laravel-payrex · 1.x

Setup intents.

Save a customer payment method with PayRex without taking a payment, then manage the resulting token safely.

A setup intent collects and stores a payment method without charging it. Your application keeps a PayRex pm_... identifier; card details remain with PayRex.

Create a setup intent

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 = [],
): SetupIntent

Pass the setup intent's clientSecret and Payrex::publicKey() to PayRex Elements to complete payment-method collection in the browser.

Retrieve or cancel

$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.

List saved payment methods

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

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.

Recurring and off-session charges

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.

Laravel PayRex is an unofficial community SDK and is not affiliated with PayRex.

View source