Pagination
Cursors, not page numbers.
ts
let page = await sp.paymentIntents.list({ limit: 100 });
const all = [...page.data];
while (page.has_more) {
page = await sp.paymentIntents.list({
limit: 100,
starting_after: page.data[page.data.length - 1].id,
});
all.push(...page.data);
}Why not page numbers
Payments arrive constantly, and every new one shifts an offset-based page by one. Page two would skip a row or repeat one, quietly, and the row most likely to be affected is the newest — which is the one you were looking for. A cursor is stable regardless of what arrives while you are paging.
Filtering
Lists are newest first. Payments can be filtered by status, by when they were created, by customer, and by your own metadata:
ts
await sp.paymentIntents.list({
status: "succeeded",
metadata: { shop_id: "scuba-sensation" },
created_gte: Math.floor(Date.now() / 1000) - 86_400,
});limit is between 1 and 100. Asking for more is an error rather than a silent clamp, so you never quietly get fewer rows than you planned for.