Skip to main content
In the examples, kerne is your secret-key client and asUser is kerne.withToken(userAccessToken), a client that acts as one signed-in user.

List plans

Your public pricing, for a pricing page. No secret key needed.
amount is in the currency’s smallest unit (2900 is 29.00). interval is a count and a unit, D, M or Y: 1M is monthly, 1Y yearly. A price’s label groups equivalent prices across plans, such as every plan’s annual price.

Find a price id

Reads your default product. Throws a NotFoundError if the plan or the label doesn’t exist, and a ValidationError if the plan has several prices and you didn’t pass a label.

Start a checkout

Pass a price id or slug, not a plan id: a plan can have several prices, and a plan id fails with PLAN_PRICE_NOT_FOUND.
string
Who the subscription is for. Required with a secret key; omit it on a withToken() client.
string
Required when the customer has no email on file. Also creates the customer if it doesn’t exist.
{ feature_key, steps }[]
Prepaid allowances the buyer chose. Stripe only. steps is capped at the plan’s maximum.
The subscription is created when the payment provider confirms payment, shortly after the customer comes back, not when this call returns. After checkout, the customer lands on your hosted portal, which sends them back to your app: to Send users back to if you set it, otherwise to your Production URL. Both are in Settings → General.

Embedded card checkout

Stripe only. For a card form you build with Stripe.js instead of the hosted checkout page:
createSubscriptionHeadless() requires your secret key, and Kerne checks with Stripe that the payment method belongs to this customer. Pass email when the customer has no email on file.
In CI or a seed script, pass testCardToken: 'tok_visa' instead of stripePaymentMethodId: it creates a new payment method on each call. Stripe test mode only.

Read subscriptions

list() also filters by productSlug. On a withToken() client it only returns that user’s subscriptions.
status is ACTIVE, TRIALING, PAST_DUE, CANCELED, UNPAID or PAUSED. PAST_DUE keeps access unless your payment failure policy ends it; UNPAID ends it.

Change plan

Takes a price id or slug. The change applies immediately, upgrade or downgrade, and the provider prorates by default. The subscription moves to the new plan’s current offer version. Scheduling a downgrade for the end of the period isn’t supported yet.

Cancel

By default access continues until the paid period ends: canceled_at is set now, and status becomes CANCELED at the end of the period. Cancelling immediately sets both now. Either way the payment provider is told first, so no further invoice goes out, and the subscription is kept for history. billing.cancel() throws a NotFoundError (NO_ACTIVE_SUBSCRIPTION) when the user has no subscription.

Billing portal

The payment provider’s page, where the customer updates their payment method, downloads invoices and manages their plan. They come back through your hosted portal, like after checkout.