← Back to library

Route failed card payments by the real decline reason

u/Beneficial-Toe-3492 on r/n8n shared the front end of a failed-payment recovery workflow, with JSON included for others to reuse. Stripe decline codes route different retries, customer emails and dunning paths instead of one blunt card-failed message for every single case.

  • OutcomeWhen a subscription payment fails, look up why and route it: retry after payday, ask the customer to update the card, or stop.
  • SetupAn afternoon+
  • LevelAdvanced
  • Creditu/Beneficial-Toe-3492 on r/n8n
View original
Works with
n8n

Published Oct 20, 2026Updated Oct 20, 2026AI dry run on sample input: passed Oct 20, 2026Source verified Oct 24, 2026

When should you use it?

  • Subscription revenue billed through Stripe
  • Failed payments are retried on a fixed schedule
  • Customers churn because a card expired

Not for: Retrying cards reported lost or stolen; Businesses without someone to own the workflow

What do you need, and what do you get?

You need

  • Stripe webhook for failed invoices
  • A Stripe credential with read access
  • Your retry and messaging policy

You get

  • A routing decision per failed payment
  • Suggested next action
  • A flag for whether Stripe will retry

How does it work, step by step?

  1. Receive and dedupeWebhook in, drop event IDs you have already handled.
  2. Fetch the real reasonLook up the payment for its decline code.
  3. RouteHard declines stop; insufficient funds wait; authentication issues go to the customer.
  4. Avoid double retriesCheck Stripe's own retry settings before adding yours.

The prompt

Our own prompt, inspired by u/Beneficial-Toe-3492 on r/n8n and written to work in n8n. Values in lime are placeholders.

Fill in the blanks (optional; the copied prompt uses your values)

Prompt4 variables
Help me design failed-payment handling for {business} (billing via Stripe; Smart Retries: {smart_retries_on}).
1) Build a table of common decline codes, including {extra_codes}: for each give a route (STOP, RETRY_AFTER_PAYDAY, RETRY_SOON, ASK_CUSTOMER), the reason, and how many retries at most.
2) Unknown codes or failed lookups: route to ALERT_STAFF, never to retry.
3) Explain how to avoid retrying twice if Stripe also retries.
4) Write a short, friendly customer email for ASK_CUSTOMER and one for a final notice before cancellation. No threats, no fees not in our terms: {terms}.
Do not invent Stripe fields; mark anything I should confirm in the Stripe docs.

Inspired by u/Beneficial-Toe-3492 on r/n8n: Stripe's failed payment webhook doesn't give you the decline code, so I made a small workflow that does. The prompt above is written by playbooks.bot in our own words; nothing from the original is quoted.

What can go wrong?

  • If the lookup fails, your own errors look like customer declines; fail loudly instead of defaulting to retry.
  • Stripe's newer API versions moved the payment reference on invoices; check your webhook's pinned version.

Our take

We like this post because it is honest and specific: a real snag in a real billing integration, a small fix, and the JSON to prove it. The comments made it better, and we folded their corrections into our version. Don't let a failed lookup default to a retry path, because your own outages will look like customer declines. Check which Stripe API version your webhook uses, since newer versions moved the payment reference. Make sure Stripe's built-in retries aren't doubling up with yours. The routing should stay deterministic code; AI earns its place in drafting the policy table and the customer emails for each route, where tone matters. In our dry run with eight sample decline codes, our prompt produced a routing table that stopped retries for lost, stolen and expired cards, scheduled insufficient-funds retries after typical paydays, sent authentication failures to a customer email, and treated unknown codes as an alert for a person.

Where the time goes back: Pointless retries stop, and the customers who need to update a card hear about it the same day instead of after the subscription lapses.

FAQ

Why does the decline code matter?
Retrying an expired or stolen card never works and can get you flagged, while a card declined for insufficient funds often succeeds a few days later. The right action depends on the reason.
Where does AI come in?
The routing is deterministic code. Our prompt uses AI to design the policy and write the customer messages for each route, which is where judgment and tone matter.

Source and credit

Inspired by u/Beneficial-Toe-3492 on r/n8n. We describe the idea in our own words, link to the original, and wrote the prompt ourselves; nothing is quoted.

Inspired by
Stripe's failed payment webhook doesn't give you the decline code, so I made a small workflow that does
Creator
u/Beneficial-Toe-3492 on r/n8n
Published on
Reddit
Original date
Oct 4, 2026
License
Not openly licensed (the poster keeps all rights), so we quote nothing and link to the original
Originally for
n8n
AI dry run
Oct 20, 2026: passed. Dry-run tested by our AI test agent on sample input. Unknown never retried; double-retry handled; no invented fees.
AI dry run on sample data; not run with live connected accounts. The playbooks.bot test agent filled the prompt with synthetic inputs, produced the output and checked it against the page's stated outputs and guardrails.
Verified
Oct 24, 2026: source link resolves to the original, the credited creator published it, our excerpt or prompt matches it, and the license allows our use.

Are you the creator? Claim or correct this page.

More in Finance & Accounting

All 62 Finance & Accounting playbooks →

Related playbooks

Finance & AccountingWorkflow✓ AI dry run

Chase unpaid bills by email with approval

Overdue invoices and stuck paperwork get chased on a schedule from your own mailbox, with approved wording and a clear list of accounts the agent must not contact.

Credit: u/danonino80 on r/AI_Agents

An afternoon+
Finance & AccountingWorkflow✓ AI dry run

Cover bills, settles and refunds in one workflow

Each billing event your app sends (invoice, payment or refund) is handled exactly once, with records, PDFs and customer emails kept in step.

Credit: u/cuebicai on r/n8n_ai_agents

An afternoon+
Finance & AccountingSkill✓ AI dry run

Prepare a financial advisor's client review brief

For one household or account and a review period, gather CRM context, holdings, planning and estate status, recent email and past meeting notes, then assemble a briefing the advisor can skim in minutes, with a snapshot, relationship notes, open action items, portfolio results, planning opportunities, a timed agenda and draft next steps.

Credit: Anthropic

An afternoon+
Finance & AccountingWorkflow✓ AI dry run

Turn emailed supplier invoices into checked purchase orders

Pull supplier invoices out of the inbox, read their contents, compare them with stock records and raise orders, with staff able to maintain the flow themselves.

Credit: Nova

An afternoon+