Initialization
Before using checkout, you must initialize the SDK with your configuration. Call Loby.init() from window.lobyAsyncInit — the SDK invokes this function automatically when the script loads.
Basic Initialization
window.lobyAsyncInit = async function() { await Loby.init({ clientId: 1234, version: 'v1' }) }
Loby.init() can only run once. If it is called again, the SDK returns immediately without re-initializing.
Configuration Options
| Parameter | Type | Required | Description |
|---|---|---|---|
clientId | number | Yes | Your Loby SDK client ID. Found in Settings > Developer Settings in your Loby dashboard. |
version | string | No | API version to use. Currently only 'v1' is supported. |
language | string | No | Initial language code (e.g., 'en', 'da'). Defaults to browser language. |
testMode | boolean | No | When true, the SDK uses test mode data (test membership types, ticket types, and Stripe test keys). Useful for development and testing before going live. Defaults to false. |
Example with All Options
window.lobyAsyncInit = async function() { await Loby.init({ clientId: 1234, version: 'v1', language: 'da', testMode: true }) console.log('Loby SDK initialized!') }
Test Mode
When testMode is set to true, the SDK will only load membership types and ticket types that are marked as test mode in your Loby dashboard. This allows you to test the full checkout flow without processing real payments.
To use test mode:
- Create test membership types or ticket types in your Loby dashboard
- Pass
testMode: truewhen initializing the SDK - Use Stripe test card numbers (e.g.,
4242 4242 4242 4242) to complete test purchases
Remember to remove testMode: true (or set it to false) before going live.
Waiting for Checkout Ready
Loby.init() loads language strings, fetches your workspace configuration, and mounts the SDK. Checkout requires additional background setup (device registration, draft order creation, and form initialization).
Before calling Loby.checkout(), wait for checkout to be ready:
await Loby.waitForCheckoutReady()
If checkout is already ready, this resolves immediately. Call it before every checkout — including on pages where the SDK is preloaded.
Do not rely on await Loby.init() alone before opening checkout.
Example with a checkout button on a preloaded page:
document.getElementById('checkout-button').addEventListener('click', async () => { await Loby.waitForCheckoutReady() Loby.checkout({ type: 'MEMBERSHIP' }) })
Example with on-demand script loading:
async function loadLoby() { await loadLobyScript() await Loby.waitForCheckoutReady() } document.getElementById('checkout-button').addEventListener('click', async () => { await loadLoby() Loby.checkout({ type: 'MEMBERSHIP' }) })
See Installation for the loadLobyScript() helper.
If the user clicks the checkout button twice before the script has loaded, both clicks await the same lobyScriptLoadPromise, then both proceed through waitForCheckoutReady(). Consider disabling the button while loadLoby() runs to avoid opening checkout twice.
Consider showing a loading state on the button while loadLoby() runs on the first click.
User Gestures and Payment Flows
Opening checkout does not require preserving the browser's user-activation token across the script load. Loby.checkout() opens an in-page modal, not a popup or redirect.
Payment and wallet flows (card, Apple Pay, MobilePay, etc.) happen when the user interacts inside the modal — for example, by clicking Pay — which provides its own user gesture.
Getting Your Client ID
Your client ID is a unique identifier assigned to your Loby workspace. To obtain your client ID:
- Log in to your Loby dashboard at loby.cloud
- Navigate to Settings > Developer Settings
- Scroll down to the SDK Client ID section
- Copy your client ID using the copy button
The SDK Client ID is automatically generated for your workspace and cannot be changed.
Error Handling
If initialization fails (e.g., invalid client ID), the promise will reject:
window.lobyAsyncInit = async function() { try { await Loby.init({ clientId: 1234, version: 'v1' }) console.log('SDK ready') } catch (error) { console.error('Failed to initialize Loby SDK:', error) } }