Billing and subscriptions overview
Add subscription plans, checkout, trials, and seat-based pricing to your app.
BuildBase handles subscription billing end-to-end. Use the headless PricingPage component for checkout, and openWorkspaceSettings('subscription') for management. Everything else - Stripe integration, plan switching, trials, invoices - is handled automatically.
Warning
Billing requires setup in the BuildBase dashboard before the SDK components will work:
- Connect Stripe - Go to Billing > Credentials and enter your Stripe API keys (use test keys for development). Until a secret key is saved, the Billing menu holds only Credentials: Plans, Pricing groups and the rest appear once it is
- Create the Stripe webhook endpoint - On the same page, Check Stripe setup compares your Stripe account with what BuildBase needs, and Create the endpoint for me makes the endpoint with every required event and saves its signing secret. To make it by hand instead, point it at the URL the page shows and subscribe it to every event under Required webhook events
- Set your billing currencies - Go to Settings > General, card Billing currencies, and pick the currencies you charge in. No plan version can be created until there is one, and a saved currency cannot be removed
- Create a product category and products - Go to Billing > Product categories, then Billing > Products. Every product needs a category, and a plan version needs at least one product before it can be saved
- Create a plan - Go to Billing > Plans and press Create plan: a Name and a Slug. The price is not set here: it belongs to the plan's version
- Publish a plan version - Press Manage versions on the plan, then Create version. Its Base plan price card holds a price per currency and billing interval. Publish the version so it can be sold
- Set up a pricing group - Go to Billing > Pricing groups. Group your plans so
PricingPageknows what to display. Your app's users can check out only a plan version that a pricing group which is not archived sells or once sold: a version in no group, such as one written for a single deal, answers "Plan version not found" there, so create a checkout session for that customer with the org API instead (POST /api/organizations/<org id>/payment/stripe/checkout/create-session, with theworkspaceIdand theplanVersionId) and send them its link. A workspace or person that already holds a version can always check it out again - Collect tax (optional) - Activate Stripe Tax in your Stripe account, then switch it on under Billing > Credentials > Stripe Tax (see Tax)
Without these steps, PricingPage renders empty plans and selectPlan() fails.
Warning
A Stripe webhook endpoint made before 23 October 2026 is missing nine events BuildBase now acts on: checkout.session.async_payment_failed, payment_intent.succeeded, payment_intent.payment_failed, payment_method.attached, payment_method.automatically_updated, customer.updated, charge.dispute.closed, invoice.voided and customer.discount.created. Nothing adds them by itself, and nothing fails loudly without them. Until they are added:
- An automatic credit top-up charged on a 3-D Secure retry, or settled late, is charged but never credited, and a top-up declined after its charge started is not retried.
- A card saved, replaced by Stripe's card updater or made the default in the billing portal keeps its old expiry until the monthly check, so the expiring-card notice comes late.
- A dispute closed in your favour does not give back the credits and add-ons it took; you restore them by hand.
- An add-on paid by a delayed method that then fails stays pending instead of being marked failed.
- The metered usage on an invoice a pause voids is recorded only when the pause ends, instead of as soon as Stripe voids it.
- A one-time promotion code given at checkout sends no
subscription.discount_applied: Stripe applies it to the first invoice and never lists it on the subscription.
Run Check Stripe setup under Billing > Credentials. Its Webhook endpoint section says how many events are missing and names each one, and Fix the endpoint for me adds them to your existing endpoint, keeping the events it already sends and its signing secret.
import { PricingPage } from '@buildbase/sdk/react';
function Pricing() {
return (
<PricingPage slug="main-pricing">
{({ loading, error, plans, selectPlan }) => {
if (loading) return <p>Loading plans...</p>;
if (error) return <p>{error}</p>;
return (
<div className="grid grid-cols-3 gap-4">
{plans.map((plan) => (
<div key={plan._id}>
<h3>{plan.name}</h3>
<button onClick={() => selectPlan(plan._id, 'monthly', 'usd')}>
Choose {plan.name}
</button>
</div>
))}
</div>
);
}}
</PricingPage>
);
}import { useSaaSAuth } from '@buildbase/sdk/react';
function ManageBilling() {
const { openWorkspaceSettings } = useSaaSAuth();
return (
<button onClick={() => openWorkspaceSettings('subscription')}>
Manage Subscription
</button>
);
}Archiving plans, credit packages and categories
Archiving takes something off sale without taking it from anyone who has it. Each list in the console has Archive in the row's More actions menu (and in the Edit dialog for plans and categories, and on a credit package's page), behind a confirmation; Unarchive brings it back, and counts against the plan limit for that kind of object again, as creating one would.
- Plan - An archived plan leaves your pricing pages, new checkouts, plan changes from another plan and the console's plan pickers. Existing subscribers keep it: it renews, they can switch interval on the version they hold, preview changes and cancel as before, and a workspace or person that holds it can check it out again. Archiving is refused, with a message saying what to do first, while the current version of a pricing group sells the plan (publish a group version without it) or while it is the free plan new workspaces start on and fall back to (choose another default plan). A pricing group version that lists an archived plan cannot be published, an archived pricing group whose current version lists one cannot be unarchived, and an archived plan cannot be made the free plan new workspaces start on. Operators are held to the same rule: the console's Change plan and Comp refuse an archived plan too, so unarchive it first to move someone onto it.
- Credit package - An archived package is off sale: it leaves the credit store and its Stripe prices are deactivated. Credits already bought or granted from it stay. Archiving is refused while a plan version grants the package, an automatic top-up buys it or credits bought or granted from it are left; to stop new sales in the meantime, switch Active off. Unarchiving mints new Stripe prices before the package goes back on sale, and leaves it archived if Stripe refuses them.
- Product category - An archived category leaves the category pickers, so no new product goes in it. Products already in it keep it, on the pricing page too, and can still be edited. Nothing is refused.
Start new workspaces on a free plan
By default a new workspace has no plan until someone in your app chooses one, and until then it has nothing a plan grants. To start every new workspace on your free plan instead, with no card and no checkout, go to Settings > General > New workspaces, choose Start every new workspace on a free plan, pick the plan and save.
- Wherever the workspace is made. Your app's create button, the first workspace made when someone signs up, an agent, or a direct
POST /api/v1/public/workspaces: the server writes the free plan before the create answers, so the next read already has it. - Workspaces made before you switched it on. A workspace that never had a plan starts on the free plan the next time it is read: the workspace list, the workspace itself (what the server SDK's
entitlements.getreads), or its subscription. A read by you, viewing your app as one of its users, changes nothing. - A workspace whose plan ended is not one of them. What happens after a paid plan or a trial ends is decided by your cancellation settings, never by this one.
- What the workspace gets. The same as choosing the free plan itself: its features, limits, quotas and plan credits, and the same events. No "Subscription activated" email is sent, because nobody chose it.
- Stripe. When Stripe is connected, a Stripe customer is made for the workspace in the background, so a later upgrade, the billing portal and a saved card all use it. Without Stripe the free plan still applies.
- A plan, not a version. You choose the free plan; each new workspace gets the version of it on sale at that moment. Publish version 3 of Free and new workspaces start on version 3, with no change to the setting. Workspaces already on Free keep their version (moving them is a version move, see billing versioning). The plan must be a free plan sold to workspaces, with a published version.
- One free plan or several. With one free plan, it is chosen for you. With several, choose the one new workspaces start on. If the plan you chose is later archived, the one free plan your default workspace pricing group sells is used instead; with none, or more than one, nothing is written and the workspace has no plan, as before. When a paid plan ends and the workspace moves to Free, it lands on the same plan's version on sale.
Your app can read which applies from the public settings, billing.onboarding.mode on GET /api/v1/public/:orgId/settings: freemium when new workspaces start on your free plan, trial when they start a trial (below), require_plan when they must choose one (below), none otherwise. In a blueprint it is billing.onboarding, for example { "mode": "freemium", "plan": "free" }, or { "mode": "trial", "plan": "pro" } to start a trial of Pro. A blueprint's plan holds a trial back, and says why, while Stripe is not connected or the plan has no trial that skips the card, so an apply is never refused halfway. In the SDK, onboardingModeOf(settings) reads the mode from @buildbase/sdk 1.1.0.
Start new workspaces on a free trial
Choose Start every new workspace on a free trial under Settings > General > New workspaces to give every new workspace a trial of a paid plan, with no card and no checkout page, and move it to your free plan when the trial ends unpaid. Pick the plan to trial (and, when you have more than one free plan, the free plan after it) and save.
- The plan. A paid plan sold to workspaces whose version on sale offers a trial with Require card off, under the version's trial settings. The workspace gets that version's trial length; publish a new version and new workspaces trial that one. A trial that requires a card cannot be started this way, since only a person can add a card, so the setting refuses such a plan.
- Stripe. Each trial is a real Stripe subscription in trial, started by the server for the workspace's own Stripe customer, so Stripe must be connected to save this mode. It is set to cancel, not charge, when it ends without a card: nothing is ever billed unless someone adds one, through checkout or the billing portal, where your renewal terms are shown.
- When it ends. A trial nobody paid for ends as
trial_expired, and the workspace moves to your free plan, as any ended plan does under cancellation settings (unless you turned Fallback to Free off). With no free plan, it is left with no plan. - One trial per person. The usual trial rules apply: a workspace whose owner, or whose creator, has had a trial starts on your free plan instead. So does a workspace when Stripe cannot start a trial for a reason that would not change on a retry, such as Stripe being disconnected. A Stripe outage starts nothing, and the next read tries again.
- Whose first workspace gets it. Since a person has one trial, it goes to their first workspace. With Auto-create first workspace on (workspace settings, the default), that is the workspace made when they first sign in, and one your app creates after it starts on your free plan. If your app creates the workspace it wants trialled, turn auto-create off.
- Wherever the workspace is made, and on first read, as for the free plan above. It sends the events a checkout trial sends,
subscription.createdandsubscription.trial_started, and the same trial started email.
Require a plan instead
Choose Require a plan before a workspace is used under Settings > General > New workspaces when every workspace must pick a plan, free or paid, before it uses your app. New workspaces start with no plan, as by default, and the server holds them to it:
- What is refused. While a workspace has no plan, recording usage (
POST .../subscription/usageand.../usage/batch) and spending credits (POST .../credits/consumeand.../credits/reserve) answer402with the codePLAN_REQUIRED(error codes). Reading, members, invitations, settings and every billing route stay open, so a plan can always be chosen. A workspace whose plan has lapsed or is paused is answered by its lapse policy, not by this. - What the refusal says. The body carries
upgradeTarget: "workspace"andnext: the route that lists the plans, the one that selects a free plan, and the one that starts a checkout. An app, or an AI agent working for your user, can act on it without knowing your pricing: list the plans, select a free one itself, or hand a person the checkout link for a paid one (a card always needs a person). - Knowing before a refusal. The subscription read of a workspace with no plan,
GET /api/v1/public/workspaces/:workspaceId/subscription, carriesplanRequired: true. - In an app built on the SDK (
@buildbase/sdk1.1.0 or later). Plan & Billing opens by itself for someone who may manage the workspace's billing, and the plan picker cannot be dismissed until a plan is chosen. Someone without that permission is never held behind it. Setui.behavior.planRequiredGate: falseto show your own plans instead. - Choosing a free plan from your own code.
useSelectFreePlan(workspaceId).selectFreePlan(planVersionId)puts the workspace on a free plan with no checkout, then reads its plan again. On a server,subscription.selectFreePlan(workspaceId, planVersionId)does the same, andme.subscription.selectFreePlan(planVersionId)for a person's own plan.isPlanRequiredError(err)tells this refusal from others. All from the same SDK release. - Agents on your MCP server. A tool refused this way (
record_usage,consume_credits, or your own tool calling the SDK) fails withplan_required, notpayment_required, anddetails.nextToolsnames the tools that end it:get_plans, thenselect_free_planfor a free plan orcreate_subscription_checkoutfor a paid one.select_free_planis a write, exposed withbuiltinTools: 'all'. - Workspaces that exist today. The rule applies to every workspace with no plan from the moment you save, not only new ones.
PricingPage
PricingPage is headless: it fetches plan data and handles checkout logic, and you render the UI through a render prop. Both slug (the pricing group to display) and children (the render function) are required.
The render prop receives:
plans- published plan versions with pricing, features, limits, and quotasitems- subscription items (features, limits, quotas) for building comparison tablesloading/error- fetch stateselectPlan(planVersionId, interval, currency)- opens the plan dialog for authenticated users, or triggers sign-in first (setredirectBaseUrlonPricingPagefor the unauthenticated flow)refetch()- refetch plan datanotes- an optional note from the server about the payloadpromotion- the promotion code the page carries (code),check(planVersionId, interval, currency)to price it against one plan,checking, and the latest answer inresultaddOns- the add-ons on sale to the page's payer:list,loadinganderror, read beside the plansselectAddOn(offerSlug)- buys an add-on: opens the add-ons dialog when signed in, or signs in first
Optional props: loadingFallback (custom loading UI), errorFallback (custom error UI), redirectBaseUrl (post-login redirect base for unauthenticated visitors), promotionCode (a code to carry to the plan picker, ahead of ?promo= or ?coupon= in the page's URL) and for ('workspace', the default, or 'user' for a plan group sold to people).
Note
promotion, addOns, selectAddOn, promotionCode and for: Requires @buildbase/sdk 1.0.0 or later. @buildbase/sdk 0.0.90 has the rest of the list.
The email on the Stripe checkout page is filled in for you and cannot be edited there. It is the workspace owner's address, so a teammate with billing rights checks out under the owner's email rather than their own. Your app never passes an email: selectPlan takes no email argument and the checkout endpoint rejects one.
Checkout inside your app
Checkout opens on Stripe's hosted page by default. To open it in a dialog on your own page instead, pass Stripe's loader to the provider and turn the switch on:
import { loadStripe } from '@stripe/stripe-js';
<SaaSOSProvider
serverUrl="https://api.console.buildbase.app"
version={ApiVersion.V1}
orgId="your-org-id"
auth={authConfig}
loadStripe={loadStripe}
ui={{ behavior: { checkoutMode: 'embedded' } }}
>
{children}
</SaaSOSProvider>;The SDK never imports @stripe/stripe-js itself, so you install it and choose the version. Every checkout the SDK starts then opens in the dialog: the plan picker, a first paid plan after Free, and credit packs.
It is still Stripe Checkout, in Stripe's own frame, so everything the hosted page does carries over: promotion codes, tax with the billing address and tax ID, trials that need no card, and 3-D Secure. Paying sends the buyer to the same return URL with the same session_id, so the success screen and the purchase event work unchanged. Closing the dialog without paying reports checkout_abandoned.
What it needs:
- Your Stripe publishable key saved with your payment credentials in the console, from the same mode as the secret key. It reaches the browser only on an embedded checkout answer. Without it, the server refuses the embedded session (
STRIPE_PUBLISHABLE_KEY_MISSING, orSTRIPE_KEY_MODE_MISMATCHfor a key from the other mode) and the dialog offers Continue on Stripe, which opens the hosted page. - Stripe's origins in your Content-Security-Policy, if you set one. See Content-Security-Policy.
- Your domain registered for Apple Pay in the Stripe dashboard, if you want Apple Pay in the dialog. The hosted page uses Stripe's own domain, which is why it works there without this.
Without loadStripe, or against a server older than embedded checkout, checkout redirects to Stripe's page as before.
If you build your own picker on useCreateCheckoutSession or usePurchaseCredits, the answer carries clientSecret and publishableKey while the switch is on, and checkoutUrl is empty. Mount it with <EmbeddedCheckoutDialog> or <EmbeddedCheckout>, or pass uiMode: 'hosted' to keep the redirect for that call.
The same loadStripe lets a customer change the card their plan is charged on and pay an open invoice in your app: see Card payment in your app.
Where buyers return after checkout
A checkout your app starts with a successUrl and a cancelUrl returns the buyer to them. A checkout sent without them (a plan, a credit pack, an add-on, an upgrade or a card setup) returns the buyer to the first of these that exists:
- The checkout return page set in the console, under Settings > General, card After checkout.
- The app the buyer was signed in to: the first public https address among its app client's redirect URLs.
- Your oldest app with a public https address.
Set the checkout return page when your app's root page does not load the BuildBase provider. It must be an https page, with no # part, on the address of one of your apps (a redirect URL of one of its app clients). Leave it empty to use the app the buyer was using. The line under the field says where a checkout with no return URL lands today, and why.
When none of these exists, the buyer returns to the old default instead of your app, and the checkout answer carries the warning RETURN_URL_DEFAULTED (error codes). Every checkout answer names where the buyer lands in landingUrl. In a non-production environment, an app's http://localhost address counts too.
Confirm the purchase when the buyer is back
Requires @buildbase/sdk 1.2.0 or later. Coming back from Stripe does not mean the purchase went through. The provider reads the page the buyer lands on once, takes the Checkout Session id from it, strips it from the address bar and asks the platform for that checkout's status until it has an outcome: every second for 5 seconds, every 2 seconds to 20 seconds, then backing off to every 10 seconds. From 15 seconds the buyer reads "This is taking longer than usual", and at 2 minutes "We couldn't confirm it yet" with Check again. A platform error means keep waiting, never "not found". The purchase event fires when the platform says complete, not on the bare return.
Every purchase is confirmed this way: a plan, a credit pack, an add-on, a card saved for top-ups, and a commerce order. The billing screens (Plan & Billing, the person's own Billing, Add-ons, Credits and the auto top-up card) show the same status in one banner, and while a purchase is being confirmed, the buy buttons give way to "A purchase is being confirmed", so nobody pays twice.
Choose how the buyer sees it with ui.behavior.checkoutReturn:
| Value | What the buyer sees |
|---|---|
'dialog' (default) | A dialog on the page they land on, from "Confirming your purchase" to the outcome. On complete it hands over at once, to onCheckoutComplete or to the settings screen the return names |
'screen' | No dialog: the billing screen opens and shows the same states as a banner |
'off' | The provider leaves the return alone. Render <CheckoutStatus> or call useCheckoutStatus on your own page; both read the return in the URL themselves. purchase then fires on the bare return |
<SaaSOSProvider
serverUrl="https://api.console.buildbase.app"
version={ApiVersion.V1}
orgId="your-org-id"
auth={authConfig}
ui={{
behavior: {
checkoutReturn: 'dialog',
onCheckoutComplete: () => router.push('/welcome'),
},
routes: { checkoutReturn: '/checkout/return' },
}}
>
{children}
</SaaSOSProvider>ui.behavior.onCheckoutComplete(result)is called once, when the purchase is complete, never from a timer. With it, the dialog closes into your app instead of opening the billing screen.ui.routes.checkoutReturnis a page of your app that renders<CheckoutStatus>. The SDK's checkouts then come back there instead of to the page they started from, which travels in the return URL as a relativereturnTofor the card's Continue. The provider shows no dialog on that page.
A return page of your own
<CheckoutStatus> from @buildbase/sdk/react is the same status as a card on your page:
// app/checkout/return/page.tsx
'use client';
import { CheckoutStatus } from '@buildbase/sdk/react';
export default function CheckoutReturnPage() {
return <CheckoutStatus onComplete={() => console.log('paid')} />;
}Its props are all optional: sessionId (default: the return the provider recognised, or the session_id in the URL), onComplete (called once, when complete), continueTo (a relative path for Continue; default the page the checkout started from), title (null hides the heading) and className.
To build the screen yourself, useCheckoutStatus() shares the same store, so nothing is asked twice:
import { useCheckoutStatus } from '@buildbase/sdk/react';
function ReturnBanner() {
const { state, loading, refetch } = useCheckoutStatus();
if (state === null) return null; // not a checkout return
if (state === 'complete') return <p>Thanks, you are all set.</p>;
if (state === 'unconfirmed')
return <button onClick={refetch}>Check again</button>;
return <p role="status">{loading ? 'Confirming your purchase...' : state}</p>;
}state is a status from the platform (complete, processing, payment_pending, failed, refunded, needs_attention, open, expired, not_found), slow from 15 seconds, unconfirmed once the window has run out, canceled on Stripe's cancel leg (nothing to check), or null when the page is not a checkout return. refetch() asks again at once, as Check again does. data holds the session id and what the platform said; error is always null, since every way a check can end is a state.
Without React
fetchCheckoutStatus and watchCheckoutStatus from @buildbase/sdk ask the same public status route (GET /api/v1/public/:orgId/checkout/:sessionId/status). The route needs no session, so a signed-out buyer's return works too. Neither throws: every failure is an outcome.
import { fetchCheckoutStatus, watchCheckoutStatus } from '@buildbase/sdk';
const config = {
serverUrl: 'https://api.console.buildbase.app',
orgId: 'your-org-id',
};
const sessionId = new URLSearchParams(location.search).get('session_id');
if (sessionId) {
// Ask once: outcome is 'answer', 'wait' (busy, retry after retryAfterMs) or 'unsupported'
const result = await fetchCheckoutStatus(config, sessionId);
if (result.outcome === 'answer' && result.answer.state === 'complete')
showThanks();
// Or ask on the schedule until it settles
const stop = watchCheckoutStatus(config, sessionId, (update) =>
render(update.state)
);
// stop.checkAgain() from a "Check again" button, stop() when leaving the page
}watchCheckoutStatus pauses while the tab is hidden and asks at once when it comes back. An update with unsupported: true means the server has no status route (an older platform): the watcher stops, and you confirm the purchase another way, such as a webhook.
Renewal terms at checkout
Every subscription checkout shows the auto-renewal terms directly above Stripe's Subscribe button: that the plan renews automatically until it is cancelled, how often, and that each renewal is charged at the plan's then-current price including any per-seat, usage and tax charges. A checkout that starts a free trial says what follows it, worded by whether the trial takes a card. The plan picker shows the same terms beside its buttons.
The terms are in the buyer's language. When you pass locale to SaaSOSProvider and it is one of the 8 languages the SDK speaks, the SDK sends it with the checkout and the terms are written in it; Stripe's own Checkout text follows where Stripe translates Checkout into that language (Hindi and Arabic keep Stripe's default, the browser's language). Without a locale, or with one the SDK does not speak, the terms are in English and Checkout keeps Stripe's default. A checkout you open yourself can pass locale in the request to useCreateCheckoutSession or useUpdateSubscription.
To add your own cancellation or renewal policy, write it in the console under Settings > General, card Your policy at checkout. Checkout shows it after the renewal terms, as you wrote it, in every language. It adds to the terms and cannot replace them.
Note
The buyer's language: Requires @buildbase/sdk 1.0.0 or later. Earlier versions send no locale and get English. Your own policy is added on the server, so it shows with every SDK version.
openPlanPicker()
Opens the plan selection UI from anywhere in your app - perfect for "Upgrade" buttons inside feature gates or trial banners:
import { useSaaSAuth } from '@buildbase/sdk/react';
function UpgradeButton() {
const { openPlanPicker } = useSaaSAuth();
return <button onClick={() => openPlanPicker()}>Upgrade Plan</button>;
}When your plans are priced in more than one currency and the workspace has no billing currency yet, the plan picker opens on the visitor's currency: the one for the country their browser's language settings name (en-GB is GBP, a bare de is Germany, so EUR). If your plans are not priced in it, it opens on USD, and without USD on the first currency offered. A checkout link's currency and the current subscription's currency come first. Nothing leaves the browser for this: there is no IP lookup and no location prompt, and the visitor can still pick another currency. The credit packages dialog does the same. From SDK 0.0.88; earlier versions open on the first currency in alphabetical order.
openWorkspaceSettings('subscription')
Opens the full subscription management screen where users can:
- View current plan and billing interval
- Upgrade or downgrade, with what the change costs shown before it is confirmed
- See the next invoice under the plan
- Apply a promotion code (see Promotion Codes)
- Collect tax with billing addresses and tax IDs (see Tax)
- Cancel or resume
- View invoices and payment history
- Access the Stripe billing portal
Changing plan
A plan change from the plan picker or useUpdateSubscription() is applied to the workspace's existing subscription. What happens next depends on the subscription:
- During a trial, the plan changes and the trial keeps running: it ends when it would have, and nothing is charged at the change. The first charge is the new plan's price, when the trial ends. A trial started without a card still needs one before then, or Stripe cancels the subscription at the end of the trial.
- An upgrade invoices the difference at once. When the card needs 3-D Secure or is declined, Stripe holds the upgrade until that invoice is paid, and the workspace stays on its current plan meanwhile. Plan & Billing shows a Complete payment button that opens Stripe's invoice page (from SDK 0.0.86; earlier versions say the plan was updated). If the invoice is not paid within 23 hours, Stripe drops the change.
- A downgrade is not credited back. The workspace keeps its current plan's features until the end of the period it paid for.
Switching interval
Customers may move their plan to another billing interval (monthly to yearly, say) themselves, from the plan picker or useUpdateSubscription(). You can turn that off under Settings > General, card Cancellation. Then a plan change or preview that names another interval than the subscription's own is refused with 403 INTERVAL_SWITCH_OFF, and one that names no interval keeps the subscription's interval rather than monthly. Moving a workspace plan onto the customer's own account (POST .../subscription/move-to-user) is held to it too: another interval than the workspace plan's is refused the same way. A first checkout is not a switch, and an operator can still change the interval from the console. The subscription read says which applies to the customer (capabilities.intervalSwitch.enabled), from the BuildBase server of this release.
Plan credits on a plan change
A plan version can give credits with it, once or every month, and Settings > General, card Credits on a plan change, decides what a plan change does to them: Plan credits.
The subscription.upgraded webhook fires when the upgrade is applied: at the change, or once its payment goes through.
Calling the hook yourself, check for a payment the user still has to make:
const result = await updateSubscription(planVersionId);
if ('checkoutUrl' in result) {
window.location.href = result.checkoutUrl; // no subscription yet: a first checkout
} else if (result.paymentRequired && result.paymentUrl) {
window.open(result.paymentUrl, '_blank', 'noopener,noreferrer'); // the upgrade waits on this payment
}paymentRequired and paymentUrl are declared on ISubscriptionUpdateResponse from SDK 0.0.86; the server sends them to every version.
Reading subscription state
Use hooks when you need to display subscription info or conditionally render UI:
import {
useSubscription,
useTrialStatus,
WhenNoSubscription,
WhenSubscriptionToPlans,
WhenTrialEnding,
} from '@buildbase/sdk/react';
function Dashboard({ workspaceId }) {
const { subscription } = useSubscription(workspaceId);
const { isTrialing, daysRemaining } = useTrialStatus();
return (
<>
{subscription && <p>Plan: {subscription.plan?.name}</p>}
{isTrialing && <p>{daysRemaining} days left in trial</p>}
<WhenNoSubscription>
<p>
No plan yet. <a href="/pricing">Choose a plan</a>
</p>
</WhenNoSubscription>
<WhenSubscriptionToPlans plans={['starter']}>
<p>Upgrade to Pro for more features.</p>
</WhenSubscriptionToPlans>
<WhenTrialEnding daysThreshold={3}>
<p>Trial ends soon - add a payment method to keep access.</p>
</WhenTrialEnding>
</>
);
}Previewing a plan change
Before a plan changes, the plan picker shows what it costs: due today, the next invoice, and for a downgrade the date it takes effect and how long the current features stay. The numbers are Stripe's own invoice preview, and the change confirmed from that screen is charged as shown. A downgrade is never prorated back: nothing is due today, and the new plan starts when the period ends.
The same reads are there for your own screens:
Note
Requires @buildbase/sdk 1.0.0 or later. @buildbase/sdk 0.0.90 has no usePreviewSubscriptionChange or useUpcomingInvoice.
import {
formatMinorAmountIntl,
usePreviewSubscriptionChange,
useUpcomingInvoice,
useUpdateSubscription,
} from '@buildbase/sdk/react';
function ChangePlan({ workspaceId, planVersionId }) {
const { preview, data, loading } = usePreviewSubscriptionChange(workspaceId);
const { updateSubscription } = useUpdateSubscription(workspaceId);
const { invoice } = useUpcomingInvoice(workspaceId);
return (
<div>
{invoice?.kind === 'invoice' && (
<p>
Next invoice:{' '}
{formatMinorAmountIntl(invoice.amount, invoice.currency)}
</p>
)}
<button
disabled={loading}
onClick={() => preview(planVersionId, { billingInterval: 'monthly' })}
>
What will this cost?
</button>
{data?.kind === 'change' && (
<>
<p>
Due today:{' '}
{formatMinorAmountIntl(data.dueToday.amount, data.currency)}
</p>
<button
onClick={() =>
updateSubscription(planVersionId, {
billingInterval: 'monthly',
prorationDate: data.prorationDate,
})
}
>
Confirm
</button>
</>
)}
</div>
);
}Amounts are in the currency's smallest unit (cents for USD, whole yen for JPY), so format them with formatMinorAmountIntl(amount, currency, locale?) rather than dividing by 100.
A preview answers one of four kinds:
| Kind | Meaning |
|---|---|
no_change | The workspace already pays this price |
checkout | No subscription yet: the first checkout's price |
change | Charged now (dueToday), then nextInvoice |
deferred_downgrade | Nothing now; the new plan from effectiveAt, current features until keeps.until |
A preview refuses what the change itself would refuse, writes nothing, and is limited to 30 calls a minute. Pass its prorationDate back on the change so Stripe charges for the moment it priced. A date older than ten minutes is ignored, and the change is priced when it is made.
Switching the same plan to another interval, monthly to yearly say, is neither an upgrade nor a downgrade: it is charged now, and the workspace keeps its plan and features throughout.
Credit a change leaves on the customer's balance normally comes off nextInvoice (in nextInvoice.creditApplied). When the same Stripe customer also pays for another workspace or for a person's own plan, that balance is shared, and whichever of its invoices Stripe finalizes first may use it. The preview then leaves nextInvoice.amount at the full price and answers the credit as nextInvoice.creditOnAccount: credit on the account for the customer's next invoice, which may or may not be this workspace's. creditOnAccount comes from the BuildBase server of this release.
useUpcomingInvoice answers kind: 'invoice' with the amount, kind: 'none' with a reason (cancels_at_period_end, no_subscription, or trial_needs_payment_method for a trial started without a card, which ends with no invoice and converts only if a payment method is added before it ends), and kind: 'paused' with resumesAt (null for a pause with no end date) while a pause is scheduled or in force: the pause voids every invoice until then, so there is no next invoice to show. The paused kind comes from the BuildBase server of this release and is typed in SDK 1.0.0 and later; an older server never answers it.
Hide the next-invoice line on the subscription screen with ui.settings.subscription.nextInvoice: false.
Cancel, pause and resume
A customer's cancel is at the end of the paid period unless you let them end it now: the workspace keeps its plan until then, nothing is refunded, and it can be resumed until the period ends. The subscription screen's cancel dialog does up to three things first, each set in the console under Settings > General, card Cancellation:
- Ask why. One of Stripe's eight reasons (
too_expensive,missing_features,switched_service,unused,customer_service,too_complex,low_quality,other) and an optional comment of up to 500 characters. The reason is sent to Stripe as the subscription'scancellation_details, so it shows in your Stripe dashboard too, and it is kept on the subscription and its history. - Offer one thing to stay. A discount (one of your coupons) or a pause. Each subscription gets the offer once. It is not shown on a trial, a past-due or comped subscription, one already cancelling or paused, and a pause offer only on a monthly plan.
- Say where the workspace lands. When the paid plan ends, the workspace moves to your Free plan instead of having none. This is on whenever one Free plan is published; switch it off in the same settings. After a failed payment, the move waits out the plan group's grace days first.
- Keep the lapse policy after failed payments. By default, once Stripe ends a subscription for failed payments and the grace days are over, the workspace moves to Free whatever the plan group's lapse policy says. Choose Keep the plan's lapse policy in force and a suspended plan stays suspended until the customer subscribes again, and a policy that ends on Free still lands on Free. A plan sold as read-only is answered as read-only until they subscribe again (
lapse.thenisread_onlyon the entitlement answer), so your app's entitlement checks and claims refuse new items; the SDK's own workspace changes (creating or renaming a workspace, adding or inviting a member) are not stopped unless the server's read-only check is switched on, and it is off by default (S23). Move to Free after a number of days (1 to 365) ends the hold then; leave it empty to keep it until they subscribe again. While it holds, the customer cannot end it by choosing your Free plan:select-free-planis refused with409LAPSE_HELD. A person's own plan follows the same setting.
The same steps are there for your own screens:
Note
Requires @buildbase/sdk 1.0.0 or later. @buildbase/sdk 0.0.90 has useCancelSubscription and useResumeSubscription, but no useRetentionOffer, useAcceptRetentionOffer or usePauseSubscription, and its cancel takes no reason.
import {
useAcceptRetentionOffer,
useCancelSubscription,
usePauseSubscription,
useResumeSubscription,
useRetentionOffer,
} from '@buildbase/sdk/react';
function CancelFlow({ workspaceId }) {
const { getRetentionOffer } = useRetentionOffer(workspaceId);
const { acceptRetentionOffer } = useAcceptRetentionOffer(workspaceId);
const { cancelSubscription } = useCancelSubscription(workspaceId);
const leave = async () => {
const { offer } = await getRetentionOffer();
if (offer && window.confirm('Stay with this offer instead?')) {
await acceptRetentionOffer(offer.id, { feedback: 'too_expensive' });
return;
}
await cancelSubscription({
feedback: 'too_expensive',
comment: 'Over budget this quarter',
...(offer
? { retention: { offerId: offer.id, outcome: 'declined' } }
: {}),
});
};
return <button onClick={leave}>Cancel subscription</button>;
}A second accept is refused with RETENTION_ALREADY_USED, and an offer that changed after it was read with RETENTION_OFFER_CHANGED.
Pause. With Let customers pause on, a monthly subscription can be paused for whole months, up to the cap you set (12 at most). The plan keeps working until the paid period ends; from then nothing is billed, the plan is off, and collection resumes on its own after the months chosen. usePauseSubscription(workspaceId).pauseSubscription(months) pauses; useResumeSubscription ends a pause early, and once the pause has started that begins a new paid period, charged at once. The subscription read says whether a customer may pause (capabilities.pause), and subscription.pause carries accessUntil and resumesAt. While a pause is scheduled or in force, useUpcomingInvoice answers kind: 'paused' with the same resumesAt. The read also carries subscription.hasPaymentMethod: true when a payment method is on file for the Stripe subscription, false when none is (the trial banner then asks for one), and absent when the server cannot tell. Both need the BuildBase server of this release, and SDK 1.0.0 or later for their typings. Operators can pause and end a pause from the workspace's Actions menu whatever the setting. Hide the Pause button with ui.settings.subscription.pause: false.
Each step fires a webhook: subscription.cancel_scheduled (with feedback, comment and retentionOutcome), subscription.retention_accepted, subscription.paused and subscription.unpaused. See Webhooks.
Ending a subscription now
Under Settings > General, card Cancellation, you also choose how a customer's own cancel ends the subscription:
- At the end of the period (the default): as above.
- Now: the cancel dialog also offers to end it at once. The plan ends immediately, Stripe sends a final invoice for anything still unbilled (metered usage, say), and the workspace moves to your Free plan as after any cancel. A subscription already set to cancel at the end of the period can be ended now too. While an invoice is unpaid (past due, being retried, suspended, or a first payment not complete), a customer's own cancel now is refused with
400and the state's code, such asSUBSCRIPTION_PAST_DUE: they can still cancel at the end of the period, and an operator can still end it now.
And what ending it now gives back for the time paid and not used:
| Refund | What the customer gets |
|---|---|
| Nothing (the default) | Nothing |
| Prorated credit | Stripe's proration: a credit for the unused time on the final invoice, kept on the customer's balance for their next invoice |
| Prorated refund | Credit notes on the invoices paid for the current period (its own, and a plan change or add-on billed since), refunded to the payment method that paid each: the unused share of what was paid for the plan's own lines (never metered usage or one-off charges), less what a plan change already credited, at most what each invoice can still refund |
A trial, an unpaid subscription and a $0 invoice get nothing back.
Both are priced by time alone, so by default a customer who has already used the period's quotas or plan credits still gets the unused share back (refundWhenAllowanceUsed: 'prorate_by_time'). Set When the customer has used the period's allowance to Give nothing back ('none') and a customer's own cancel now gives nothing back once any of the period's quotas or plan credits were used: it answers refund.kind none with refund.withheld: 'allowance_used', and capabilities.cancelNow.refundWhenAllowanceUsed says which rule applies.
The subscription read says what a customer may do: capabilities.cancelNow carries enabled and refund (none, prorated_credit or prorated_refund). The route is POST /api/v1/public/workspaces/:workspaceId/subscription/cancel-now, or POST /api/v1/public/me/subscription/cancel-now for a person's own plan, with the cancel's body (feedback, comment, retention). It answers subscription (_id, subscriptionStatus, canceledAt) and refund (kind, amount in the currency's smallest unit, currency), and is refused with 403 CANCEL_NOW_OFF while customers cancel at the end of the period. The subscription.canceled webhook fires once Stripe has ended it, as for any cancel. Both need the BuildBase server of this release; the SDK's cancel dialog offers it from 1.0.0.
Operators can end a subscription now from the console whatever the setting, choosing the refund, with yours as the default.
Trials
A trial is offered once per person, not once per workspace. Someone who has had a trial in any workspace, or whose workspace's owner has, is not offered another. The server decides, per plan: each plan version's trial can be once per person (the default), once per person per plan, or once per workspace.
On a plan priced per seat, a trialling workspace holds the seats included in the price by default, so a plan with none included lets nobody join during the trial. Each plan version's trial can instead hold up to the plan's maximum seats, or a set number from 1 to 10000 (trial.seatCap: included, max or a number), and publishing a trial that would hold no seat is refused.
From SDK 1.0.0, two hooks cover trials on your own screens:
useTrialEligibility(workspaceId)answers whether the signed-in person would get a trial in this workspace:eligibilityis{ eligible, reason, usedAt, perPlan }, wherereasonsays why not (for exampleuser_usedorworkspace_used),usedAtis when the trial that used it up started, andperPlansays per plan version whether a checkout would start a trial. It isnullon a server without the route, and refreshes after a checkout.useConvertToPaid(workspaceId)ends a trial now and pays for the plan with the card on file. When the charge goes through,convertedistrueand the subscription is active. When it does not (a declined card, or one that needs authentication), the trial keeps running, nothing changes, andpaymentUrlis Stripe's page for the open invoice. With no card on file, or on a bank debit, it is refused before anything is charged.
import { useConvertToPaid, useTrialEligibility } from '@buildbase/sdk/react';
function TrialActions({ workspaceId }: { workspaceId: string }) {
const { eligibility } = useTrialEligibility(workspaceId);
const { convertToPaid, loading } = useConvertToPaid(workspaceId);
async function payNow() {
const result = await convertToPaid();
if (!result.converted && result.paymentUrl) {
window.location.assign(result.paymentUrl);
}
}
return (
<>
{eligibility && !eligibility.eligible && <p>You have used your trial.</p>}
<button type="button" onClick={payNow} disabled={loading}>
End trial and pay now
</button>
</>
);
}From the workspace's Actions menu in the console, your team can extend a trial, end it now, or let a person trial again (see Managing subscriptions). When a trial is extended, the subscription.trial_extended webhook says so. See Webhooks.
Hooks
| Hook | What it returns |
|---|---|
useSubscription(workspaceId) | Current plan, status, billing interval |
useTrialStatus() | isTrialing, daysRemaining |
useTrialEligibility(workspaceId) | From SDK 1.0.0: eligibility, loading, refetch |
useConvertToPaid(workspaceId) | From SDK 1.0.0: convertToPaid(), loading, error |
useSeatStatus(workspace) | memberCount, includedSeats, canInvite, inviteBlockReason |
usePromotionCode() | check(code, plan or pack), the answer, loading, error |
usePreviewSubscriptionChange(workspaceId) | preview(planVersionId, options?), the answer, loading, error, reset |
useUpcomingInvoice(workspaceId) | The next invoice, loading, error, refetch |
useRetentionOffer(workspaceId) | getRetentionOffer(): the reasons switch, the offer, the Free plan after |
useAcceptRetentionOffer(workspaceId) | acceptRetentionOffer(offerId, reason), loading, error |
usePauseSubscription(workspaceId) | pauseSubscription(months), loading, error |
useAddOns({ currency? }) | The add-ons on sale, public, for a pricing page |
useWorkspaceAddOns(workspaceId) | What the workspace may buy, what it holds, purchasable and reason |
usePurchaseAddOn(workspaceId) | purchaseAddOn(request), preview(offerSlug), loading, error |
useCancelAddOn(workspaceId) | cancelAddOn(grantId), loading, error |
useGrants(workspaceId) | What the workspace holds beyond its plan, for display |
The add-on hooks take { user: true } in place of the workspace id for the signed-in person. See Add-ons.
Note
Every hook in this table from usePromotionCode down to useGrants: Requires @buildbase/sdk 1.0.0 or later.
A pending invitation is billed as a seat, so inviting needs an organization
email sender as well as a free seat. With no sender configured, creating an
invitation is refused with 503 NO_SENDER_CONFIGURED before anything is
written, and no seat is billed for a mail that was never sent. See
Invitations.
The plan decides who takes a seat. By default every active member and every pending invitation takes one. Blocked members don't, and agents and service accounts never do. A plan can change that. It can:
- count only some roles, so you bill editors and leave viewers free
- stop counting pending invitations
- count blocked members too
- bill a minimum number of seats
- sell seats in blocks
On a plan that leaves viewers free, adding a viewer changes nothing on the invoice. Promoting them to editor takes a seat, and is refused at the plan's seat cap, just as an invitation would be. See Seat-based pricing.
Conditional components
| Component | Renders when |
|---|---|
WhenSubscription | Has an active subscription |
WhenNoSubscription | No subscription |
WhenSubscriptionToPlans | On a specific plan (pass plans prop) |
WhenTrialing | In trial period |
WhenNotTrialing | Not in trial |
WhenTrialEnding | Trial ends within daysThreshold days |
Server-side
Check subscription status from your backend:
import BuildBase from '@buildbase/sdk';
const bb = BuildBase({ serverUrl, orgId, getSessionId });
const { subscription, plan } = await bb.subscription.get(workspaceId);
// A trial is a subscription in good standing: let it through.
const allowed = ['active', 'trialing'];
if (!subscription || !allowed.includes(subscription.subscriptionStatus)) {
return Response.json({ error: 'Subscription required' }, { status: 403 });
}Revenue in the console
Billing > Revenue shows what your subscriptions bring in, read from your own data rather than from Stripe. What each figure counts, and a walk through the screen: Revenue and billing health.
Billing health
Billing > Billing health lists what in your billing needs a person, and changes nothing. Each list and what to do about its rows: Revenue and billing health.
Billing versioning switches
Versioned billing keeps what customers bought fixed, moves them between versions, and versions add-ons and credit packages. Each of those parts can be turned off for one organization if it misbehaves there, on the Billing versioning card in Settings > General, which owners and admins (and any role granted organization settings) can change. All three are on unless someone turns one off, the console asks before turning one off, and every change is in the audit log with its value before and after. Nothing is lost while a switch is off: turn it back on and things carry on from where they stood.
| Switch | While it is off |
|---|---|
| Keep what customers bought fixed | A catalog item, the workspace feature it turns on, and a credit package that customers hold can be changed, archived or deleted in place (no CATALOG_ITEM_SOLD or CREDIT_PACKAGE_IN_USE), and holders may lose or gain what they bought at their next renewal or sync. Published plan versions, pricing groups and add-ons still need a new version (VERSION_REQUIRED) |
| Version moves | No move can be previewed, started or confirmed, and a holder a running move waits on cannot be retried (VERSIONING_MOVES_OFF). Moves already made wait where they stand: nobody is moved, sent a notice or told until the switch is on again. Reading a move, cancelling one and leaving a holder where they are still work, and a publish without a move goes ahead |
| Add-on and credit package versions | A new version of an add-on or a credit package is not published, and neither is a lifetime add-on that includes future versions (VERSIONING_OFFERS_OFF). Drafts stay editable, and what customers already hold keeps working |
The same switches are GET and PATCH /api/organizations/settings/billing-versioning
({ "freeze": true, "moves": false, "offers": true }, any of the three).
Next Steps
- Pricing Page - Order, group and highlight what each plan includes.
- Seat-based pricing - Included seats, who takes one, minimums, blocks and the cap.
- Add-ons - Sell capacity, unlocks and packs on top of a plan.
- Failed payments - Chasing a failed payment (dunning), the card-expiring notice and Stripe events that fail.
- Managing subscriptions - Comp, extend a trial, discount or re-sync from the console.
- Credits & Usage - Add consumption-based billing.
- Permissions - Gate billing UI by role.