Automated payment failure recovery system built with n8n + Supabase
Recover 20-30% more failed payments automatically with intelligent retry strategies based on failure type.
5-10% of recurring payments fail every month. Most companies retry once (wrong approach) or manually chase customers (doesn't scale). Each failed payment means:
- Lost MRR
- Potential churn
- Wasted manual effort
- Poor customer experience
Result: Companies lose 8-12% of failed payments permanently due to poor recovery processes.
An automated payment recovery engine that:
- Categorizes failures by type (expired card, insufficient funds, fraud flag, other)
- Applies smart retry logic tailored to each failure reason
- Sends personalized notifications to customers
- Tracks recovery metrics in real-time
- Alerts on anomalies (low recovery rates, high amounts at risk)
| Metric | Before | After | Improvement |
|---|---|---|---|
| Recovery Rate | 8-12% (manual) | 28-35% (automated) | 3x increase |
| Time Spent | 8 hrs/week | 15 min/week | 96% reduction |
| Recovery Value | Inconsistent | $12K-15K/month | Consistent |
| Detection Time | Days | Real-time | Same day |
Stripe Payment Failure
β
[n8n Webhook Receiver]
β
[Categorize Failure Reason]
β
[Store in Supabase + Schedule Retry]
β
ββββββ΄βββββ¬ββββββββββ
β β β
[Expired] [Insufficient] [Fraud]
Card Funds Flag
β β β
[Notify + [Retry 3x [Alert +
Retry 1x over 7d] No Retry]
in 24hrs]
β
[Recovery Tracker]
β
[Dashboard + Alerts]
- n8n instance (self-hosted or cloud)
- Supabase account (free tier works)
- Stripe account with API access
- SMTP email service (Gmail, SendGrid, etc.)
- Clone this repository
git clone https://github.com/yourusername/failed-payment-recovery-engine.git
cd failed-payment-recovery-engine- Set up Supabase database
# Run the SQL schema in your Supabase SQL editor
cat database/schema.sql | supabase db execute- Import n8n workflows
# Import each workflow JSON file into your n8n instance
# Import order:
# 1. 1-webhook-receiver.json
# 2. 2-process-failed-payment.json
# 3. 3-send-email.json
# 4. 4-retry-scheduler.json
# 5. 5-daily-report.json- Configure environment variables in n8n
STRIPE_WEBHOOK_SECRET=whsec_xxxxx
STRIPE_SECRET_KEY=sk_test_xxxxx
N8N_HOST=https://your-n8n-instance.com
SLACK_ALERT_CHANNEL=#payment-alerts (optional)
REPORT_EMAIL=your-email@company.com
DASHBOARD_URL=https://your-dashboard.com (optional)- Set up Stripe webhook
- Go to Stripe Dashboard β Developers β Webhooks β Add endpoint
- Endpoint URL:
https://your-n8n-instance.com/webhook/stripe-payment-failed - Events to send:
payment_intent.payment_failed,invoice.payment_failed,charge.failed - Copy the signing secret β Add to n8n environment variables
- Test the system
# Use Stripe's test mode to trigger payment failures
# Watch the workflows execute in n8n
# Verify data appears in Supabasefailed-payment-recovery-engine/
βββ database/
β βββ schema.sql # Supabase database schema
β βββ sample-data.sql # Test data for development
βββ n8n-workflows/
β βββ 1-webhook-receiver.json
β βββ 2-process-failed-payment.json
β βββ 3-send-email.json
β βββ 4-retry-scheduler.json
β βββ 5-daily-report.json
βββ email-templates/
β βββ expired-card.html
β βββ insufficient-funds.html
β βββ fraud-alert.html
βββ docs/
β βββ INSTALLATION.md
β βββ CONFIGURATION.md
β βββ TESTING.md
β βββ TROUBLESHOOTING.md
βββ tests/
β βββ test-data/
β βββ sample-webhooks.json
βββ README.md
The system uses different retry strategies based on failure type:
Expired Card:
- Retries: 1x
- Timing: 24 hours after failure
- Notification: Immediate email asking customer to update card
Insufficient Funds:
- Retries: 3x
- Timing: 2 days, 5 days, 7 days (strategic timing after payday)
- Notification: Friendly reminder about payment
Fraud Flag:
- Retries: 0 (no automatic retry)
- Action: Immediate alert to finance team for manual review
Other Failures:
- Retries: 1x
- Timing: 3 days after failure
- Notification: Generic payment failure notice
You can customize retry strategies in the workflow:
- Open
2-process-failed-payment.jsonin n8n - Navigate to "Set Retry Strategy" node
- Modify
retry_schedulearray for each failure category - Save and activate workflow
The system includes pre-built email templates:
- Expired Card Template: Professional, urgent, with clear CTA to update payment method
- Insufficient Funds Template: Empathetic, helpful, with payment options
- Fraud Alert Template: Security-focused for finance team
Customize templates in /email-templates/ directory.
Includes:
- Yesterday's failures by category
- Recovery rate by category
- Total amount at risk
- Pending retries
- Performance trends
Automatic Slack/email alerts when:
- Recovery rate drops below 20%
- Amount at risk exceeds $10,000
- Fraud flags detected
- System errors occur
# 1. Use Stripe test cards to trigger failures
# Expired card: 4000000000000069
# Insufficient funds: 4000000000009995
# Fraud flag: 4100000000000019
# 2. Trigger test webhooks from Stripe Dashboard
# 3. Monitor workflow execution in n8n
# 4. Verify data in Supabase tables
# 5. Check email notifications sentSee TESTING.md for comprehensive testing guide.
- All Stripe webhooks are signature-verified
- Supabase Row Level Security (RLS) enabled
- Environment variables for sensitive data
- API credentials stored in n8n credential manager
- HTTPS required for all endpoints
- Webhook response: < 200ms
- Retry scheduling: Real-time
- Daily report: < 5 seconds
- Database queries: Optimized with indexes
- Email delivery: Asynchronous (doesn't block workflow)
- Workflow Engine: n8n (v1.0+)
- Database: Supabase (PostgreSQL)
- Payment Processor: Stripe API
- Email: SMTP (Gmail, SendGrid, etc.)
- Alerts: Slack API (optional)
- Hosting: Self-hosted or n8n cloud
- Installation Guide - Step-by-step setup
- Configuration Guide - Customize for your needs
- Testing Guide - Test thoroughly before production
- Troubleshooting - Common issues and fixes
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built as part of the 30-Day Financial Automation Build Challenge
- Inspired by real-world payment recovery challenges in SaaS businesses
- Thanks to the n8n and Supabase communities
- Issues: GitHub Issues
- Email: ethercess@proton.me
- Twitter: @ChukwuAugustus
- Revenue Leakage Detector - Find lost revenue automatically
Built with β€οΈ by [Ugo Chukwu] | Website | LinkedIn | X(formerly Twitter)
If this project helped you recover failed payments, give it a βοΈ!