Fetch invoices whose date is greater than given date only

This commit is contained in:
PCoder 2019-04-13 12:54:57 +02:00
parent 9ee21b9bc3
commit 061ef7d036
2 changed files with 4 additions and 4 deletions

View file

@ -35,7 +35,7 @@ class Command(BaseCommand):
all_invoices_response = stripe_utils.get_all_invoices( all_invoices_response = stripe_utils.get_all_invoices(
user.stripecustomer.stripe_id, user.stripecustomer.stripe_id,
created=created_gt created_gt=created_gt
) )
if all_invoices_response['error'] is not None: if all_invoices_response['error'] is not None:
self.stdout.write(self.style.ERROR(all_invoices_response['error'])) self.stdout.write(self.style.ERROR(all_invoices_response['error']))

View file

@ -123,19 +123,19 @@ class StripeUtils(object):
return card_details return card_details
@handleStripeError @handleStripeError
def get_all_invoices(self, customer_id, created): def get_all_invoices(self, customer_id, created_gt):
return_list = [] return_list = []
has_more_invoices = True has_more_invoices = True
starting_after = False starting_after = False
while has_more_invoices: while has_more_invoices:
if starting_after: if starting_after:
invoices = stripe.Invoice.list( invoices = stripe.Invoice.list(
limit=10, customer=customer_id, created=created, limit=10, customer=customer_id, created={'gt': created_gt},
starting_after=starting_after starting_after=starting_after
) )
else: else:
invoices = stripe.Invoice.list( invoices = stripe.Invoice.list(
limit=10, customer=customer_id, created=created limit=10, customer=customer_id, created={'gt': created_gt}
) )
has_more_invoices = invoices.has_more has_more_invoices = invoices.has_more
for invoice in invoices.data: for invoice in invoices.data: