SwitchFlow.mount(options)
| Option | Type | Required | Description |
|---|---|---|---|
container | string | HTMLElement | Yes | CSS selector or element the form renders into |
sessionId | string | Yes | From your server’s session-create response |
clientSecret | string | Yes | From your server’s session-create response |
apiBase | string | Yes | SwitchFlow API origin (https://api.switchflows.net) |
vault | VaultConfig | Yes | The vault block from the session-create response — pass it through unchanged |
onSuccess | (result: SuccessResult) => void | No | Called when the payment is captured |
onDeclined | (result: DeclineResult) => void | No | Called on a terminal decline |
alternativeMethodLabel | string | No | Button label shown if all gateways are down (default: "Pay with PayPal") |
Result shapes
Do not branch fulfillment logic on the widget callbacks alone — they run in
the customer’s browser. Treat the signed
webhook as the source of truth for order fulfillment,
and the callbacks as UX signals.
The vault block
The session-create response includes a vault object that tells the widget
how to tokenize. Pass it to mount() verbatim — its contents depend on your
account’s vault mode and are not something you construct yourself:
saas mode the widget loads the vault’s secure-fields SDK, so card input
is fully isolated from your page’s JavaScript; the widget then submits an
opaque pm_… payment-method token. In shim mode (sandbox) the widget
renders its own fields and tokenizes to vaultBase. Your integration code is
identical in both modes.
Degradation behavior
If the API responds with{ "action": "RETRY_ALTERNATIVE_METHOD" } (all
gateways down within the latency ceiling), the widget replaces the card form
with a single button labeled alternativeMethodLabel. Clicking it is your
page’s cue to present your fallback payment flow. If you configure no
alternative method, the widget shows a retry-later message instead. See
Failover behavior.