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.
type | Meaning |
|---|---|
oleqpay:ready | Checkout UI mounted (ignored by default) |
oleqpay:success | Payment succeeded — vreference, optional amount |
oleqpay:failed | Payment failed — optional vreference, message |
oleqpay:close | User closed checkout from inside the iframe |
Errors
OleqPayCheckoutError has a stable code:
| Code | When |
|---|---|
ssr_unsupported | openIframe / redirect called outside the browser |
invalid_api_key | Missing, too short, or secret (sk_…) key |
invalid_payload | Missing/invalid orderid, reference, amount, or URLs |