💬 Recover failed Stripe payments with AI emails (by FlyCode)

54 views · 💬 Lead Nurturing & AI Sales Agents

💡 Pro Tip — Job boards are notoriously hard to scrape — CAPTCHAs, rate limits, constantly changing layouts. ScraperNode has maintained scrapers for Indeed jobs, Glassdoor reviews, and Glassdoor jobs that handle all of that for you.

View All Scrapers

Description

⚙️ Automated Stripe Failed Payment Recovery (with Postmark + AI Email Generator)

Recover failed Stripe subscription payments with AI-personalized emails sent via Postmark.

📝 Template Description

Recover failed subscription payments automatically with Stripe, Postmark, and AI.

This workflow listens for Stripe invoice.payment_failed webhooks, checks that the event is related to an auto-charged subscription, and then automatically sends a personalized email (generated with AI) to the customer. The email is polite, branded, but also urgent — encouraging the customer to pay quickly and avoid service cancellation.


🛠️ How it works

  1. 📣 Webhook
    Listens for Stripe webhook events. Make sure to connect it in your Stripe dashboard (see setup below).

  2. 🧹 Filter (Guard)
    Ensures the event is indeed an invoice event and filters out unrelated webhooks.

  3. 💡 Code Node
    Extracts useful fields (firstName, lastName, customer email, amount, currency, invoice number, hosted invoice URL, subscription description, account name).

  4. ✅ If Node
    Verifies that:

    • Event type = invoice.payment_failed
    • Billing reason = subscription_cycle
    • Collection method = charge_automatically

    👉 This ensures only recurring subscription invoices with auto-payment are processed.

  5. 🤖 AI Agent + OpenAI
    Generates a ready-to-send email JSON (to, subject, HTML body) using the extracted Stripe data.
    ✍️ You can customize the prompt here to match your brand’s tone of voice and style.

  6. 🧩 Code Parser
    Parses the AI model’s JSON output into fields (to_email, email_subject, email_body).

  7. 📧 HTTP Request (Postmark)
    Sends the email using Postmark’s API.
    You’ll need your own Postmark Server Token, From address, and Message Stream.


🚀 Setup Instructions

1. Stripe Webhook

👉 Example docs: Stripe: Listen to events with webhooks.

2. Disable Stripe’s Default Failed Payment Emails

3. Postmark Setup

Docs: Postmark API overview.

4. OpenAI Setup


✨ Customization Tips


✅ Outcome

Whenever a customer’s subscription payment fails, this workflow:

Result: Fewer cancellations, higher recovered revenue, and a smoother customer experience. 💸💌

🔗 Nodes Used

HTTP Request, Webhook, Filter, AI Agent, OpenAI Chat Model

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup