Claude Templates / S-tier · Foundation

Foundation

The Stripe Billing Playbook

Customer linkage, plan tiers, a webhook handler that survives replays, and checkout.

STRIPE-BILLING-PLAYBOOK.md · 15 sections · 2,392 words · 20 KB · markdown

By Moe Ameen, founder of BILT · Published · Updated

The Stripe Billing Playbook gives Claude Code the money layer for a SaaS app: checkout and customer-portal routes, an idempotent Stripe webhook handler, the link between Stripe customers and Supabase profiles, plan-gated features through one getEffectivePlan helper, credit grants on each invoice, payment-failed handling, downgrades, refunds and a founding-member lifetime price. The file calls the webhook handler the load-bearing file.

Key takeaways

  • Routes: /api/billing/checkout, /api/billing/portal, /api/billing/balance-status, /api/stripe/webhook.
  • One helper, getEffectivePlan(userId), gates features by plan.
  • The webhook handler is built to survive duplicate and replayed events.
  • Includes downgrade, refund and founding-member pricing patterns.

The whole money layer. Stripe customer linkage to your user table, plan-tier modeling, an idempotent webhook handler, checkout sessions, and the founding-member pattern for pre-launch pricing. Written around the failure modes: duplicate events, out-of-order webhooks, subscription drift.

What does the Stripe Billing Playbook build?

It builds subscription and credit-pack billing on Stripe Checkout and the customer portal, with profiles.stripe_customer_id as the link to your users.

Sections cover plan-gated features, credit allocation, payment failure, downgrades and refunds, and end with a kickoff prompt and reference file list.

When should you add billing with it?

Add it in week 2, once there is something worth charging for. Credit Metering and the admin console's P&L both read what it stores.

If you sell one-off products with no accounts, Stripe Payment Links are simpler.

What do you need first?

You need App Infrastructure and Auth & Onboarding in place, Stripe secret keys and a webhook secret for test and live, and a STRIPE_PRICE_ variable for each plan and credit pack.

Decide your plan table first: price, monthly credits and whether bring-your-own API keys are allowed.

What's inside

What does the playbook give you?

When to use it

Week 2, once there's something worth charging for.

Straight from the file

What does the writing look like?

Pairs with AUTH-ONBOARDING-PLAYBOOK.md (depends on profiles.account_status) and EMAIL-INFRA-PLAYBOOK.md (consumes subscription_canceled / payment_failed trigger events).

Table of contents

Which sections does the file cover?

  1. 0. Use this spec
  2. 1. Architecture
  3. 2. Schema
  4. 3. The webhook handler — the load-bearing file
  5. 4. Checkout + portal
  6. 5. Plan-gated feature enforcement
  7. 6. Credit allocation pattern
  8. 7. Payment failed → accountstatus
  9. 8. Email triggers (cross-reference)
  10. 9. Founding-member / lifetime-pricing pattern
  11. 10. Downgrade handling
  12. 11. Refund flow
  13. 12. Common pitfalls
  14. 13. Kickoff prompt
  15. 14. Reference files in BKE

How do you run it?

Drop STRIPE-BILLING-PLAYBOOK.md into your repo, then tell Claude Code: “Read STRIPE-BILLING-PLAYBOOK.md and implement it in this codebase.” It's written for an agent to execute end to end. Search the file for angle-bracket placeholders and swap in your own project names, domains, and keys before the first run.

↓ Download the playbook

Who is this for, and who should skip it?

Best for

  • Subscription SaaS on Next.js and Supabase
  • Apps that also sell credit packs
  • Founders running a founding-member or lifetime offer

Not ideal for

  • Marketplaces needing Stripe Connect payouts (see the Affiliate Program file)
  • Billing providers other than Stripe
  • One-time digital downloads with no user accounts
  • Builders who won't adapt paths: the file points to a reference app you won't have

What else do people ask?

What is in the Stripe Billing Playbook download?

The Stripe Billing Playbook is a markdown file of about 2,400 words. It has SQL for the billing columns on profiles plus the subscriptions, stripe_webhook_events, credits, credit_transactions and plan_history tables, a table of webhook events to handle, a plan-gate snippet, a pitfalls list and a kickoff prompt.

Which Stripe events does it handle?

The Stripe Billing Playbook handles checkout.session.completed, customer.subscription.created, .updated and .deleted, invoice.payment_failed and invoice.paid. Subscription credits are granted only in invoice.paid, while checkout.session.completed grants one-time credit packs only, so the first month never gets credited twice.

What happens when a customer's payment fails?

The Stripe Billing Playbook stamps profiles.payment_failed_at and shows a fix-payment banner with a portal link, but keeps access on while Stripe Smart Retries runs for about a week. If the retries run out, customer.subscription.deleted drops the user to the free plan and clears the flag.

How should upgrades and downgrades work?

The Stripe Billing Playbook routes self-serve plan changes through the Stripe Customer Portal and updates the existing subscription with stripe.subscriptions.update and proration. It forbids cancel-and-recreate, which loses prorations, double-charges trial users and fires a subscription.deleted event that can send the cancellation email.

Do customers lose unused credits when they cancel?

Not by default. The Stripe Billing Playbook keeps the credit balance on cancellation so users keep what they paid for, and treats it as a policy call you should document in code comments either way.

How do we know this?

This page is based on the playbook file itself, STRIPE-BILLING-PLAYBOOK.md, which Moe Ameen wrote from the Kompozy codebase (called BKE in the file). We read the file on November 4, 2026; the facts here come from it, not from independent testing in other codebases.

More foundation playbooks

← All 28 Claude templates