OleqPay Docs
Checkout

Browser SDK

OleqPayCheckout — openIframe, redirect, close, and buildUrl.

Construct

import { OleqPayCheckout } from '@oleq-ai/pay';

const oleqpay = new OleqPayCheckout({
  checkoutBaseUrl: 'https://my.olefi.co',
  locale: 'en',
});

Methods

openIframe(payloadOrUrl, options?)

Opens hosted checkout in a modal iframe. Browser-only — throws OleqPayCheckoutError (ssr_unsupported) on the server.

Accepts either a CheckoutPayload or a pre-built session URL string.

oleqpay.openIframe(payload, {
  onSuccess: (event) => {},
  onError: (event) => {},
  onClose: () => {},
});

// or a server-minted URL
oleqpay.openIframe(sessionUrl, { onSuccess, onError, onClose });

Re-opening replaces any existing modal and message listener.

redirect(payloadOrUrl)

Sets window.location to the checkout URL. Browser-only.

close()

Closes the active modal and removes the postMessage listener.

buildUrl(payload)

Returns a checkout URL. Safe on the server (no DOM). Prefer this for Nest/backends so amount and order fields are baked into the URL before the browser sees them.

const url = oleqpay.buildUrl({
  apikey: process.env.OLEQPAY_PUBLIC_KEY!,
  amount: order.total,
  orderid: order.id,
  reference: order.reference,
  returnurl: order.returnUrl,
});

Events

The checkout page posts messages to the parent. The SDK only accepts events from the checkout origin.

typeMeaning
oleqpay:readyCheckout UI mounted (ignored by default)
oleqpay:successPayment succeeded — vreference, optional amount
oleqpay:failedPayment failed — optional vreference, message
oleqpay:closeUser closed checkout from inside the iframe

Errors

OleqPayCheckoutError has a stable code:

CodeWhen
ssr_unsupportedopenIframe / redirect called outside the browser
invalid_api_keyMissing, too short, or secret (sk_…) key
invalid_payloadMissing/invalid orderid, reference, amount, or URLs

On this page