Skip to content

Commit 4bc6691

Browse files
authored
Subscriptions: fallback to first unpaid invoice (#12379)
There are subscriptions that have no paid invoices. ref https://read-the-docs.sentry.io/issues/6788746272/?project=161479&query=is%3Aunresolved&referrer=issue-stream
1 parent 99925fb commit 4bc6691

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

readthedocs/subscriptions/views.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,15 @@ def get_context_data(self, **kwargs):
140140
context["features"] = features.values()
141141
# When Stripe marks the subscription as ``past_due``,
142142
# it means the usage of RTD service for the current period/month was not paid at all.
143-
# Show the end date as the last period the customer paid.
143+
# Show the end date as the last period the customer paid,
144+
# or in case the subscription is not paid at all,
145+
# default to the first unpaid invoice end date.
144146
context["subscription_end_date"] = stripe_subscription.current_period_end
145147
if stripe_subscription.status == SubscriptionStatus.past_due:
146-
latest_paid_invoice = stripe_subscription.invoices.filter(paid=True).first()
148+
latest_paid_invoice = (
149+
stripe_subscription.invoices.filter(paid=True).first()
150+
or stripe_subscription.invoices.filter(paid=False).last()
151+
)
147152
context["subscription_end_date"] = latest_paid_invoice.period_end
148153

149154
return context

0 commit comments

Comments
 (0)