From e25ed77538b13f40b9537941d3780341284973c4 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 25 Feb 2020 11:13:26 +0530 Subject: [PATCH 1/2] Handle invoice for no stripe error --- hosting/views.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 17af51fd..bffaa072 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1297,9 +1297,12 @@ class InvoiceListView(LoginRequiredMixin, TemplateView): except CustomUser.DoesNotExist as dne: logger.debug("User does not exist") cu = self.request.user - invs = stripe.Invoice.list(customer=cu.stripecustomer.stripe_id, - count=100) - paginator = Paginator(invs.data, 10) + if cu.stripecustomer: + invs = stripe.Invoice.list(customer=cu.stripecustomer.stripe_id, + count=100) + else: + invs = [] + paginator = Paginator(invs.data if len(invs) > 0 else [], 10) try: invs_page = paginator.page(page) except PageNotAnInteger: @@ -1308,11 +1311,14 @@ class InvoiceListView(LoginRequiredMixin, TemplateView): invs_page = paginator.page(paginator.num_pages) else: try: - invs = stripe.Invoice.list( - customer=self.request.user.stripecustomer.stripe_id, - count=100 - ) - paginator = Paginator(invs.data, 10) + if self.request.user.stripecustomer: + invs = stripe.Invoice.list( + customer=self.request.user.stripecustomer.stripe_id, + count=100 + ) + else: + invs = [] + paginator = Paginator(invs.data if len(invs) > 0 else [], 10) try: invs_page = paginator.page(page) except PageNotAnInteger: From 56d3d4e7fe25272443f14e1e12787484abad2661 Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 25 Feb 2020 11:50:39 +0530 Subject: [PATCH 2/2] Check invoice list from stripe only if we have a stripecustomer --- hosting/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index bffaa072..0cf555f2 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1297,7 +1297,7 @@ class InvoiceListView(LoginRequiredMixin, TemplateView): except CustomUser.DoesNotExist as dne: logger.debug("User does not exist") cu = self.request.user - if cu.stripecustomer: + if hasattr(cu, 'stripecustomer'): invs = stripe.Invoice.list(customer=cu.stripecustomer.stripe_id, count=100) else: @@ -1311,7 +1311,7 @@ class InvoiceListView(LoginRequiredMixin, TemplateView): invs_page = paginator.page(paginator.num_pages) else: try: - if self.request.user.stripecustomer: + if hasattr(self.request.user, "stripecustomer"): invs = stripe.Invoice.list( customer=self.request.user.stripecustomer.stripe_id, count=100