Recover failed Stripe payments with smart Loops dunning emails

When a Stripe payment fails, send the right Loops recovery email based on how many times the customer has already failed, and brief your revenue team in Slack.

Agentic Task
StripeLoops.soSlack BotFinanceCustomer SupportNotifications & AlertsEmail Automation

Build me an agent workflow that recovers revenue from failed Stripe payments without spamming the customer. It should pick the right Loops dunning email based on how deep into the failure cycle the customer is, and loop my revenue team in via Slack.

Trigger: Stripe webhook on invoice.payment_failed.

When the event fires, the agent should:

1. Pull full context. Call Stripe Retrieve Customer for the customer on the failed invoice. Then call Stripe List Invoices filtered to that customer to count how many invoices have status open or uncollectible (or were marked payment_failed) in the last 30 days. This is the failure depth.

2. Skip noise. If the Stripe customer is a test customer (livemode is false, or metadata flags it as test) or the invoice amount_due is under $5, stop and do nothing.

3. Enrich from Loops. Call Loops Find Contact by the customer's email so the agent can read prior contact properties like plan tier (planTier) and lifecycle stage (lifecycleStage). If no contact exists in Loops, proceed using only Stripe fields.

4. Pick the template. Based on the failure count in the last 30 days, choose the matching published Loops transactional template:

- 1 failure -> gentle first nudge template

- 2 or 3 failures -> firmer urgent reminder template

- 4 or more failures -> churn-warning template

Make these three transactionalId values configurable at the top of the workflow so I can swap them without editing logic. Also leave a clear hook for branching by planTier or lifecycleStage if I want a white-glove variant later.

5. Send the email. Call Loops Send Transactional Email to the customer's email with the chosen transactionalId and dataVariables for: firstName (from the Loops contact, else parse from Stripe customer name), amountDue (formatted as currency from invoice.amount_due in cents), retryDate (from invoice.next_payment_attempt, formatted as a friendly date), and invoiceUrl (the invoice.hosted_invoice_url). Send an Idempotency-Key header derived from the Stripe invoice id + attempt_count so a retried webhook does not re-send.

6. Brief the team. Call Slack Bot Send a Message to a configurable revenue channel (default #revenue-alerts) with a short structured summary:

- Customer name and email

- Plan tier (from Loops, if present)

- Dollar amount at risk

- Number of prior failures in the last 30 days

- Which Loops template was sent (gentle / urgent / churn-warning)

- Link to the hosted Stripe invoice

Use slackbot (not the user OAuth slack integration) so the alert is attributed to the bot, not me.

Configuration to expose at the top of the workflow: the three Loops transactionalId values, the Slack channel, the minimum dollar amount (default $5), and the failure-count thresholds (defaults 1, 2-3, 4+).

Error handling: if Loops returns 404 on transactionalId, post a warning to the Slack channel naming the missing template instead of silently failing. If Stripe Retrieve Customer or List Invoices fails, still try to post a degraded Slack alert with whatever fields are available so nothing is missed.

Additional information

What does this prompt do?
  • Listens for failed invoice payments in Stripe and pulls the customer's recent failure history so it knows whether this is a one-off slip or a deeper dunning situation.
  • Picks the right Loops transactional template for the moment: a gentle first nudge, a firmer second or third reminder, or a churn-warning email when failures pile up.
  • Sends the email through Loops with the customer's first name, amount due, retry date, and a hosted Stripe invoice link already filled in.
  • Posts a short summary to your revenue Slack channel so the team can see which accounts are at risk and step in on the high-value ones.
  • Skips Stripe test customers and tiny amounts so your inbox and your team only see real recoverable revenue.
What do I need to use this?
  • A Stripe account where payment-failure events can be sent to General Input
  • A Loops account with your dunning templates already published (gentle nudge, firmer reminder, and churn-warning versions)
  • A Slack workspace and the channel where your revenue or finance team wants the alerts
How can I customize it?
  • Change the failure thresholds, for example treat a 2nd failure as urgent instead of the 3rd, or extend the lookback window beyond 30 days.
  • Swap in different Loops templates per plan tier or lifecycle stage, like a white-glove version for enterprise contacts.
  • Adjust the Slack channel, the minimum dollar amount that triggers a post, or the fields included in each alert.

Frequently asked questions

Do I need to write the recovery emails from scratch?
No. The workflow uses templates you have already published in Loops. It just picks the right one and fills in the customer name, amount, retry date, and invoice link for you.
Will the customer get spammed if Stripe retries several times in a few days?
No. The workflow looks at recent failure history before sending, so a quick second retry the next day reuses the same dunning step instead of starting over. Each email also uses a unique key so duplicate runs do not double-send.
Can I send a different email for high-value customers?
Yes. The agent reads the matching Loops contact, including plan tier and lifecycle stage, before choosing a template. You can map those fields to whatever template variants you want.
Will test payments in Stripe trigger real emails?
No. The workflow skips Stripe test customers and any amount under five dollars, so your real customers and your team only see meaningful failures.
How does my revenue team know what happened?
Every send drops a short summary into the Slack channel you choose, with the customer name, plan, dollar amount at risk, how many times they have failed recently, and which template was sent.

Stop losing revenue to one-size-fits-all dunning emails.

Connect Stripe, Loops, and Slack once, and Geni picks the right recovery email for every failed payment.