Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kryptonit3's avatar

How do you paginate a users stripe invoices?

On stripe, my test user has 18 invoices. When I grab the invoices with the Cashier method $this->auth->user()->invoices() it only returns 10.

Has anyone had any experience paginating the invoices in the controller/view?

I am not sure where to start. I am sure it has something to do with passing a $parameter with starting_after to the api.

Anyone have any working method for this?

0 likes
8 replies
MattCroft's avatar

Looks like it returns 10 by default, also looks like you can up this by passing the limit param.

I can't see any way to get a total from the github code, looks like the total param is wiped away because taylor formats the invoices into his own class.

Would be ideal if Taylor could alter this to return an Invoice collection maybe.

1 like
Kryptonit3's avatar

@JeffreyWay - I have yet to reach 10+ invoices on this site. But how do you accomplish this? Have you found a way to paginate invoices?

Poxucis's avatar

It shouldn't be $this->auth->user()->invoices to return all of users invoices? Without brackets at the end.

Kryptonit3's avatar

invoices() is a method provided by the Billable trait. The main issue here is how do we paginate and progress through the stripe API data with the current implementation of Stripe with the Cashier package?

1 like
Kryptonit3's avatar

Anyone figure this out? I would have thought Stripe was a widely used payment gateway in the Laravel community.

stevebauman's avatar

I personally don't use Stripe, however the $parameters argument is passed directly to Stripes Customer object. Looking at their API, it looks like you can specify params such as ending_before and starting_after to perform pagination:

https://stripe.com/docs/api#list_customer_invoices

EDIT: Woops didn't see your starting post, you already knew this. Have you played with sending those parameters? You could always supply a ending_before and starting_after params to encompass their entire subscription life, and then you can cache and paginate the result manually so you wouldn't have to keep sending large requests?

There's always the allInvoices() method as well, have you tried that?

https://github.com/laravel/cashier/blob/5.0/src/Laravel/Cashier/StripeGateway.php#L288

socieboy's avatar

I don't know if you make it work but I do.

$invoices = $this->user->invoices();
$invoices = new Paginator($invoices, 15);

Please or to participate in this conversation.