›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-payrex
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Client and resources
  • Data objects and enums
  • Errors and retries
  • Pagination

Accepting payments

  • Payment intents
  • Checkout sessions
  • Setup intents
  • Payments and refunds

Customers and billing

  • Customers
  • Eloquent customers
  • Billing statements
  • Payouts

Webhooks

  • Receiving webhooks
  • Events and listeners
  • Managing endpoints

Advanced usage

  • Testing
  • Security and operations
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Client and resources
  • Data objects and enums
  • Errors and retries
  • Pagination

Accepting payments

  • Payment intents
  • Checkout sessions
  • Setup intents
  • Payments and refunds

Customers and billing

  • Customers
  • Eloquent customers
  • Billing statements
  • Payouts

Webhooks

  • Receiving webhooks
  • Events and listeners
  • Managing endpoints

Advanced usage

  • Testing
  • Security and operations
  • Troubleshooting

byrcsc/laravel-payrex · 1.x

Setup intents.

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.

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.

What to read next

  • Customers to create the customer required by a setup intent.
  • Payment intents to charge an attached payment method.
  • Billing statements to build application-managed billing cycles.
PreviousCheckout sessionsNextPayments and refunds

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

View source

On this page

  1. Create a setup intent
  2. Retrieve or cancel
  3. List saved payment methods
  4. Customer sessions
  5. Recurring and off-session charges
  6. What to read next