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

Pagination.

Read one result page, stream all pages, or build a Laravel cursor paginator.

PayRex list endpoints use resource IDs as before and after cursors. Laravel PayRex provides three levels of pagination: one response page, a generator across every page, and Laravel's CursorPaginator.

The following resources support all three forms:

  • checkout sessions;
  • customers;
  • billing statements; and
  • webhook endpoints.

Customer payment methods and payout transactions return a single Listing page and accept manual cursor arguments.

Retrieve one page

Use list() when the application controls the cursor:

$page = Payrex::customers()->list(
    limit: 25,
    after: $request->string('after')->toString() ?: null,
);

foreach ($page as $customer) {
    // ...
}

$page->data;
$page->hasMore;
$page->first();
$page->collect();
$page->isEmpty();
count($page);

The raw response is available on $page->raw. To construct the next manual cursor, read the final resource ID when hasMore is true:

$last = $page->data[array_key_last($page->data)] ?? null;
$nextAfter = $page->hasMore ? $last?->id : null;

Walk every page

autoPaging() returns a lazy generator. It fetches another page only as the loop reaches it:

foreach (Payrex::customers()->autoPaging(limit: 100) as $customer) {
    SyncCustomer::dispatch($customer->id);
}

This is appropriate for jobs and console commands. Avoid turning a large generator into an array unless the complete result comfortably fits in memory.

Laravel cursor pagination

paginate() bridges a PayRex list to Laravel's cursor paginator:

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

return view('customers.index', compact('customers'));

In Blade:

@foreach ($customers as $customer)
    <p>{{ $customer->name }}</p>
@endforeach

{{ $customers->links() }}

The default query parameter is cursor. Supply a custom name or path when a page contains more than one paginator:

$customers = Payrex::customers()->paginate(
    perPage: 20,
    cursorName: 'customers',
    path: route('customers.index'),
);

The package uses PayRex's has_more value instead of requesting one extra row, so the outbound limit remains exactly the requested page size.

Passing filters

Use the trailing options array for documented list filters not modeled by a named parameter:

$page = Payrex::checkoutSessions()->list(
    limit: 25,
    options: [
        'status' => 'active',
        'customer_reference_id' => 'acct_1042',
    ],
);

The same options are sent on every page of autoPaging() and paginate().

What to read next

  • Client and resources to see which resources support each pagination form.
  • Customers for customer list examples.
  • Managing endpoints for paginated webhook endpoints.
PreviousErrors and retriesNextPayment intents

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

View source

On this page

  1. Retrieve one page
  2. Walk every page
  3. Laravel cursor pagination
  4. Passing filters
  5. What to read next