diff --git a/subscribie/blueprints/subscriber/__init__.py b/subscribie/blueprints/subscriber/__init__.py index 402f22ea..b3c63183 100644 --- a/subscribie/blueprints/subscriber/__init__.py +++ b/subscribie/blueprints/subscriber/__init__.py @@ -222,7 +222,7 @@ def account(): stripe_publishable_key = get_stripe_publishable_key() stripe_default_payment_method = None stripe_session = None - bad_invoices = g.subscriber.bad_invoices() + bad_invoices = g.subscriber.bad_invoices(skipFetchDeclineCode=False) # Add hosted_invoice_url attribute to all bad invoices try: @@ -380,7 +380,7 @@ def subscriber_view_failed_invoices(): no further *automated* payment collections for this invoice. """ get_stripe_invoices() - bad_invoices = g.subscriber.bad_invoices() + bad_invoices = g.subscriber.bad_invoices(skipFetchDeclineCode=False) return render_template( "subscriber/subscriber_failed_invoices.html", bad_invoices=bad_invoices ) diff --git a/subscribie/models.py b/subscribie/models.py index 15acb012..f1d558d3 100644 --- a/subscribie/models.py +++ b/subscribie/models.py @@ -230,9 +230,13 @@ def invoices(self, refetchCachedStripeInvoices=False, skipFetchDeclineCode=False for invoice in invoices: stripeRawInvoice = json.loads(invoice.stripe_invoice_raw_json) setattr(invoice, "created", stripeRawInvoice["created"]) - # Get stripe_decline_code if possible + # Get stripe_decline_code if possible, ignoring paid invoices try: - if skipFetchDeclineCode is not True: + if ( + skipFetchDeclineCode is not True + # No point checking decline_code of a paid invoice + and invoice.status != "paid" + ): payment_intent_id = stripeRawInvoice["payment_intent"] stripe_decline_code = stripe.PaymentIntent.retrieve( payment_intent_id, @@ -275,10 +279,10 @@ def failing_invoices(self): failing_invoices.append(invoice) return failing_invoices - def bad_invoices(self): + def bad_invoices(self, skipFetchDeclineCode=False): """List Subscribers failing and failed invoices""" bad_invoices = [] - invoices = self.invoices() + invoices = self.invoices(skipFetchDeclineCode=skipFetchDeclineCode) for invoice in invoices: if stripe_invoice_failed(invoice) or stripe_invoice_failing( invoice @@ -659,7 +663,7 @@ class Plan(database.Model, HasArchived): ) def __getattribute__(self, name): - if name == 'trial_period_days': + if name == "trial_period_days": """ Ensure all shops return an int (and not None) for trial_period_days