Skip to content

Billing

Subscriptions behind one provider-neutral seam: Stripe, Lemon Squeezy or Paddle.

Requires:DatabaseEmailsSign-in and teams

Providers

Pick one to update the preview and files

List prices at the time of writing. Verify before you rely on them.

Preview

What it adds

7 things, working end to end
  • A BillingProvider contract: the app owns plans, the database and every action, an adapter only talks to the vendor
  • Plan catalog with free, plus and pro, as display data with no vendor ids
  • Choose-a-plan page and a plan settings page with the current plan and card
  • Hosted checkout, billing portal and cancel, as server actions
  • Signed webhooks that are verified, normalised and written by one function, into one neutral Customer and Subscription schema
  • Billing per user or per organization: it follows the auth structure you picked
  • Provider contract and webhook tests, plus a fake vendor server for end-to-end tests

Set up Stripe

Accounts and keys, in this order
  1. 1
    Stay in test modeKeep Test mode on while you set up.dashboard.stripe.comTest mode
  2. 2
    Copy your secret keyOpen the API keys page.DevelopersAPI keys
    .env
    STRIPE_SECRET_KEY=sk_test_...
  3. 3
    Create your plansAdd a product with a recurring price for the Plus and Pro plans in lib/payments/plans.ts. Copy each price ID.Product catalogAdd product
    .env
    STRIPE_PRICE_PLUS=price_...
    STRIPE_PRICE_PRO=price_...
  4. 4
    Forward webhooks while developingInstall the Stripe CLI and run this. It prints a signing secret.
    stripe listen --forward-to localhost:3000/api/stripe/webhook
    # then add to .env
    STRIPE_WEBHOOK_SECRET=whsec_...
  5. 5
    In productionAdd an endpoint at https://yourdomain.com/api/stripe/webhook with the events customer.subscription.created, customer.subscription.updated, customer.subscription.deleted, customer.deleted and invoice.payment_failed, and use its signing secret.
  6. 6
    Check it worksOpen /choose-plan, pick a plan and pay with the test card 4242 4242 4242 4242. The plan turns active when the webhook arrives.

Environment variables

For the selected provider
.env
# Public URL of the app, used for return links
NEXT_PUBLIC_APP_URL=
# Secret API key (sk_test_... while testing)
STRIPE_SECRET_KEY=
# Signing secret of the webhook endpoint
STRIPE_WEBHOOK_SECRET=
# Price id of the Plus plan
STRIPE_PRICE_PLUS=
# Price id of the Pro plan
STRIPE_PRICE_PRO=

Works with

Other modules this one connects to

Add it to your repo

Pick the preset in the builder, check the providers, and download a repo that already has this module wired in.

Build your repo