Billing (Stripe)
Billing uses Stripe for subscriptions: Checkout, the Customer Portal, and webhooks that sync subscription state into the database. Plans and credit allowances are defined in .
1. Add your secret key
Both are in your .
2. Create products & prices
Run the helper once — it creates a product and monthly price for each paid plan and prints the env lines to paste in:
Prices are derived from priceMonthly in config/plans.ts.
3. Forward webhooks locally
Install the , then:
Copy the printed signing secret into .env:
4. Test the flow
- Sign in and go to Billing.
- Upgrade to a paid plan — use Stripe's test card
4242 4242 4242 4242. - The webhook syncs the subscription; your plan and credits update.
- Manage subscription opens the Stripe Customer Portal.
Production
Add a webhook endpoint in the Stripe dashboard pointing at
https://your-domain.com/api/webhooks/stripe, subscribe to subscription and
checkout events, and set the resulting STRIPE_WEBHOOK_SECRET. Use your live
keys and re-run npm run stripe:setup on the live account.
How it fits together
config/plans.ts— plans, prices, credit allowances (source of truth)features/billing/server/— checkout, portal, subscription syncapp/api/webhooks/stripe/route.ts— signature-verified webhook handler