I recently worked with a Vancouver-based SaaS company that was spending about eight hours a week managing Stripe subscriptions manually. Every failed payment needed a follow-up email. Every plan upgrade required manual invoice adjustments. Every cancellation triggered a retention workflow that lived in a spreadsheet and someone's head.
We automated the entire subscription lifecycle with Claude Code in about four days. Monthly recurring revenue increased 14% within sixty days, and the founder got his Fridays back. Here's exactly how we built the Stripe subscription automation system and what you need to know if you want to do the same.
What Claude Code Can Automate in Stripe Subscription Workflows
Before diving into implementation, it's worth being clear about what parts of subscription management are actually automatable with Claude Code. I've seen people try to automate the wrong things first and get frustrated when it doesn't save time.
The high-value automation opportunities in Stripe subscriptions fall into three categories:
- Billing event handling — responding to subscription creation, renewal, upgrade, downgrade, cancellation, and payment failure events from Stripe webhooks
- Invoice and payment workflows — generating custom invoices, sending payment receipts, updating internal records when payments succeed or fail
- Customer lifecycle automation — dunning sequences for failed payments, win-back campaigns for cancellations, upgrade prompts based on usage data
What it can't do: replace your payment gateway or subscription logic. Stripe still handles the actual billing. Claude Code sits on top of that and automates the operational workflows that happen before, during, and after each billing event.
How I Set Up Stripe Webhook Automation with Claude Code
The foundation of any Stripe automation system is webhook handling. Stripe sends HTTP requests to your server every time a billing event happens — payment succeeded, subscription cancelled, invoice finalized, whatever. Your job is to catch those events and trigger the right workflow.
I built a Claude Code script that listens for incoming Stripe webhook events, validates the signature to make sure it's actually from Stripe, parses the event data, and routes it to the appropriate handler. The structure looks like this:
1. Receive POST request from Stripe webhook 2. Verify webhook signature using Stripe secret key 3. Parse event type and customer data from JSON payload 4. Route to specific handler based on event type: - invoice.payment_succeeded → send receipt + update CRM - invoice.payment_failed → trigger dunning sequence - customer.subscription.updated → log plan change + notify team - customer.subscription.deleted → run cancellation workflow 5. Return 200 OK to Stripe within 5 seconds
The hardest part is making sure you respond to Stripe fast enough. If your script takes longer than about five seconds, Stripe assumes it failed and retries. You end up processing the same event multiple times, which causes duplicate emails and confused customers.
My solution: acknowledge the webhook immediately and queue the actual work for async processing. The webhook handler just logs the event to a database table and returns 200. A separate Claude Code process polls that table every 30 seconds and handles each event in sequence.
Automating Dunning Emails for Failed Payments
This is where the real revenue impact shows up. Most SaaS companies lose 5–10% of monthly recurring revenue to involuntary churn — customers who wanted to keep paying but their card expired or hit a limit. A good dunning sequence recovers about half of that.
The workflow I built triggers automatically when Stripe reports invoice.payment_failed. It checks how many previous failures the customer has had, then sends the appropriate email from a graduated sequence:
- First failure — friendly reminder that payment didn't go through, link to update payment method, assumes it's a temporary issue
- Second failure (3 days later) — more urgent tone, explicitly mentions service interruption risk, offers phone support if they need help
- Third failure (7 days later) — final notice before cancellation, includes a one-click reactivation link with a grace period discount
Claude Code generates each email from a template, personalizes it with the customer's plan details and outstanding balance, and logs the send in the CRM. If payment succeeds at any point, it cancels the remaining sequence automatically.
For the Vancouver SaaS client, this dunning automation recovered about $4,200 in monthly recurring revenue in the first 60 days. The script runs itself — no one has to monitor failed payments or decide when to send the next email.
Custom Invoice Generation and Delivery
Stripe generates PDF invoices automatically, but they're generic and don't always match what enterprise customers expect. A lot of B2B SaaS companies need custom invoice formats with specific line items, tax breakdowns, or branding.
I built a Claude Code workflow that listens for the invoice.finalized webhook event, pulls the invoice data from Stripe's API, and generates a custom PDF using a branded template. The template includes:
- Company logo and billing address
- Itemized line items with descriptions pulled from Stripe metadata
- Subtotal, tax, and total in the customer's currency
- Payment terms and due date
- A unique invoice number that matches internal accounting systems
Once the PDF is generated, the script uploads it to the client's document storage (we used Google Drive), updates the customer record in their CRM with the invoice link, and sends an email with the PDF attached.
The whole process takes about 12 seconds per invoice. For a company sending 200+ invoices per month, that's about six hours of admin work eliminated.
Handling Plan Upgrades and Downgrades Automatically
Subscription changes — upgrades, downgrades, add-ons — generate a lot of operational overhead if you handle them manually. You need to prorate charges, update internal seat counts, notify the customer, and sometimes trigger onboarding or offboarding workflows.
Claude Code can automate most of that. When a customer.subscription.updated event comes in, the script compares the old plan to the new plan, calculates what changed, and triggers the appropriate workflow:
- Upgrade — send congratulations email, update CRM to flag for success check-in, notify account manager if it's an enterprise account
- Downgrade — log the change, send confirmation email, schedule a feedback survey for 7 days later to understand why they downgraded
- Add-on activated — trigger onboarding sequence specific to that feature, update user permissions in the app
The key is making sure your Stripe metadata is structured well. I store plan tier, feature flags, and seat counts as metadata on each subscription. That way Claude Code can read the old and new states directly from the webhook payload without needing to query your app database.
Cancellation and Win-Back Workflows
When someone cancels, you want to know why and you want a chance to win them back. Most SaaS companies do this manually — someone on the team sees the cancellation, sends a personal email, maybe offers a discount. It works, but it doesn't scale.
I automated it with a staged win-back sequence that triggers on customer.subscription.deleted:
- Day 0 — cancellation confirmed, send exit survey asking why they left (multiple choice + open text field)
- Day 3 — if they cited price, send a 25% discount offer valid for 14 days
- Day 7 — if they cited missing features, share product roadmap and invite to early access program
- Day 30 — final check-in email with case studies showing ROI, no hard sell
The survey responses get logged in a Google Sheet for the product team to review quarterly. The win-back emails are personalized based on the cancellation reason and the customer's past usage data, which Claude Code pulls from the app's analytics API.
For my client, this workflow reactivated about 8% of cancelled subscriptions within 30 days. That's an extra $1,800/month that would have been lost without automation.
Integrating Stripe Automation with Your CRM
Subscription data is only useful if your team can see it. Every time a billing event happens, I update the customer's record in the CRM — HubSpot, Airtable, Notion, whatever they're using.
The integration is straightforward: when Claude Code processes a Stripe webhook, it checks if the customer exists in the CRM (matching by email or Stripe customer ID), then updates the relevant fields:
- Subscription status (active, past_due, canceled)
- Current plan and MRR
- Next renewal date
- Payment method status
- Lifetime value
If the customer doesn't exist yet, the script creates a new CRM record automatically. This keeps sales and support teams in sync without manual data entry.
I wrote more about CRM integration patterns with Claude Code if you want the technical details, and there's a full guide on business process automation that covers the broader strategy.
What You Need to Build This Yourself
If you want to set up Stripe subscription automation with Claude Code, here's what you'll need:
- A Stripe account with active subscriptions (obviously)
- Webhook endpoint that can receive POST requests — a simple Node.js server works, or you can use a serverless function
- Stripe API keys and webhook signing secret
- Access to your CRM's API (HubSpot, Airtable, Salesforce, etc.)
- Email sending service (SendGrid, Postmark, Mailgun)
- A way to store and process queued events — I use a lightweight SQLite database
The build usually takes 3–5 days depending on how many workflows you're automating. Once it's running, maintenance is minimal — maybe an hour a month to review logs and tweak email copy based on performance.
If you're handling more than 50 subscriptions a month and spending any time on manual billing tasks, the ROI on this is usually obvious within 60 days. For the Vancouver client I mentioned, the system paid for itself in saved labor hours in the first month.
Common Mistakes to Avoid
I've seen a few patterns that cause problems when people try to automate Stripe workflows:
- Not handling webhook retries properly — Stripe will retry failed webhooks up to three times. If your script isn't idempotent (safe to run multiple times), you'll send duplicate emails or double-charge customers.
- Ignoring test mode vs. live mode — always build and test in Stripe test mode first. Accidentally triggering live charges or cancellations during development is embarrassing and expensive.
- Hardcoding business logic — your dunning sequence, upgrade offers, and cancellation flows will change. Store them in a config file or database so you can update them without touching code.
- Not logging everything — when something goes wrong, you need to know which webhook triggered which workflow and what the customer saw. Log every event, every email sent, every API call.
The other big one: don't try to automate everything at once. Start with one high-impact workflow — usually dunning emails — get it working reliably, then add the next piece. I've written about this automation mistake pattern in more detail if you want to avoid the common traps.
If you're running a SaaS business in Vancouver or anywhere else and want help building this kind of system, I walk through it on the AI Audit call. We map out your subscription workflows, identify what's worth automating first, and I'll build a working proof-of-concept of the highest-ROI piece during the engagement. Details at alejandroarce.com, and the FAQ page answers most of the common questions about scope and pricing.