Guide

How to handle the Stripe failed payment webhook and test it with decline cards

What Retivo sells: a one-time $490 report that shows where your Stripe revenue leaks: failed payments, unconverted trials, cancellations and downgrades in $/month, from a read-only Stripe key, in 48 hours.
Get the report

invoice.payment_failed is the Stripe event that tells you a customer's payment just failed. Every failed renewal you do not act on is a paying customer on the way out, so this handler is where recovered revenue starts. This guide covers what the event means, what to do when it arrives, and how to test it with Stripe's decline cards before a real customer hits it. Facts are from Stripe's documentation, read 27 November 2026.

What does invoice.payment_failed mean?

Stripe sends it when a payment for an invoice fails. For subscriptions that is usually a renewal: the card on file was charged and declined. Stripe also sends invoice.updated on every attempt, with status still open after a failure. Source: Stripe docs, Using webhooks with subscriptions.

Two fields on the invoice matter most:

What happens to the subscription?

What should my handler do?

Stripe lists these actions for a failed payment: notify the customer, collect new payment details, update the default payment method on the subscription, and consider Smart Retries. In practice the handler is short:

  1. Verify the signature and return 2xx fast. Do the work after you respond.
  2. Look at the PaymentIntent status. requires_payment_method means you need a new card. requires_action means the customer must complete authentication, and invoice.payment_action_required is the event for that case.
  3. Tell the customer once per failure, with a link to update the card. If Stripe's own failed payment emails are on, do not send a second email for the same attempt.
  4. Do not cut access on the first failure. Retries often recover the payment. Decide access on customer.subscription.updated when the status changes, not on the failure event.
  5. Make it idempotent. Stripe does not promise event order, and the same event can arrive twice. Key on the event ID.

Which declines retries can never fix, and how the retry schedule works, is in how Stripe Smart Retries work.

Which Stripe test cards make a payment fail?

All of these work only in test mode or a sandbox. Source: Stripe docs, Testing.

What you testCard numberPaymentMethoddecline_code
Renewal fails after the card was saved4000000000000341pm_card_chargeCustomerFailcharge fails
Generic decline4000000000000002pm_card_visa_chargeDeclinedgeneric_decline
Insufficient funds4000000000009995pm_card_visa_chargeDeclinedInsufficientFundsinsufficient_funds
Lost card (hard decline)4000000000009987pm_card_visa_chargeDeclinedLostCardlost_card
Stolen card (hard decline)4000000000009979pm_card_visa_chargeDeclinedStolenCardstolen_card
Expired card4000000000000069pm_card_chargeDeclinedExpiredCarderror code expired_card
Too many attempts4000000000006975pm_card_visa_chargeDeclinedVelocityLimitExceededcard_velocity_exceeded
3D Secure on a subscription4000002760003184authentication

The first card is the one for renewals. Most decline cards fail when you try to save them, so you never get a subscription to test. 4000000000000341 attaches to the customer fine and fails only when Stripe charges it.

How do I test a failed renewal end to end?

Stripe's own recipe (source: Stripe docs, Test Billing integrations):

  1. Set 4000000000000341 as the customer's default payment method.
  2. Create a subscription with a short trial, so the first charge happens when the trial ends.
  3. Let the trial end. The invoice finalizes, the charge fails and your endpoint receives invoice.payment_failed.
  4. Check the invoice and subscription statuses, and that your retry and customer emails behave as configured.

For a quarterly or annual renewal, use test clocks to move simulated time forward instead of waiting. To run the endpoint on your laptop, use the Stripe CLI, for example stripe listen --forward-to localhost:4242/webhook. Events from stripe trigger carry made-up data, so they test one handler, not the whole subscription flow.

How do I know my handler is working in production?

Count it. Compare failed invoices with those later paid: that is your failed payment recovery rate. If it does not move after you ship the handler, the emails are not reaching people or the link does not work. To see what each lost payment costs, use the failed payment calculator.

Retivo is our product. Its $490 Revenue Leak Report reads your invoice history from a restricted read-only Stripe key and shows in dollars how many failed payments were never recovered, without changing anything in your account.

Want your own numbers?

The Revenue Leak Report puts failed payments, unconverted trials, cancellations and downgrades in dollars per month, read from a restricted read-only Stripe key. $490, delivered within 48 hours of receiving the key. Nothing in your account is changed.

Get the Revenue Leak Report - $490 See a sample (synthetic data)