Recover failed Stripe payments with SendGrid dunning emails

By General Input

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.

Integrations

  • Stripe
  • SendGrid
  • Slack Bot

Type

Agentic Task

Categories

  • Finance
  • Operations

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.

Related prompts

Explore more prompts
Let support send one-off Loops emails without an engineerA brand asset library your marketing team actually searchesTurn Mailjet email clicks into ranked HubSpot follow-upsClean out the Looker dashboards and Looks nobody opensLiveKit live operations console for room moderationWake up dormant Keap leads with a researched reasonCustomer lifecycle inspector for Loops, Stripe and PostHogLiveChat coverage board for planning next week's shiftsPhone routing control panel for LiveKit voice agentsLinkedIn Ads budget pacing dashboard for every client account