Benjamin
Benjamin

Reputation: 3826

Stripe - Get the LAST customer invoice

Is there a way to filter the invoice result by the last invoice that was generated for a particular customer?

Going through the Stripe documentation I can see it is possible to get an upcoming invoice, but I can't find a way to get the last generated one.

Upvotes: 3

Views: 2312

Answers (2)

Matt Roberts
Matt Roberts

Reputation: 26877

If you're using stripe billing, then the subscription contains a LatestInvoice - so you can either use the latestInvoiceId, or you can get the subscription and expand it to also return the latest invoice in one hit.

Upvotes: 3

duck
duck

Reputation: 5470

You can use https://stripe.com/docs/api/invoices/list

The invoices are returned sorted by creation date, with the most recently created invoices appearing first.

So, if you want the most recent for a given customer

invoices = stripe.Invoice.list(customer="cus_xxxyyyzzz")
# first in the list should be the most recent
print(invoices.data[0])

Upvotes: 2

Related Questions