Developer Tools

Pagination

List operations return one cursor page at a time. Walk to the next page yourself, or let the lazy iteration helper fetch pages as you consume items.

Every demonstration here makes a real PayMongo API call in test mode. Nothing is simulated, and no real money moves.

  • A list returns a CursorPage: its items, whether PayMongo has more, and nextPage(), which repeats the request with the after cursor set to the last item's id.
  • lazy() yields items across page boundaries and fetches the next page only when the items run out, so take() stops the requests early.
  • Payouts page by cursor tokens instead (CursorTokenPage, with the same nextPage() and lazy()), and webhook endpoints come back as a plain array.
  • PayMongo cannot filter a list to the Playground's payments, so this walks the whole test account and hides what the Playground did not create. On a busy account the first pages may hold none of them.

Page by page

PHP
use Luigel\Paymongo\Facades\Paymongo;

public function pageByPage(): array
{
    $pages = [];
    $page = Paymongo::payments()->list(['limit' => 3]);

    while ($page !== null && count($pages) < 3) {
        $pages[] = $page;
        $page = $page->nextPage();
    }

    return $pages;
}

Lazily across pages

PHP
use Luigel\Paymongo\Facades\Paymongo;

public function lazily(): array
{
    return Paymongo::payments()->list(['limit' => 3])
        ->lazy()
        ->take(9)
        ->all();
}
Sign in to run this example