Recover failed Stripe payments with Brevo emails and CRM tasks

By General Input

When a Stripe invoice payment fails, send a warm Brevo recovery email, open a follow-up task in the Brevo CRM, and brief your revenue team in Slack.

Integrations

  • Stripe
  • Brevo
  • Slack

Type

Agentic Task

Categories

  • Finance
  • Sales

Build me an agent workflow that recovers customers after a failed Stripe payment using Brevo for both the email and the CRM follow-up, and pings our revenue team in Slack.

Trigger: a Stripe webhook for invoice.payment_failed. If the event has no invoice attached, fall back to charge.failed so one-off payments still flow through.

Step 1 — Gather context from Stripe. Call Stripe Retrieve Customer using the customer id on the event to get the customer's name, email, and any metadata I have on them (deal owner, plan tier). Then call Stripe Retrieve Invoice using the invoice id (when present) to get the amount due, currency, attempt count, next payment attempt timestamp, and hosted_invoice_url. If there is no invoice (charge.failed path), use the charge object's amount, currency, and failure_message, and skip the retry date.

Step 2 — Upsert the customer in Brevo. Call Brevo Create Contact with updateEnabled=true using the customer's email, first/last name parsed from the Stripe name, and attributes for STRIPE_CUSTOMER_ID, LAST_FAILED_AMOUNT, LAST_FAILED_AT, and FAILED_PAYMENT_COUNT (increment if the contact already exists). This makes the customer searchable in our Brevo CRM with dunning history attached.

Step 3 — Send a recovery email through Brevo. Use Brevo Send Transactional Email to the customer. Vary the tone based on (a) the attempt count on the invoice and (b) the dollar amount: first attempt and small amount = friendly heads-up, third+ attempt or amount above a configurable threshold (default $500) = more direct, urgent ask with a clear deadline. Always greet by first name, restate the amount and product, embed the hosted_invoice_url as a one-click "Update payment method and finish checkout" button, and mention the next retry date when we have one. If a Brevo transactional template id is configured, use the template and pass the variables in instead of freeform HTML.

Step 4 — Open a Brevo CRM task. Call Brevo Create Task with a title like "Recover $AMOUNT from CUSTOMER NAME (attempt N)", assignee = the deal owner from Stripe metadata (fall back to a default owner I configure), due date = Stripe's next payment attempt (or +2 business days if no retry date), and link it to the Brevo contact created in Step 2. Set priority to High when the failure is urgent (attempt count >= 3 or amount above threshold), otherwise Medium.

Step 5 — Notify the revenue team in Slack. Call Slack Send a Message to the billing channel (configurable, default #revenue) with a four-line summary: customer name + email, amount and currency, attempt number, and a link to the Brevo CRM task created in Step 4. Prefix the message with :rotating_light: Urgent when the failure qualifies as urgent, otherwise :warning:. Keep it tight — four lines, no walls of text.

Edge cases the agent should handle: customer has no email on the Stripe object (skip Brevo steps, still post to Slack noting the missing email so someone can chase it manually); Brevo Create Contact returns a duplicate (re-fetch and continue with the existing contact id); Brevo Create Task fails (still send the Slack message but flag that the task couldn't be created); Stripe Retrieve Invoice fails (proceed with charge-only context).

Use the dunning tone, urgency decision, and task priority as agent judgment calls — that's the whole reason this is an agent and not a static workflow.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentWin back LiveChat visitors whose chats went unansweredLet support send one-off Loops emails without an engineerCustomer lifecycle inspector for Loops, Stripe and PostHogChat quality review board for LiveChat support leadsWin back no-show and cancelled appointments every morningLive Loop returns analytics with product-level drill-downMonth-end Stripe finance pack, stored and shared in SlackNewsletter pre-flight and approval board for Mailjet sendsTurn a prospect spreadsheet into personalized sequence enrollments