Reputation: 3826
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
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
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