Skip to main content
Early access — new tools and guides added regularly
🔴 Launch a Business — Guide 4 of 8
View track
>_ claude codeAdvanced40 min

Add Payments with Stripe

Integrate Stripe for one-time payments, subscriptions, and metered billing. Handle webhooks, invoices, and subscription lifecycle.

What you will build
A complete Stripe integration with checkout, webhooks, billing portal, and subscription management

Stripe concepts in 5 minutes

Stripe has four core concepts. Products are what you sell (your SaaS plans). Prices are how much they cost (monthly or yearly amounts attached to products). Customers are your users (Stripe stores their payment methods and billing history). Subscriptions link a Customer to a Price and handle recurring billing automatically. Checkout Sessions are Stripe-hosted payment pages — you redirect users there and Stripe handles card collection, validation, and charging. Webhooks are HTTP callbacks from Stripe to your server when events happen (payment succeeded, subscription cancelled, invoice paid). Create your products and prices in the Stripe Dashboard first, then ask Claude Code to integrate.

Building the checkout flow

Ask Claude Code: "Create a pricing page with Free, Pro ($12/month), and Team ($29/month/seat) plans. When a user clicks 'Get Started' on a paid plan, create a Stripe Checkout Session and redirect them to Stripe. After payment, Stripe redirects back to /app/billing?success=true. Store the Stripe Customer ID and Subscription ID on the user record in the database. Create a POST /api/stripe/checkout API route that creates the session." Test with Stripe test cards. The key detail: always use Stripe Checkout instead of building your own payment form. Stripe handles PCI compliance, 3D Secure, and payment method variety.

Webhook handling for subscription lifecycle

Webhooks are the backbone of subscription billing. Ask Claude Code: "Create a POST /api/stripe/webhook route that handles these events: checkout.session.completed (activate the subscription), customer.subscription.updated (handle plan changes), customer.subscription.deleted (handle cancellation), invoice.payment_failed (notify the user). Verify the webhook signature for security. Log every event for debugging. Use the Stripe CLI to forward webhooks to localhost during development."

Billing portal and subscription management

Users need to manage their own subscriptions. Ask Claude Code: "Create a /app/billing page that shows: current plan name and price, next billing date, payment method (last 4 digits of card), a 'Change Plan' button that opens Stripe's Customer Portal, and a 'Cancel Subscription' button with a confirmation modal. The Customer Portal is a Stripe-hosted page where users can update their card, change plans, and view invoices — use it instead of building your own billing management UI."

Metered billing and usage-based pricing

For APIs and usage-based products, you need metered billing. Ask Claude Code: "Add a usage-based pricing tier: API Access at $0.01 per request (first 1,000 free). Track API usage per user per month. Report usage to Stripe using their meter events API. Create a usage dashboard at /app/usage showing: requests this month, estimated cost, usage chart over time." This is advanced Stripe territory but Claude Code handles the implementation. The pattern: track usage in your database, report to Stripe periodically, and let Stripe handle invoicing.

Related Lesson

Monetisation Strategies

This guide is hands-on and practical. The full curriculum covers the conceptual foundations in depth with structured lessons and quizzes.

Go to lesson