Skip to content

Commit

Permalink
Fix #1319 When showing subscriber failed invoices, don't check declin…
Browse files Browse the repository at this point in the history
…e code of paid invoices
  • Loading branch information
chrisjsimpson committed Mar 10, 2024
1 parent a5cf46e commit 211565b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions subscribie/blueprints/subscriber/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
)
Expand Down
14 changes: 9 additions & 5 deletions subscribie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 211565b

Please sign in to comment.