Work Pricing FAQ Blog Jobs Trending Book the AI Audit

HomeBlogHow to Automate Stripe Invoicing with Claude Code

How to Automate Stripe Invoicing with Claude Code

I used to spend about 90 minutes every Friday afternoon generating invoices for clients. Pull data from my CRM, cross-reference it with my project tracker, create the invoice in Stripe, send it, log the action, and set a reminder to follow up if payment didn't come through in seven days. It was entirely mechanical work, but it had to be done correctly or I wouldn't get paid on time.

Six months ago I automated the entire process with Claude Code. Now invoicing happens automatically every Thursday night. Clients get their invoices Friday morning. Payment confirmations trigger thank-you emails and update my internal tracking. Overdue invoices send polite reminders without me lifting a finger. The whole system runs in the background, and I've gotten paid faster than ever.

Here's exactly how I built it, and how you can do the same if you're running any kind of service business that bills clients regularly.

Why Automate Stripe Invoicing with Claude Code

Stripe has a solid API, but their default invoicing setup still requires manual steps. You log in, create an invoice, fill in line items, send it, and then wait. If you're billing monthly retainers or project milestones, that's a lot of repetitive clicking.

The alternative most people reach for is Zapier or Make. Those work fine for simple workflows, but they fall apart when you need custom logic — like adjusting invoice amounts based on hours logged, pulling client-specific tax rates from a spreadsheet, or generating line items from multiple data sources.

Claude Code handles all of that. It connects directly to Stripe's API, pulls whatever data you need from wherever you store it (Airtable, Google Sheets, a custom database), applies your business rules, generates the invoice, and sends it. The best part: once it's set up, it costs you nothing per invoice. No monthly SaaS fees, no per-transaction charges beyond what Stripe already takes.

The Components of an Automated Invoicing System

My system has four main parts:

  • Data source — I use Airtable to track clients, projects, and billable hours. You could use Google Sheets, Notion, or a PostgreSQL database.
  • Invoice generator — A Claude Code script that reads the data source, calculates totals, and creates invoices via the Stripe API.
  • Webhook listener — A lightweight server that listens for Stripe payment events (invoice paid, payment failed) and triggers follow-up actions.
  • Email automations — Scripts that send confirmation emails when invoices are paid or reminder emails when they're overdue.

Each piece is simple on its own. The value comes from wiring them together so they run without human intervention.

Step 1: Connect Claude Code to Stripe

The first thing you need is a Stripe API key. You get this from your Stripe dashboard under Developers → API keys. Use a restricted key with only the permissions you need — in this case, write access for invoices and read access for customers.

In Claude Code, I use the stripe-python library. Installation is one line:

pip install stripe

Then you authenticate with your API key and you're ready to create invoices programmatically. The basic pattern looks like this:

import stripe

stripe.api_key = 'sk_test_your_key_here'

invoice = stripe.Invoice.create(
    customer='cus_customer_id',
    auto_advance=True,
    collection_method='send_invoice',
    days_until_due=7
)

stripe.InvoiceItem.create(
    customer='cus_customer_id',
    invoice=invoice.id,
    amount=5000,  # in cents
    currency='cad',
    description='Marketing consulting - July 2026'
)

stripe.Invoice.finalize_invoice(invoice.id)
stripe.Invoice.send_invoice(invoice.id)

That's the core. In practice, I wrap this in a function that takes client data as input and handles edge cases like discounts, tax rates, and multi-line invoices.

Step 2: Pull Client Data from Your CRM or Spreadsheet

My client records live in Airtable. Each row has fields for client name, Stripe customer ID, billing email, hourly rate, and a linked table of project hours logged that month.

Claude Code pulls this data using Airtable's API. The script runs a query for all clients marked as "Active" and filters for records where the "Last Invoiced" date is more than 30 days ago (for monthly retainers) or where unbilled hours exist (for hourly projects).

Here's the rough structure:

import requests

airtable_api_key = 'your_airtable_key'
base_id = 'appYourBaseID'
table_name = 'Clients'

url = f'https://api.airtable.com/v0/{base_id}/{table_name}'
headers = {'Authorization': f'Bearer {airtable_api_key}'}

response = requests.get(url, headers=headers)
clients = response.json()['records']

for client in clients:
    # Extract fields, calculate totals, generate invoice
    pass

If you're using Google Sheets instead, you'd use the gspread library or the Google Sheets API. Same principle — read rows, extract what you need, pass it to the invoice generator.

Step 3: Build the Invoice Generator Script

This is where the logic lives. For each client, the script:

  1. Calculates the total amount due (hours × rate, or a flat retainer)
  2. Checks for any discounts or credits in the CRM
  3. Creates a Stripe invoice with line items for each billable project or service
  4. Finalizes and sends the invoice
  5. Updates the CRM with the invoice ID and "Last Invoiced" date

