Billing
Configure your plans, and the changes you'll most often make to them.
Billing is per organization and driven entirely by src/config/billing.ts.
That file is data only: each plan's own fields decide how it's sold and
displayed, and nothing else in the codebase refers to a plan by id. The
template ships one plan of each kind:
export const BILLING_PLANS: BillingPlan[] = [
{
id: 'free',
...
prices: {},
features: ['create-projects'],
limits: { maxMembers: 1 },
},
{
id: 'pro',
...
prices: {
month: { amount: 9900, priceId: process.env.NEXT_PUBLIC_PRICE_PRO_MONTHLY ?? '' },
year: { amount: 95040, priceId: process.env.NEXT_PUBLIC_PRICE_PRO_YEARLY ?? '' },
},
features: ['create-projects', 'team-analytics', 'advanced-reporting'],
recommended: true,
limits: { maxMembers: 3 },
},
{
id: 'lifetime',
...
prices: { once: { amount: 29900, priceId: process.env.NEXT_PUBLIC_PRICE_LIFETIME ?? '' } },
features: ['create-projects', 'team-analytics', 'advanced-reporting'],
limits: { maxMembers: 3 },
},
{
id: 'enterprise',
...
prices: {},
contactUrl: '/contact',
limits: { maxMembers: -1 },
},
]Every price needs a matching Price in Stripe — see Stripe Setup.
Plan options
| Field | Effect |
|---|---|
prices.month / prices.year | A subscription. Charged immediately, unless the plan has trialDays. |
prices.once | A one-time purchase. Buying it cancels the organization's current subscription or trial. |
contactUrl | A "Contact us" plan. Never sold through checkout; its button links to contactUrl. |
No prices and no contactUrl | The free plan. Organizations without a subscription fall back to it. Without a free plan, they see the upgrade gate instead. |
trialDays | A card-required free trial on the organization's first subscription — see Offer a free trial. |
isDefault | New sign-ups go straight to checkout for this plan — see Send new sign-ups to checkout. |
features | Feature keys for gating. |
limits | Numeric limits. maxMembers sets the organization's seats — see Member limits. -1 means unlimited. |
recommended | Adds a "recommended" badge to the plan card. |
Plan descriptions and feature labels are translated: they live under plans
and features in src/i18n/messages/*.json, keyed by plan id and feature
key.
After editing the config, run pnpm test. tests/unit/config/billing.test.ts
catches the common mistakes: two free plans, duplicate ids, trialDays on a
one-time plan, or more than one isDefault.
Common changes
Add a plan
Create its price(s) in Stripe and add a NEXT_PUBLIC_PRICE_* environment
variable for each — see Stripe Setup.
Add the plan id to the PlanType union and the plan to BILLING_PLANS,
reading the price from its variable:
prices: {
month: { amount: 4900, priceId: process.env.NEXT_PUBLIC_PRICE_STARTER_MONTHLY ?? '' },
}Keep amount (in cents) equal to the Stripe price: Stripe charges its own
amount, while the pricing page displays this one.
Add the plan's description under plans (and any new feature labels under
features) in src/i18n/messages/en.json and fr.json.
For a "Contact us" plan, leave prices empty and set contactUrl instead.
Change a plan's price
Stripe Prices can't be edited. Create a new Price in Stripe, put its ID in
the plan's NEXT_PUBLIC_PRICE_* variable, update amount in the config, and
archive the old Price once existing subscriptions have moved off it.
Offer a free trial
Add trialDays to a subscription plan. The hero, pricing subtitle, and FAQ
pick it up automatically. Trials go through Stripe Checkout, so a card is
required up front and the first charge happens when the trial ends.
Each person gets one trial. It's refused when the organization already has a Stripe customer, or when the same user — matched by user id or by a hash of their email — has started one before, even in a deleted organization.
In the app, plan buttons already reflect this: eligible admins see "Start 14-Day Free Trial", everyone else sees "Subscribe". The marketing pricing page can't know who's visiting, so it always shows the trial label; if the visitor turns out to be ineligible, checkout sends them to the upgrade gate, which explains why, instead of charging them.
Remove the free plan
Delete it from BILLING_PLANS. Organizations without a subscription then
see the upgrade gate instead of a free tier.
Send new sign-ups to checkout
Set isDefault: true on one plan. New sign-ups who didn't pick a plan on
the pricing page go straight to Stripe Checkout for it (monthly, if
offered) instead of the dashboard. Combined with trialDays, that's a
card-required trial that starts at sign-up.
This needs Membership required in Clerk (see Setup), so the organization exists by the time the user reaches checkout.
Gating features and limits
Check the organization's plan with hasFeature() — in a Server Component to
decide what to render, and again in any Server Action that does the work:
import { getOrgBilling, hasFeature } from '@/lib/billing/server'
const billing = await getOrgBilling(orgId)
if (!hasFeature(billing, 'team-analytics')) return null // or a fallbackFor numeric limits, add the key to every plan's limits and check usage
with hasReachedLimit(billing, 'maxProjects', currentCount). A plan missing
the key counts as a limit of 0.
Build Your First Feature uses both, end to end.
Pages under (saas)/app/(gated)/ are also gated as a whole: an organization
with no access at all (no subscription and no free plan) sees the upgrade
gate instead — the plan grid for admins, "ask an admin" for everyone else.
Member limits
limits.maxMembers is the number of seats a plan gets. Plan cards show it,
for example "3 user seats".
- Enforced by Clerk. Whenever an organization's plan changes, the app sets its Clerk membership limit to the plan's seats, and Clerk blocks invitations past it (pending invitations count). Organizations without a plan get the free plan's limit, or 1 — which is why Clerk's default membership limit should match it (see Setup).
- Downgrades lock the app. If a downgrade or cancellation leaves an organization with more members than its plan allows, the app shows a "Too many members" screen instead of gated pages until an admin removes members or upgrades. The organization pages stay reachable so they can.
- One-time plans keep their limit. It's set at purchase, so changing
maxMemberslater doesn't affect organizations that already paid.
Without Clerk's B2B Authentication add-on, an organization can have at most 20 members, so "unlimited" means 20 until you add it.
For when seat limits fit better than charging per seat, and the code for each, see Seat Limits vs Per-Seat Pricing. For how checkout, the billing portal, and webhooks work under the hood, see How Billing Works.