Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1319 When showing subscriber failed invoices, don't check decline code of paid invoices #1320

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading