›
›
›
  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

Customers.

Create and manage PayRex customer records for repeat payers.

Customers group payment methods, payments, and billing statements around one payer.

Create a customer

use ByRcsc\LaravelPayrex\Enums\Currency;
use ByRcsc\LaravelPayrex\Facades\Payrex;

$customer = Payrex::customers()->create(
    name: 'Ada Lovelace',
    email: 'ada@example.com',
    currency: Currency::PHP,
    billingDetails: [
        'phone' => '+639171234567',
        'address' => [
            'line1' => '123 Example Street',
            'city' => 'Makati',
            'postal_code' => '1200',
            'country' => 'PH',
        ],
    ],
    billingStatementPrefix: 'ACME',
    nextBillingStatementSequenceNumber: '1001',
    metadata: ['account_id' => '1042'],
);

The complete signature is:

create(
    string $name,
    string $email,
    Currency $currency = Currency::PHP,
    ?array $billingDetails = null,
    ?string $billingStatementPrefix = null,
    ?string $nextBillingStatementSequenceNumber = null,
    ?array $metadata = null,
    array $options = [],
): Customer

Retrieve and update

$customer = Payrex::customers()->retrieve('cus_...');

$customer = Payrex::customers()->update(
    id: $customer->id,
    name: 'Ada Byron',
    email: 'ada@example.com',
    metadata: ['account_id' => '1042'],
);

update() accepts the same customer fields as create, except the ID is first and every other field is optional.

Delete a customer

$deleted = Payrex::customers()->delete('cus_...');

$deleted->id;
$deleted->deleted; // true

PayRex can return a deleted customer from retrieve() as an HTTP 200 tombstone instead of a 404:

$customer = Payrex::customers()->retrieve('cus_...');

if ($customer->isDeleted()) {
    // Remove or replace the stale local association.
}

Do not infer that any HTTP 200 customer is active without checking isDeleted() when deletion could have happened outside your application.

List customers

$page = Payrex::customers()->list(limit: 25);

foreach (Payrex::customers()->autoPaging(limit: 100) as $customer) {
    // ...
}

$customers = Payrex::customers()->paginate(perPage: 20);

See pagination for manual cursors and Laravel links.

Saved payment methods

$methods = Payrex::customers()->listPaymentMethods(
    id: $customer->id,
    limit: 25,
);

$deleted = Payrex::customers()->deletePaymentMethod(
    id: $customer->id,
    paymentMethodId: 'pm_...',
);

listPaymentMethods() also accepts before, after, and options.

Customer sessions

Create a short-lived session for PayRex embedded components:

$session = Payrex::customerSessions()->create($customer->id);

$session = Payrex::customerSessions()->retrieve($session->id);

Only the customer-session client secret and public key should be exposed to the browser. The server secret key must remain private.

Customer response

The Customer object includes:

$customer->id;
$customer->name;
$customer->email;
$customer->currency;
$customer->billing;
$customer->billingStatementPrefix;
$customer->nextBillingStatementSequenceNumber;
$customer->deleted;
$customer->livemode;
$customer->metadata;
$customer->createdAt;
$customer->updatedAt;
$customer->raw;

What to read next

  • Eloquent customers to store the PayRex customer ID on an application model.
  • Setup intents to save a payment method for the customer.
  • Billing statements to bill the customer with itemized line items.
PreviousPayments and refundsNextEloquent customers

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

View source

On this page

  1. Create a customer
  2. Retrieve and update
  3. Delete a customer
  4. List customers
  5. Saved payment methods
  6. Customer sessions
  7. Customer response
  8. What to read next