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:sandboxorproduction. 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.
checkoutBaseUrl is omitted, the SDK resolves bootstrap in this order:
checkoutEnvironmentCLINK_ENV
CLINK_ENV=sandbox maps to https://uat-api.clinkbill.com/api/sdk/bootstrap, and CLINK_ENV=production maps to https://api.clinkbill.com/api/sdk/bootstrap.
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
complete: The checkout reached a terminal payment state, either from the checkout page itself or viapollStatus.hosted_return: A hosted success or cancel page returned control to the parent page. Use this for UI cleanup or navigation.error: An SDK or polling failure, not necessarily a payment terminal state.
Bootstrap Environment
The SDK supports fixing the remote bootstrap environment withCLINK_ENV:
CLINK_ENV=sandbox→https://uat-api.clinkbill.com/api/sdk/bootstrapCLINK_ENV=production→https://api.clinkbill.com/api/sdk/bootstrap
checkoutEnvironment uses the same values: sandbox and production.
Priority order:
loadClink(..., { checkoutBaseUrl })loadClink(..., { checkoutEnvironment })CLINK_ENV
Error Handling
The SDK throwsClinkError for validation, bootstrap, and embedded checkout failures.
INVALID_PUBLIC_KEYINVALID_CHECKOUT_ENVBOOTSTRAP_REQUEST_FAILEDINVALID_BOOTSTRAP_RESPONSEINVALID_REDIRECT_PARAMSINVALID_EMBEDDED_OPTIONSINVALID_SESSION_IDSESSION_ID_FETCH_FAILEDEMBEDDED_CHECKOUT_DISABLEDCONTAINER_NOT_FOUNDNOT_IN_BROWSER