From ecfec9dd21b2d9572ada24f674c0845c3b582bc5 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 20 Apr 2019 08:57:13 +0200 Subject: [PATCH] Handle invoice item in line items also --- utils/stripe_utils.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/utils/stripe_utils.py b/utils/stripe_utils.py index 4b4a157e..a3682514 100644 --- a/utils/stripe_utils.py +++ b/utils/stripe_utils.py @@ -139,6 +139,14 @@ class StripeUtils(object): ) has_more_invoices = invoices.has_more for invoice in invoices.data: + sub_ids = [] + for line in invoice.lines.data: + if line.type == 'subscription': + sub_ids.append(line.id) + elif line.type == 'invoiceitem': + sub_ids.append(line.subscription) + else: + sub_ids.append('') invoice_details = { 'created': invoice.created, 'receipt_number': invoice.receipt_number, @@ -156,9 +164,7 @@ class StripeUtils(object): 'lines_meta_data_csv': ','.join( [line.metadata.VM_ID if hasattr(line.metadata, 'VM_ID') else '' for line in invoice.lines.data] ), - 'subscription_ids_csv': ','.join( - [line.id if line.type == 'subscription' else '' for line in invoice.lines.data] - ), + 'subscription_ids_csv': ','.join(sub_ids), 'line_items': invoice.lines.data } starting_after = invoice.id