Keep Pro through failed-payment retries + dunning emails - #2074
Merged
Conversation
…etry window A past_due subscription previously lost Pro on the first failed charge and the billing card fell back to the Upgrade to Pro state as if no subscription existed. past_due now retains entitlement until Stripe exhausts retries and moves the sub to canceled/unpaid, and the billing card shows an explicit payment-failed state pointing at the payment method fix.
Handle invoice.payment_failed for renewals and plan changes: email on the first failure and the final retry (idempotent via Resend idempotency keys), linking to billing settings. Also compute inviteQuota from all entitled subscription statuses (active, trialing, past_due) so an org's seats no longer collapse to zero while Stripe retries the card. Note: the Stripe webhook endpoint must have invoice.payment_failed added to its enabled events after this deploys; it currently only sends checkout and subscription events.
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Failed payments currently get the harshest possible treatment, which makes them a meaningful and avoidable source of churn:
userIsPro()excludedpast_due, so access dropped on the first failed charge with no grace window.invoice.payment_failedwas not in the webhook's relevant events (the handler 400s it), and no billing email of any kind existed.What
past_dueretains Pro entitlement (userIsPro,isAiGenerationEnabledForUser) until Stripe exhausts retries and moves the sub tocanceled/unpaid, which is when access actually drops. The grace window is therefore bounded by the Stripe retry schedule, no timer of our own.getSubscriptionDetailspasses past_due through.payment-failedemail template (matches existing email styling); webhook handlesinvoice.payment_failedforsubscription_cycle/subscription_updateinvoices, emailing on the first failure and the final retry only. Idempotent via Resend idempotency keys, so Stripe webhook retries can't double-send.Activation (after deploy)
The production Stripe webhook endpoint must have
invoice.payment_failedadded to its enabled events once this is live, otherwise the dunning path never fires. Deliberately not done yet so events don't hit an endpoint that 400s them.Testing
pro-entitlement-grace.test.ts), full apps/web unit suite run: 1290 passed, 1 pre-existing unrelated failure (slack-app-manifest.test.tscolor constant, also failing on main).tscclean on apps/web and packages/utils.Immediate effect on merge
Existing past_due subscriptions regain Pro access and see the fix-your-card state instead of the upgrade pitch.