Recover failed Stripe payments with SendGrid dunning emails

When a Stripe invoice payment fails, send a warm SendGrid email with a billing portal link and retry date, then post a one-line alert to Slack for finance.

Agentic Task
StripeSendGridSlack BotFinanceOperationsEmail AutomationNotifications & Alerts

Build me an agent workflow that recovers revenue when a Stripe invoice payment fails. The trigger is a Stripe webhook on the invoice.payment_failed event.

When that event fires, the agent should do the following:

1. Use Stripe's Retrieve Invoice operation to pull the failed invoice. From it, capture the amount due (remember Stripe amounts are in the smallest currency unit, convert cents to dollars for human display), the currency, the failure reason from the last payment error, the next automatic retry date (next_payment_attempt), the attempt count, and the hosted invoice URL plus the customer's billing portal link if available.

2. Use Stripe's Retrieve Customer operation on the customer ID from that invoice to get the customer's name and email address.

3. Draft a warm, non-alarming dunning email to the customer. Tone is helpful and clear, not threatening. The email should: greet them by first name, explain in one short sentence that their most recent payment did not go through, state the amount and what it was for, give the plain-English reason if available (for example, "your card was declined" or "your card has expired"), tell them when Stripe will automatically retry, and include a clear button or link to update their card via the Stripe billing portal or hosted invoice URL. Keep it short, two or three short paragraphs maximum. End with a friendly sign-off from the team.

4. Send the email using SendGrid's Send Email operation. The from address should be a configured sender (let me set this when I configure the workflow). The subject line should be friendly and clear, something like "Quick heads up about your recent payment". Use the customer's email as the recipient.

5. After the email is sent, post a one-line summary to a configured Slack channel using Slack Bot's Send a Message operation. Format it as a single line so finance can scan a stream of these and spot patterns. Include: customer name and email, failed amount with currency, failure reason in plain English, next retry date, and the attempt number (for example, "attempt 2 of 4"). Make the customer name and the invoice link clickable if possible.

This is a real revenue-recovery workflow, not a generic notification. Make sure the customer email is genuinely helpful and never sounds threatening or like a collections notice. If any required field is missing on the invoice (for example, the customer has no email on file), skip the email step but still post the Slack alert so finance can follow up manually.

Inputs I should be able to configure when setting up the workflow: the SendGrid from address and from name, the SendGrid template ID if I want to use my own dynamic template, the Slack channel ID for finance alerts, and an optional CC list for the customer email.

Additional information

What does this prompt do?
  • Catches every failed Stripe invoice the moment it happens, no more waiting on weekly billing reports.
  • Sends the customer a warm, plain-English email that explains what happened, links them to update their card, and tells them exactly when Stripe will retry.
  • Posts a one-line summary to a finance Slack channel with the customer, amount, reason, and next retry date so the team can spot patterns.
  • Replaces silent retries with proactive outreach, the same pattern that lifts dunning recovery rates from single digits to roughly 30 percent.
What do I need to use this?
  • A Stripe account with permission to set up webhooks (works in live or test mode).
  • A SendGrid account with a verified sender email or domain.
  • A Slack workspace and a channel for finance alerts.
How can I customize it?
  • Adjust the tone of the email (warm and apologetic, neutral and factual, or tiered by invoice amount).
  • Change which Slack channel receives the finance alert, or route by plan or amount threshold.
  • Add CC recipients to the customer email, like the account owner or CSM, so the right person knows to follow up.

Frequently asked questions

Will this work for subscription invoices and one-off invoices?
Yes. The workflow listens for any failed invoice payment in Stripe, so it covers recurring subscriptions, one-off invoices, and metered billing the same way.
What happens if Stripe successfully retries the card later?
Nothing extra fires. This workflow only runs on a failed payment, so a successful retry simply means the customer is back in good standing. You can pair it with a separate success workflow if you want a thank-you email.
Can I use my own SendGrid email template?
Yes. Tell the agent to use your SendGrid dynamic template ID and which fields to pass in (customer name, amount, retry date, portal link). The agent will plug those values into your template.
Will customers get duplicate emails if their card fails several times?
Stripe fires a separate failed payment event for each retry attempt, so by default you will send one email per attempt. You can ask the agent to only email on the first failure, or to send a different message after the second and third attempt.
How do I keep the email out of spam folders?
Verify your sending domain in SendGrid (SPF, DKIM, and DMARC), send from a real human-looking address, and keep the subject line plain. The workflow uses the verified sender you configure in SendGrid.

Stop losing revenue to silent failed payments.

Connect Stripe, SendGrid, and Slack once, and Geni runs this every time a Stripe invoice payment fails.