Reputation: 387
I have a subscription with proration. So for the first months, the client is charged 10 euros and for the last month the client is charged 9.99. Sometimes, some coupons are applied and the client is charged 5 euros. How can I get the total of all the amounts paid by this customer for this subscription? I need to get the sum of 10 x (number of months) + 9.99 + 5 x (number of months where coupons was applied).. In other words, I need to get all the amount of all the money he previously paid until now.
Upvotes: 4
Views: 2166
Reputation: 41
Here is the method to get the list of all the invoices that have status paid:
def get_all_invoices(start_timestamp, end_timestamp):
all_invoices = []
has_more = True
starting_after = None
while has_more:
params = {
'created': {
'gte': start_timestamp,
'lt': end_timestamp,
},
'status': 'paid',
'limit': 100
}
if starting_after:
params['starting_after'] = starting_after
invoices = stripe.Invoice.list(**params)
all_invoices.extend(invoices['data'])
has_more = invoices['has_more']
if has_more:
starting_after = invoices['data'][-1]['id']
return all_invoices
Upvotes: 0
Reputation: 1587
You can retrieve all the invoices for a given Customer
https://stripe.com/docs/api/invoices/list. If you want the invoices for a particular Subscription
, pass in the subscription
parameter.
You can then iterate through all the invoices and sum the amounts paid. Note that you can only retrieve up to 100 invoices.
Upvotes: 2