View as Markdown

Hosted checkout

Send a customer to a payment page we run. It shows their plan, takes the card through Stripe and starts the subscription.

How it works

  1. Your server opens a checkout session for a customer and gets back a URL.
  2. You redirect the browser to that URL.
  3. The payer confirms. We save the payment method, create the subscription and charge the first invoice.
  4. We send checkout.session.completed, and the payer is sent to your success_url.

The page carries your brand: logo, colour, support email and links come from your branding settings. Totals, tax and discounts are always worked out by the server; the browser never sends a price.

Open a session

Needs a secret key with the checkout:write scope.

checkout.ts
const session = await mint.checkout.create({
  customerExternalId: 'ws_123',
  planCode: 'starter_annual',
  seats: 5,
  promotionCode: 'LAUNCH20',
  trialDays: 14,
  metadata: { source: 'pricing_page' },
  successUrl: 'https://app.example.com/billing/done',
  cancelUrl: 'https://app.example.com/billing',
})
 
redirect(session.url)

The reply has the session id, its url and expires_at. A session is valid for 24 hours.

Fields

FieldNotes
customer_external_id or customer_idExactly one. The customer must already exist.
items1 to 10 plans, each named by plan_id or plan_code, with an optional quantity.
plan_id or plan_code, with seatsShorthand for a single item.
modesubscription (the default), or setup to save a payment method without subscribing.
promotion_codeApplied up front. It is checked when you open the session, so a bad code fails here and not in front of the payer.
allow_promotion_codesWhether the payer may type a code. Default true.
lock_itemsFix the plan, seats and interval. The page shows them read-only. Default false.
trial_days0 to 730. Without it, the product's own trial length applies.
success_url, cancel_urlRequired. https, or http for localhost.
metadataUp to 50 string values, copied onto the subscription.

A metered item names a meter and has no quantity. It needs a monthly metered plan, and it cannot be the first item.

After payment

The payer is sent to success_url with ?session_id=… added. Do not grant access on that redirect: a payer can close the tab before it happens.

Grant access when you receive checkout.session.completed or invoice.paid. For a subscription, the event's data has subscription_id, invoice_id, amount_due_cents, currency and your metadata. For a setup session it has payment_method_id.

In this event data.mode is the kind of session, subscription or setup. It is not test or live.

A payer who submits twice is not charged twice: the second submit returns the result of the first.

Refusals

CodeStatusWhen
not_found404The customer or a plan does not exist, or the plan is inactive.
promotion_code_invalid422The promotion code does not apply to this customer or plan.
unprocessable422An item cannot be billed as asked, such as a meter on a plan that is not metered.
validation_failed422A field is missing or malformed.

Security

  • The session URL holds a signed token that expires. A forged, expired or unknown token answers 404.
  • Hosted pages send a Content-Security-Policy that allows only our origin and Stripe, cannot be framed by another site, and are not indexed by search engines.
  • A secret key is never needed in the browser.

On this page