Every SaaS billing integration eventually hits the same milestone: a customer's renewal fails, and you decide to listen to Stripe's invoice.payment_failed webhook to send a recovery email.
The webhook handler takes 20 minutes to write. The edge cases take months to discover.
1. Extract the actual decline_code
When invoice.payment_failed fires, don't treat all failures the same way. Inspect the underlying payment_intent.last_payment_error.decline_code:
const event = stripe.webhooks.constructEvent(rawBody, sig, webhookSecret); if (event.type === "invoice.payment_failed") { const invoice = event.data.object; if (!invoice.subscription) return; // Branch on soft vs. hard decline codes: // - Hard declines (expired_card, lost_card, authentication_required): email on day 0 // - Soft declines (insufficient_funds, do_not_honor): wait 48h for Smart Retries } If you want a zero-dependency TypeScript helper that classifies 45+ Stripe decline_code values into soft vs. hard, I open-sourced it here: stripe-decline-classifier on GitHub.
2. Four traps that break DIY dunning
- Duplicate emails on Smart Retries: Stripe fires
invoice.payment_failedon every retry attempt. Without per-invoice state tracking, customers get emailed 4 times for one temporaryinsufficient_fundsdecline. - Forgetting to cancel queued emails: You also need to listen to
invoice.paidandcustomer.subscription.deletedto stop follow-ups when a payment succeeds or cancels. - 3D Secure (
authentication_required): Retrying won't pass SCA. Customers need a hosted confirmation link, not a generic card-update form. - No expiring-card visibility:
invoice.payment_failedonly fires after a payment fails.
If you want to see how much MRR is currently stuck in soft vs. hard declines (and cards expiring in the next 30–90 days) without writing webhook queues first, you can run a free read-only 90-day scan at SavedMRR or check the 45+ Stripe decline codes reference.

