Bootstrapper

The Morefin cashier bootstrapper is a lightweight iframe embed package. It builds the cashier URL from request parameters and mounts the cashier inside an iframe so host styles stay isolated from the checkout UI.

Package

Install:

npm install @morefin/cashier-bootstrapper

How It Works

  • Create a CashierBootstrapper instance.
  • Pass requestParams that should be sent to the cashier.
  • Pass properties.environment so the package knows which Morefin environment to target.
  • The bootstrapper creates and mounts an iframe.
  • Once the cashier iframe is ready for host configuration, it exposes a small runtime API such as setCss and updateData.
  • The iframe is revealed after host configuration is applied, so custom CSS can be injected before the customer sees the cashier.

The bootstrapper waits for the cashier runtime to be ready before calling the host onReady callback. This prevents the cashier from briefly rendering with default styling before merchant CSS is applied.

Environment

The README examples use:

const CASHIER_ENVIRONMENT = 'uat' as const; // 'production' | 'uat'

Basic Embed

import { CashierBootstrapper } from '@morefin/cashier-bootstrapper';

new CashierBootstrapper('#cashier-root', {
  properties: { environment: CASHIER_ENVIRONMENT }
});

Custom Request Params And Iframe Options

import { CashierBootstrapper } from '@morefin/cashier-bootstrapper';

new CashierBootstrapper('#cashier-root', {
  requestParams: {
    merchantId: 'merchant-123',
    terminalId: 'terminal-456',
    userId: 'user-789',
    sessionId: 'session-abc',
    locale: 'sv_SE',
    channel: 'ios',
    predefinedAmounts: [100, 200, 300],
    layout: 'default',
    transactionType: 'deposit',
    attributes: {
      campaign: 'spring-launch',
      isVip: true
    }
  },
  properties: {
    environment: CASHIER_ENVIRONMENT,
    iframe: {
      height: '720px',
      minHeight: '640px',
      title: 'Morefin Cashier',
      attributes: {
        'data-testid': 'cashier-iframe'
      }
    }
  }
}, api => {
  console.log('Cashier iframe ready', api.iframe);
});

requestParams.channel selects the cashier payment method order channel. Supported values are windows, mac, ios, android, and other. When omitted, the bootstrapper derives the channel from the customer device.

requestParams.attributes sends custom cashier data as the attributes query parameter. Use it for values the cashier should receive as part of the request payload. It does not control payment method ordering.

properties.iframe.attributes applies plain HTML attributes directly to the rendered <iframe>. Use it for DOM concerns such as data-*, loading, or other iframe element attributes.

requestParams.channel is a first-level request parameter. Do not put it inside requestParams.attributes when you want to control payment method ordering.

Provide Container Via Config

If you do not pass a container as the first constructor argument, the bootstrapper can use properties.container:

import { CashierBootstrapper } from '@morefin/cashier-bootstrapper';

new CashierBootstrapper(null, {
  properties: {
    environment: CASHIER_ENVIRONMENT,
    container: '#cashier-root'
  }
});

Runtime Controls And Host Configuration

import { CashierBootstrapper } from '@morefin/cashier-bootstrapper';

new CashierBootstrapper('#cashier-root', {
  properties: { environment: CASHIER_ENVIRONMENT }
}, api => {
  api.setCss(`
    .payment-layout-root .payment-container {
      border: 2px dashed hotpink;
    }
  `);

  api.updateData({ userId: 'updated-user' });
});

The bootstrapper calls onReady after the cashier iframe has registered its runtime message listener. The iframe stays hidden behind a loading overlay while host configuration runs. After onReady completes, the bootstrapper notifies the cashier that host configuration is done and reveals the iframe after the cashier confirms that the configuration has been applied.

If the cashier build does not support the ready/configuration events, the bootstrapper falls back to iframe load and reveal timeouts after 3 seconds to preserve existing integrations.

Available runtime helpers:

  • api.setCss(css: string) injects CSS into the cashier iframe.
  • api.updateData(data: object) posts updated app data into the cashier iframe.
  • api.pause() sends a pause signal to the cashier.
  • api.resume() sends a resume signal to the cashier.

Host configuration uses this event flow:

  1. The cashier posts CASHIER_READY after its message listener is registered.
  2. The bootstrapper calls the host onReady(api) callback.
  3. The host can call runtime helpers such as api.setCss(...) or api.updateData(...).
  4. When onReady finishes, the bootstrapper posts CASHIER_HOST_CONFIG_DONE to the cashier.
  5. The cashier applies host configuration, temporarily disables transitions/animations during CSS application, and posts CASHIER_HOST_CONFIG_APPLIED.
  6. The bootstrapper reveals the iframe and removes the loading overlay.

If CASHIER_READY is not received from an older cashier build, the bootstrapper falls back to iframe load after 3 seconds. If CASHIER_HOST_CONFIG_APPLIED is not received, the iframe is revealed after a 3-second fallback timeout.

For asynchronous merchant configuration, return or await the async work from onReady. The cashier stays in its host-configuration loading state until the returned promise completes.

import { CashierBootstrapper } from '@morefin/cashier-bootstrapper';

new CashierBootstrapper('#cashier-root', {
  properties: { environment: CASHIER_ENVIRONMENT }
}, async api => {
  const css = await fetch('/merchant-cashier-theme.css').then(response => response.text());
  api.setCss(css);
});

