Skip to main content
Features

Billing

Configure Stripe plans, checkout, webhooks and credit accounting.

Open MarkdownFull AI corpusFeedback

Plans and entitlements

Plans and public price identifiers are configured in config/billing.config.ts. Server-side billing and credit accounting live in lib/billing, with authorized operations exposed through tRPC.

The kit supports subscriptions, one-time purchases, per-seat pricing, credits and server-side plan entitlements. Configure your own Stripe products and prices; the example price IDs are not usable products in your account.

Set STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET and the applicable NEXT_PUBLIC_STRIPE_PRICE_* values in the environment. Keep Stripe test and live configuration separate.

Hosted or embedded Checkout

Hosted Stripe Checkout is the default and recommended starting point:

STRIPE_CHECKOUT_MODE=hosted

Optional embedded Checkout uses the included modal. To enable it, set STRIPE_CHECKOUT_MODE=embedded and configure NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY from the same Stripe account and mode as the secret key. The browser reads this through the kit's public environment configuration, not a raw process.env access.

Public environment changes require a new build. A missing embedded publishable key should be fixed in configuration; do not expose the Stripe secret key to the browser.

Webhooks

The endpoint is /api/webhooks/stripe, implemented by src/routes/api/webhooks/stripe.ts and the shared handler in lib/billing/webhook-handler.ts.

For local testing:

npm run stripe:listen

Copy the signing secret printed by the Stripe CLI into your local environment. A Stripe Dashboard endpoint has its own signing secret; it is not interchangeable with the local listener secret.

For production, create a Stripe webhook endpoint at:

https://your-domain.com/api/webhooks/stripe

Use the handled-event list in .env.example when selecting events. Ensure Stripe can reach the endpoint: a deployment-protection login page is not a successful delivery. Verify delivery status in Stripe after configuration.

Payment correctness

A checkout success redirect is not proof of payment. Verified webhook processing updates subscription, order and credit state. Event claims and transaction references prevent duplicate fulfillment when Stripe retries or delivers related events more than once.

When applications share a Stripe account, the handler ignores events for customers not associated with an organization in this application's database. Metadata alone does not grant access to an organization.

Keep entitlement, billing-management and credit checks on the server. Organization owners and admins can manage billing; ordinary members should not gain access by calling an endpoint directly.

The protected admin panel also includes manual subscription-access controls. These are application access grants, not a substitute for charging a customer or modifying a Stripe invoice.