Payments
Subscriptions with Stripe Checkout and the customer portal, behind one PaymentProvider interface.
Choose with --payments stripe or --payments none (default). Payments need an auth module. On a React + Vite frontend with an API, the Hono and FastAPI APIs implement Stripe: see A frontend and its API.
The plans users can buy are in apps/web/src/config/plans.ts, with the app's own ids. The dashboard's billing card offers checkout for each plan, then shows the subscription and opens billing management. Server code reads a user's plan with getBilling().subscriptionFor(userId) and isEntitled from @/server/payments, and the subscriptions table keeps it in sync through the provider's webhook at /api/webhooks/payments.
Stripe
Stripe runs checkout and billing management. In test mode:
Copy the secret key from the dashboard's API keys into STRIPE_SECRET_KEY.
Create a recurring price for each plan and put its id in STRIPE_PRICE_<PLAN>, such as STRIPE_PRICE_PRO.
Forward webhooks to your machine with the Stripe CLI, and put the signing secret it prints in STRIPE_WEBHOOK_SECRET:
stripe listen --forward-to localhost:3000/api/webhooks/paymentsTurn on the customer portal in the dashboard's billing settings, so "Manage billing" works.
The result, with a pro plan:
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
STRIPE_PRICE_PRO=price_...In production, add a webhook endpoint for https://<your-domain>/api/webhooks/payments with these events, and use its signing secret:
checkout.session.completedcustomer.subscription.created,.updated,.deleted,.paused, and.resumed
Every webhook's signature is verified, each event is applied once, and subscription events read the subscription's current state from Stripe, so retried or out-of-order deliveries are safe.
A frontend and its API
With the Hono API (Starter v0.25.0 or newer) and the FastAPI API (Starter v0.26.0 or newer), the API runs billing, and the React + Vite dashboard has the same billing card:
- The plans are in
apps/api/src/config/plans.tswith Hono andapps/api/src/clubedge_api/plans.pywith FastAPI, and the API serves them at/api/billing. Checkout and the portal send the user back toFRONTEND_URL. - Hono's code reads a user's plan with
getBilling().subscriptionFor(await getUserProfileId(user))andisEntitled, from@/server/paymentsand@/server/users. FastAPI's code checks it withhas_active_subscription(await ensure_user_id(user)), fromclubedge_api.paymentsandclubedge_api.users, or reads it withfind_subscriptionandis_entitled. - FastAPI uses the same tables as Hono, those of
packages/payments, whichpnpm db:migrateand the image'snode migrate.mjsapply. - The Stripe variables go in
apps/api/.env.local, and on the API's service in production. - Stripe calls the frontend, which forwards
/api/webhooks/paymentsto the API with the body untouched, so the API stays private.stripe listen --forward-to localhost:3000/api/webhooks/paymentsworks as above, and the production endpoint ishttps://<your-frontend>/api/webhooks/payments.
With an active subscription, the settings page refuses to delete the account: the user cancels it with "Manage billing" first.
A mobile app or a native app has no billing card: app stores require their own in-app purchases for digital goods, so subscriptions stay on the website.
A project without a website has no payments: checkout and the customer portal send users back to the website's pages, so the CLI refuses --payments stripe there.
Another provider
Payments go through the provider-neutral PaymentProvider interface in packages/payments. To use another provider, implement that interface in a new package and return it from apps/web/src/server/payments.ts (apps/api/src/server/payments.ts with the Hono API); billing logic, the tables, the routes, and the billing card stay the same.
With the FastAPI API, the PaymentProvider protocol is in apps/api/src/clubedge_api/payments.py. Implement it in a new module, and in server.py, build its Billing in place of stripe_billing (from payments_stripe.py).
How is this guide?