Avoid starting async setup without returning it. In this example, the bootstrapper cannot wait for the timer, so the cashier may become visible before the CSS is applied:

new CashierBootstrapper('#cashier-root', {
  properties: { environment: CASHIER_ENVIRONMENT }
}, api => {
  setTimeout(() => {
    api.setCss(css);
  }, 1000);
});

Cashier Reset On Back To Payment Selection

When a customer reaches a failed cashier result page, the cashier shows a Back action that returns the customer to the payment selection screen.

Inside the bootstrapper iframe, this reset uses the same loading and host-configuration lifecycle as the initial cashier load:

  1. The customer clicks Back on the failed result page.
  2. The cashier posts CASHIER_RESETTING to the parent page before navigating back to the cashier entry URL.
  3. The bootstrapper hides the iframe and shows the loading overlay again.
  4. The cashier reloads the payment selection screen and posts CASHIER_READY.
  5. The bootstrapper calls onReady(api) again, so merchant CSS and runtime data can be applied to the reset cashier screen.
  6. After host configuration is applied, the bootstrapper reveals the iframe again.

No extra host callback is required for this reset flow. If your onReady callback loads CSS or data asynchronously, keep returning the promise so the reset screen is also hidden until that work is complete.

Transaction Result Callbacks

import { CashierBootstrapper } from '@morefin/cashier-bootstrapper';

new CashierBootstrapper('#cashier-root', {
  properties: { environment: CASHIER_ENVIRONMENT },
  callbacks: {
    onSuccess: ({ status, transactionId }) => {
      console.log('Cashier success callback', status, transactionId);
    },
    onFailure: ({ status, message, transactionId }) => {
      console.log('Cashier failure callback', status, message, transactionId);
    },
    onCancel: ({ status, transactionId }) => {
      console.log('Cashier cancel callback', status, transactionId);
    },
    onValidationFailed: ({ message }) => {
      console.log('Cashier validation failed callback', message);
    }
  }
});

Callback mapping:

  • onSuccess: result status APPROVED or DECLINED
  • onFailure: result status INVALID, or an explicit cashier error event
  • onCancel: result status CANCELLED
  • onValidationFailed: cashier /validate failed and forwards a message

API

new CashierBootstrapper(container, config?, onReady?)

Iframe-based embed that loads the cashier URL and exposes runtime controls once ready.

Parameters:

  • container: string | HTMLElement | null | undefined Where the iframe is appended. If omitted, config.properties.container is used. If neither is provided, it falls back to document.body.
  • config?: CashierIframeConfig Request parameters and iframe properties.
  • config.properties.environment Required environment selector.
  • config.callbacks?: CashierCallbacks Optional host handlers for cashier result events.
  • onReady?: (api: CashierIframeApi) => void | Promise<void> Called when the cashier iframe is ready for runtime messages. If it returns a promise, the bootstrapper waits for it before notifying the cashier that host configuration is complete.

onReady can be synchronous or asynchronous. Return a Promise when merchant CSS or app data must be loaded before the cashier is revealed.

Supported Config Shape

interface CashierRequestParams {
  merchantId?: string;
  terminalId?: string;
  userId?: string;
  sessionId?: string;
  locale?: string;
  channel?: CashierRuntimeChannel | string;
  predefinedAmounts?: number[];
  layout?: string;
  transactionType?: string;
  attributes?: Record<string, unknown>;
}

type CashierRuntimeChannel = 'windows' | 'mac' | 'ios' | 'android' | 'other';

type CashierEnvironment = 'production' | 'uat';

interface CashierIframeOptions {
  width?: string;
  height?: string;
  minHeight?: string;
  title?: string;
  allow?: string;
  sandbox?: string;
  attributes?: Record<string, string>;
}

interface CashierIframeProperties {
  environment: CashierEnvironment;
  container?: string | HTMLElement;
  iframe?: CashierIframeOptions;
}

interface CashierIframeConfig {
  requestParams?: CashierRequestParams;
  properties?: CashierIframeProperties;
  callbacks?: CashierCallbacks;
}

interface CashierResultCallbackPayload {
  status?: string;
  transactionId?: string;
  message?: string;
}

interface CashierValidationFailedPayload {
  message: string;
}

interface CashierCallbacks {
  onSuccess?: (payload: CashierResultCallbackPayload) => void;
  onFailure?: (payload: CashierResultCallbackPayload) => void;
  onCancel?: (payload: CashierResultCallbackPayload) => void;
  onValidationFailed?: (payload: CashierValidationFailedPayload) => void;
}

Notes

  • predefinedAmounts is sent as repeated query parameters.
  • The cashier path is handled internally by the package.
  • The bootstrapper adds a temporary loading overlay and hides the iframe until host configuration has finished, or until the fallback reveal timeout is reached.
  • When the cashier posts CASHIER_RESETTING, the bootstrapper returns to the loading-overlay state and waits for the next ready/configuration cycle before showing the iframe.
  • Custom CSS received through setCss or updateData is applied without transitions or animations during the host-configuration phase.
  • The current package types also expose local development environments such as local and local4200, but the README examples document production and uat.

The host-configuration loading flow applies to cashier usage inside the bootstrapper iframe. Standalone cashier usage outside an iframe is not blocked by this loading state.

Cashier Flows

Cashier Merchant Platform Integration