Developers
Open a checkout from code
A data-plandalf-present button covers most sites. When you need to open a checkout from your own code, decide what happens after it, or put it inside your page, use plandalf.present() and plandalf.mount().
Open a checkout in a frame
plandalf.present(slug, options) opens the checkout over your page and returns a handle. Await the handle to find out how it ended.
const result = await plandalf.present('YOUR-CHECKOUT');
if (result.status === 'complete') {
location.href = result.redirectUrl ?? '/thanks?session=' + result.session.uuid;
}
The slug is the checkout's slug from its Share screen, the same value data-plandalf-present takes. Run this from a click handler or inside plandalf('ready', …) so the SDK has loaded. See Call the SDK before it loads.
The result
Result of a presented flow. Always resolved from plandalf.present() —
successful completions and user dismissals both produce a FlowResult so
callers can branch on status without needing a .catch. Only real
errors (network failure, bad slug, etc.) reject the promise.
| Property | Type | What it does |
|---|---|---|
customer optional | Customer | Convenience — same as result.session.customer. |
mode optional | "live" | "test" | "preview" | test when the purchase used test cards (test domain, test link,
mode: 'test'). Never grant real access for a test purchase. |
reason optional | "complete" | "cancel" | "escape" | When dismissed, why — backdrop / close button / escape. |
redirectUrl optional | string | Where to redirect the customer after complete (if the offer configures one). |
session optional | CheckoutSessionPayload | The full CheckoutSession at the moment of completion (populated on
status='complete' only). Invoice + everything else lives in here —
inspect via result.session.uuid, result.session.total,
result.session.invoice, etc. |
status | FlowResultStatus | 'complete' = user finished the flow. 'dismissed' = closed early. |
test optional | boolean | Shorthand for mode === 'test'. |
Check result.test before you give anyone access: it's true for a purchase made with test cards.
The handle resolves both when the buyer finishes and when they close the checkout, so you don't need a catch for a buyer who changes their mind. It only rejects on a real error, such as a wrong slug, a network failure or a server error.
Choose the frame and size
frame picks how the checkout opens and size how wide it is.
plandalf.present('YOUR-CHECKOUT', { frame: 'slideout', size: 'wide' });
plandalf.present('YOUR-CHECKOUT', { size: { w: '900px', h: '640px' } });
| Option | Values |
|---|---|
frame | modal (the default, centred over the page), slideout (from the right), bottom (a sheet from the bottom), fullscreen |
size | compact (700px), standard (1050px, the default), wide (1400px), fullscreen, or { w, h } |
The same choices work on a button with data-plandalf-frame and data-plandalf-size.
Put a checkout on the page
plandalf.mount(target, slug, options) renders the checkout inside your own element instead of a frame. The checkout fills the element, so size the element with your own CSS.
<div id="checkout" style="min-height: 560px"></div>
<script>
plandalf('ready', async () => {
const flow = plandalf.mount('#checkout', 'YOUR-CHECKOUT');
for await (const event of flow.events) {
if (event.type === 'complete') location.href = '/thanks';
}
});
</script>
A mounted checkout has no frame to close, so its handle resolves as soon as the checkout is on the page, not when the buyer finishes. Watch .events for complete instead. A target selector that matches nothing rejects the handle.
Without code, <div data-plandalf-mount="YOUR-CHECKOUT"></div> does the same when the page loads.
Live events and closing
The handle from present() or mount() is a Promise with two extras:
.eventsyields each event as it happens:startwhen the checkout opens,purchasefor each payment that goes through,completewhen the buyer finishes, andcancelwhen they close it. Usefor await, andbreakto stop listening..close()closes the checkout from your code.
const flow = plandalf.present('YOUR-CHECKOUT');
for await (const event of flow.events) {
if (event.type === 'purchase') analytics.track('purchase', { total: event.invoice_total });
}
const result = await flow; // still resolves once the checkout closes
For a button the SDK bound itself, plandalf.from(button) returns its handle once it has been clicked, and null before. Every event name and its data are in Events.
Prefill fields and pass metadata
plandalf.present('YOUR-CHECKOUT', {
properties: { email: 'ada@example.com', company: 'Analytical Engines' },
metadata: { crm_id: 'contact_1815' },
});
propertiespre-fills checkout fields, keyed by field ID. The buyer sees them and can change them. They're saved on the checkout session and show on the customer in the dashboard.metadatais copied to the Stripe customer's metadata when Plandalf creates the customer, and merged into it for a returning customer. The buyer never sees it. Keys can be up to 40 characters and values up to 500, with at most 50 entries; empty values are dropped. Here values must be strings; for values read at checkout time, use a function inplandalf('configure', { metadata }).
Values passed to one call win over page-wide values set with configure.
Other options you'll use
| Option | What it does |
|---|---|
promo | A deadline timer slug. The checkout uses the price of the deadline timer's current tier. See Deadline timers from code. |
user | A signed buyer token for this checkout only, overriding identify(). See Identify buyers. |
subscription | The id of a subscription this checkout should change, for an upgrade. Leave it out for a new purchase. |
continuity, session | Whether to reopen the buyer's unfinished checkout. See Session continuity. |
mode | 'test' asks for a test checkout. It's honoured on your test domains, for a signed buyer token with "mode": "test", and for people signed in to your Plandalf organization; everyone else gets the live checkout. See Test mode. |
confirmClose | A function run when the buyer tries to close the checkout. Return true (or a Promise of it) to let it close, false to keep it open. Passing true instead of a function shows Plandalf's own "are you sure?" prompt; the TypeScript type only accepts a function. |
mount() takes promo, user, subscription, continuity, session, mode, properties and metadata. It has no frame, size or close confirmation.
All options
present()
Some names below are kept only so older code keeps working. Await the handle instead of passing onComplete, onClose or onError (they still run). Use frame and size instead of width, height, position, backdrop, closeOnBackdrop, closeButton, dragToClose, animation and duration, and a confirmClose function instead of the confirm… labels. environment is the old name for mode.
Options for opening an offer in a frame. present() takes these (see PresentOptions).
| Property | Type | What it does |
|---|---|---|
confirmClose optional | () => boolean | Promise<boolean> | Merchant-supplied "are you sure?" gate. Resolved true allows the close
to proceed, false keeps the frame open. Replaces the previous boolean
+ label/title strings combo. Off when omitted. |
continuity optional | ContinuityScope | Per-call continuity override. |
frame optional | FrameMode | Frame modality. Was previously mode — renamed because mode now means
the test/live/preview environment (see below). |
metadata optional | Record<string, string> | Per-call Stripe-customer metadata. Eager string values only — for window-global lookups use the page-global PlandalfConfig.metadata thunk form. Wins over PlandalfConfig.metadata on overlap. |
mode optional | "live" | "test" | "preview" | Environment for the session: 'test' | 'live' | 'preview'. Was previously
environment. The server decides: with 'test', the checkout runs in test mode on the organization's test domains, for people signed in to the organization, with an identify() token carrying "mode": "test", or from a signed test link; anywhere else it runs live. Test mode also needs the organization's Stripe test account.
'preview' is for the dashboard editor; on a page it runs live. |
promo optional | PromoContext | Promo whose active tier price applies. |
properties optional | Record<string, unknown> | Per-call form-field prefill defaults. Wins over PlandalfConfig.properties on overlap. See specs/sdk-checkout-config.md. |
session optional | string | null | Session continuity token (cks_…). Pass explicitly to resume a specific session
server-side — cross-device handoff, email "continue your checkout" links, anywhere the
merchant has a token in hand. Pass null to force a fresh session and skip any stored
token. Omit entirely to let the SDK auto-detect. |
size optional | FlowSize | { h: string; w: string } | Size of the modal panel. Either a named preset OR an explicit
{ w, h } object for one-off cases. Defaults to 'standard'. |
subscription optional | string | The customer's existing Stripe subscription id (sub_…) to change instead of starting a
new one: the checkout moves that subscription to the offer's plan (or adds the offer's
add-ons to it) and never creates a second subscription. Omit it and the subscription
claim of the identify() token is used. Pass it when a customer holds several subscriptions. |
user optional | string | Customer JWT for THIS call only — overrides the SDK-wide identity from
plandalf.setUser() or the user init option. Useful for "buy as customer"
admin tooling, impersonation flows, or offers that need a different identity
than the global one. The value is the raw JWT string. |
mount()
Options accepted by plandalf.mount(target, slug, opts?).
Inline mount has fewer knobs than present() because there's no frame —
no modality, no size preset (the mount fills its container), no confirm-close
gate (nothing to close).
| Property | Type | What it does |
|---|---|---|
continuity optional | ContinuityScope | Per-call continuity scope override. |
metadata optional | Record<string, string> | Per-call Stripe-customer metadata. Eager strings only. |
mode optional | "live" | "test" | "preview" | Environment for the session: 'test' | 'live' | 'preview'. Same rules as present()'s
mode: test applies on the organization's test domains, for people signed in to the
organization, with an identify() token carrying "mode": "test", or from a signed test
link (and needs the organization's Stripe test account); anywhere else it runs live. |
promo optional | string | Promo slug; the SDK resolves the active tier internally and applies its price. |
properties optional | Record<string, unknown> | Per-call form-field prefill. Wins over PlandalfConfig.properties on overlap. |
session optional | string | null | Session continuity token. Pass null to force fresh. Omit for default. |
subscription optional | string | Checkout-specific subscription to change. Omit for a new purchase. |
user optional | string | Per-call JWT override — overrides the global identify() for this mount. |