The key is making it resilient. I added error handling so that if one invoice fails (maybe a Stripe customer ID is missing), the script logs the error and moves on to the next client instead of crashing.

Pro tip: always run this in test mode first. Stripe has separate test and live API keys. Use the test key until you've verified every edge case. The last thing you want is to send 30 incorrect invoices to real clients.

Step 4: Set Up Webhook Listeners for Payment Events

Once invoices go out, you need to know when they're paid. Stripe sends webhook events for every invoice status change: invoice.payment_succeeded, invoice.payment_failed, invoice.overdue.

I set up a small Flask server to listen for these webhooks. When a payment comes through, the server triggers a thank-you email and updates the CRM to mark the invoice as paid. When an invoice goes overdue, it sends a polite reminder.

Here's the webhook listener skeleton:

from flask import Flask, request
import stripe

app = Flask(__name__)
stripe.api_key = 'sk_live_your_key'

@app.route('/webhook', methods=['POST'])
def webhook():
    payload = request.data
    sig_header = request.headers.get('Stripe-Signature')
    event = stripe.Webhook.construct_event(payload, sig_header, 'whsec_your_signing_secret')

    if event['type'] == 'invoice.payment_succeeded':
        # Send thank-you email, update CRM
        pass
    elif event['type'] == 'invoice.payment_failed':
        # Log failure, notify admin
        pass

    return '', 200

if __name__ == '__main__':
    app.run(port=5000)

You host this on any cheap server — I use a $5/month DigitalOcean droplet. Point Stripe's webhook settings to https://yourdomain.com/webhook and you're live.

Step 5: Automate Follow-Up Emails

The last piece is email. When an invoice is paid, I send a quick confirmation. When it's overdue, I send a reminder after seven days and another at 14 days.

I use SendGrid's API for this, but you could use any transactional email service. The emails are simple templates with merge fields for client name, invoice amount, and payment link.

This gets wired into the webhook listener. When invoice.payment_succeeded fires, the script sends the thank-you email. When invoice.overdue fires, it checks if a reminder has already been sent (tracked in Airtable) and sends one if needed.

What This Saves Me Every Month

Time saved: about six hours per month. That's 90 minutes every Friday, plus follow-up time chasing late payments.

Money saved: harder to quantify, but I get paid faster now. Average time to payment dropped from 12 days to 8 days. That's meaningful when you're running on tight cash flow.

Mental overhead saved: priceless. I don't think about invoicing anymore. It just happens.

Common Mistakes to Avoid

The biggest mistake I see people make when automating billing: over-engineering it upfront. Start with the simplest version that works. For most service businesses, that's:

  • A script that pulls client data once a month
  • Generates invoices in Stripe
  • Sends a confirmation email when paid

You don't need webhook listeners, reminder emails, or CRM updates on day one. Add those once the basic flow is working and you know where the friction points are.

Second mistake: not testing payment failures. Stripe's test mode lets you simulate failed payments. Make sure your system handles them gracefully — logs the error, notifies you, doesn't retry indefinitely.

Third mistake: forgetting about tax. If you're invoicing clients in multiple provinces or countries, you need to handle GST, HST, or VAT. Stripe can manage this if you set it up correctly, but the invoice generator script needs to pass the right tax rates. I store these in Airtable alongside each client record.

How Long This Takes to Build

For someone comfortable with Python and APIs, this is a 2–3 day project. Day one is setting up the Stripe integration and testing invoice creation. Day two is pulling data from your CRM and wiring in the business logic. Day three is webhooks, email automations, and deploying the server.

If you're newer to this, budget a week. The good news: once it's done, it runs forever with minimal maintenance.

And if you don't want to build it yourself, this is exactly the kind of project I take on for clients. A custom invoicing system built around your existing tools, delivered in 5–7 business days. If that sounds useful, let's talk.

Is This Worth It?

If you're sending fewer than 10 invoices a month, probably not. The manual process is annoying but manageable.

If you're sending 20+ invoices a month, or if late payments are costing you real money, this pays for itself immediately. The setup cost (whether you build it or hire someone) is usually recovered within 30 days from time saved and faster payments.

For more on how Claude Code fits into broader business automation, check out my guides on invoice automation workflows and CRM integrations. And if you're still figuring out whether this is the right move for your business, the FAQ covers most of the questions I get about custom automation projects.

The bottom line: if invoicing is taking up your Friday afternoons, you don't have to live with that. The tools to fix it are here, and they're simpler than you think.

Work with me

Want this kind of result for your business?

Start with the AI Audit — $1,500. One focused engagement. The 3 highest-ROI opportunities in your business, ranked. A working proof-of-concept of the #1. Credited toward your build if we go forward.

Book the AI Audit → Read the FAQ
← All posts Book the AI Audit →