NPM Package
View the package on npmjs.com
Create Checkout Session
Create a checkout session on your backend before launching checkout.
Checkout Session Guide
Learn how hosted checkout sessions work end to end.
Installation
Install the SDK from npm with your preferred package manager:dist/index.umd.js, the SDK is exposed as Clink.loadClink(...) on window.
Initialization
Initialize the SDK with your publishable key:pk_test_*, pk_uat_*, and pk_prod_*.
If you already know the final checkout host, you can skip bootstrap by passing checkoutBaseUrl directly:
Init Options
checkoutEnvironment:uatorlive. Used whencheckoutBaseUrlis not provided.checkoutBaseUrl: Checkout host used directly by the SDK. When set, bootstrap is skipped.locale: Forwarded during bootstrap.origin: Override the current site origin.fetchImpl: Customfetchimplementation for non-browser runtimes.
Redirect Checkout
Use redirect checkout when you want Clink to take over the full page flow.redirectToCheckout accepts:
sessionParam: Preferred when available.sessionId: Used when you only have the session ID.replace: Useswindow.location.replace(...)instead ofassign(...).
sessionParam and sessionId are provided, sessionParam wins.
Embedded Checkout
Use embedded checkout when you want the payment flow to stay inside your page.fetchSession must create a checkout session on your backend and return the final checkout URL. The SDK mounts that URL as-is and does not rewrite its query parameters.
Embedded Options
fetchSession: Required. Must resolve{ sessionId, checkoutUrl, orderId? }.onEvent: Receives all checkout lifecycle events.autoResize: Automatically applies iframe height updates. Default:true.autoDestroyOnComplete: Automatically destroys the embedded instance after a successful payment. Default:true.pollStatus: Optional polling hook for terminal state detection.pollIntervalMs: Poll interval in milliseconds. Default:2000.
Embedded Instance API
mount(container): Mount into a CSS selector orHTMLElement.unmount(): Remove the iframe but keep the instance reusable.destroy(): Fully dispose the instance.on(type, handler): Subscribe to a specific event type.getState(): Returns{ mounted, destroyed }.
Events and States
Embedded checkout can emit the following events:| Event | Description |
|---|---|
ready | The checkout iframe is ready or has finished loading. |
resize | The iframe requests a height update. |
state_change | Checkout state changed. |
complete | A terminal state was reached. |
hosted_return | The hosted checkout returned control to the parent page. |
error | SDK or polling error. |
paymentpendingsuccesscancellederrorexpired
Error Handling
The SDK throwsClinkError for validation, bootstrap, and embedded checkout failures.
INVALID_PUBLIC_KEYINVALID_CHECKOUT_ENVBOOTSTRAP_REQUEST_FAILEDINVALID_REDIRECT_PARAMSINVALID_EMBEDDED_OPTIONSSESSION_ID_FETCH_FAILEDEMBEDDED_CHECKOUT_DISABLEDCONTAINER_NOT_FOUND