Menu

How to Handle Stripe's invoice.payment_failed Webhook (Without Breaking Dunning)
📰

How to Handle Stripe's invoice.payment_failed Webhook (Without Breaking Dunning)

DEV Community: typescript·Henrique Miguel·12 days ago
#95hanCyf
#devtotypescript#devto#dev#invoice#stripe
Long article (302 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.