Widget integration

Embed the payment widget

Drop the rezolvepay.js SDK onto your site with a single <script> tag, mint a one-time widget token on your server, then hand it to RezolvePay.mount(container, { widgetToken }). That's the whole integration. Your merchant API key never leaves your server.

Step 1: Mint a one-time widget token on your backend

From your server, POST /api/v2/checkout/init with your merchant credentials, the order details (amount, currency, order_id) and customer_phone. The response contains a single-use widget_token (valid 15 minutes) that already encodes those values. customer_phone is required: a request without it fails with 422. customer_email is optional backup contact, not the phone wallet's identity.

For a subscription, mint with POST /api/v2/checkout/subscription/init instead. It takes the same fields plus recurring, and requires customer_email as well as customer_phone. Subscriptions need a Stripe merchant.

POST /api/v1/checkout/init is deprecated. It keeps working, with no end date announced yet. Mint one-time payments with POST /api/v2/checkout/init and subscriptions with POST /api/v2/checkout/subscription/init. The v2 endpoints take no customer_registered flag, so registered customers (below) still mint with v1 for now.

Step 2: Render the page with the token

Inject the widget_token into your page's render context (template variable, hydrated state, etc.). It's a single-use credential — never log it, never reuse it.

Step 3: Mount the widget

Add the SDK <script> tag, then call RezolvePay.mount(container, { widgetToken, customerPhone, onSuccess, onContinueToShop }). The shopper picks card (or a saved card on return) and pays. The merchant supplies the phone; the widget does not capture or edit it.

customerPhone is optional and only used for display. The customer_phone on the token is what the widget actually uses: it identifies the shopper's saved cards and receives the SMS code. Pass the same phone to mint and mount. A phone given only at mount cannot enable saved cards. See Saved cards and SMS verification below.

onSuccess({ paymentId }) fires immediately when the payment is confirmed — use this to update your order state or trigger server-side fulfilment. The widget remains visible.

onContinueToShop() fires when the shopper clicks Continue to shop on the success screen — use this to navigate away or unmount the widget.

Security: Never include your merchant API key in client-side code. The SDK doesn't need it — only the widget_token minted server-side. Each token is single-use and expires in 15 minutes.

Theme

RezolvePay.mount takes an optional theme: 'light' or 'dark'. It defaults to 'light', so an integration that doesn't pass it looks exactly as before. Any other value, including a different casing such as 'Dark', falls back to 'light'.

RezolvePay.mount("#rezolve-pay-container", {
  widgetToken: "WIDGET_TOKEN_FROM_SERVER",
  theme: "dark",
});

With 'dark', every widget screen is dark: the payment options, the saved-cards screens, the code entry, the success and failure screens, the Remove card? dialog and the card number, expiry and CVC fields.

Apple Pay and Google Pay use the button presets that Apple and Google publish for the background: the white presets on 'light' and the dark presets on 'dark'. They are never restyled.

The theme option only takes effect in a widget release that includes it. A release pinned before that stays light and ignores the option, so check the release you pin in the script tag.

Saved cards and SMS verification

Shoppers can save cards to a wallet tied to their mobile number and reuse it with any RezolvePay merchant. The widget runs the whole flow. Your only part is passing customer_phone when you mint the token.

When saved cards are offered. Both of these must hold. Otherwise the widget shows a guest card form and the purchase still goes ahead.

  • The token was minted with a customer_phone.
  • The phone is a valid mobile number in a supported country.

What the shopper sees.

  1. Unlock saved cards. The widget sends a 6-digit code by SMS to the masked phone it shows (for example +44*******123). The shopper cannot change the number inside the widget.
  2. Verify. The shopper enters the code, and may also be asked to confirm with a passkey (Face ID, Touch ID or a security key).
  3. Pay. The shopper picks a saved card or adds a new one. Choosing Save card for a new card also requires the code, the first time and every later time a card is added.

Remembered devices. After a successful verification the device is remembered for 30 days. The 30 days are counted from verification, and using the device does not extend them. On a remembered device the shopper can list saved cards, pay with one, change the default card or remove a card without a new code. Adding a card or signing out of all devices always needs a fresh verification.

Cancelling. If the shopper closes the SMS or passkey prompt, nothing is charged. When they were saving a card, the widget offers Pay without saving so the order can still complete.

Phone formatting: POST /api/v2/checkout/init accepts international + or 00 input, or UK national 07…. ASCII spaces, hyphens and parentheses are allowed; extensions and other characters are rejected with 400. Valid numbers are stored in canonical E.164 (+44 (0)7400 123456 becomes +447400123456). A well-shaped number that numbering metadata rejects still permits guest-only checkout. Accepting a number does not mean saved cards will be offered for it. That depends on the rules above.

Registered customers

If your shoppers sign in to an account with you and you have verified their email address, the widget can show the cards they saved with you without an SMS code or a passkey. It is off by default. Turn it on only if you accept the trade-offs at the end of this section.

Turn it on. A merchant admin switches on Skip verification for registered customers in the Portal's merchant settings. Every change is recorded in your audit log.

Mint the token. For a signed-in shopper, add customer_registered: true and their customer_email to POST /api/v1/checkout/init. The flag is not available on the v2 endpoints yet, so this is the one case that still mints with the deprecated v1:

{
  "amount": 2599,
  "currency": "GBP",
  "order_id": "ORD-4421",
  "customer_email": "[email protected]",
  "customer_registered": true
}
  • Without customer_email the call fails with 400 customer_email is required when customer_registered is true.
  • While the setting is off it fails with 400 registered customers are not enabled for this merchant. There is no fallback to SMS, even when the token has a phone.
  • Without the field, or with false, the checkout works exactly as in the rest of this guide, whatever the setting.

What the shopper sees.

  • The cards they saved with you under that email are listed straight away, with their default card selected.
  • Paying with a saved card needs no code. The card issuer may still ask for 3-D Secure.
  • Save card still needs the shopper to tick the box, and nothing else. The card is saved for that email at your shop only.
  • Changing the default card or removing a card needs no code either.
  • These cards are visible only to you. Another merchant that sends the same email sees none of them, and they never join the shopper's phone wallet.

With a phone too. A registered token ignores customer_phone for saved cards. The shopper sees only the cards saved with you, gets no SMS code, and cannot reach their phone wallet in that checkout. A card saved during that checkout is saved to the registered cards. Send the flag only when you want the registered cards; leave it out to offer the phone wallet as in Saved cards and SMS verification.

Switching it off takes effect at once, also for tokens you already minted: they behave as if minted without the flag. Nothing is deleted. The cards stay available through GET /api/v1/customers/saved-payment-methods and reappear in the widget if you switch the setting back on.

The mobile SDK does not support registered customers yet. A token minted with the flag behaves there as one minted without it, except that after the SMS code the card list also includes the registered cards.

Trade-offs you accept.

  • Whoever holds a token minted with the flag can see and pay with that shopper's saved cards. You are liable for account takeover on your side, so send the flag only for a shopper who is signed in and whose email you have verified.
  • Your merchant API key can mint such a token for any email. A leaked key exposes your registered customers' cards, though never a phone wallet or another merchant's cards. Keep the key on your server.
  • When a shopper changes their email with you, their saved cards stay under the old email.
  • When you give an email to a new account holder, that holder sees the previous holder's cards at your shop.

Script tag with SRI

<script
  src="https://secure.pay.rezolve.com/widget/1.1.4/rezolvepay.js"
  integrity="sha384-qwulfqVbaOqstTMHtRVCdrZUxvwSv/iZcTcbIPax9P5Rrkz3XkcO+kiBetNn4aaA"
  crossorigin="anonymous"
></script>

Load the script from this host exactly as shown — it is not the same host as your API calls. A passkey belongs to one domain, and the loader creates the checkout on whichever host it was loaded from, so a script tag pointing anywhere else saves the shopper's passkey against the wrong domain and we can never recognise her again. Nothing errors when that happens, which is why the host matters. Every other example on this page keeps using your API base URL.

Choosing a version

Every published release, with its integrity hash, is listed at https://secure.pay.rezolve.com/widget/releases.json. The newest release comes first. The values below are only an example:

{
  "releases": [
    {
      "version": "1.2.0",
      "path": "/widget/1.2.0/rezolvepay.js",
      "integrity": "sha384-…"
    }
  ]
}

Use the list when you pick or upgrade a version. Put the widget host in front of path, copy that URL and integrity into your page, and commit them with the rest of your code.

Do not read the list from your shopper's browser to build the script tag, and never fetch it when the page loads. The hash protects you only because it lives in your own code. A hash read from our server at page load would match whatever our server sends, so it would protect nothing. For the same reason there is no address that always serves the newest release.

A version can leave the list. It keeps working for merchants who already pinned it, but it is no longer offered to anyone choosing a version.

Mount the widget

HTML

<!-- 1. Load the SDK (see "Script tag with SRI" above) -->
<!-- 2. Mount point for the widget -->
<div id="rezolve-pay-container"></div>

<script>
  // widgetToken is rendered into the page by your server
  // (see the Node.js / cURL example below).
  RezolvePay.mount("#rezolve-pay-container", {
    widgetToken: "WIDGET_TOKEN_FROM_SERVER",
    customerPhone: "+447700900123", // same phone used when minting the token
    customerEmail: "[email protected]", // optional backup contact
    theme: "light", // optional: "light" (default) or "dark"

    // Fires immediately when payment is confirmed (notification hook).
    // Update your order state here; the widget stays visible.
    onSuccess: ({ paymentId }) => {
      console.log("Payment confirmed:", paymentId);
    },

    // Fires when the shopper clicks "Continue to shop" (navigation hook).
    // Navigate away or unmount the widget here.
    onContinueToShop: () => {
      window.location.href = "/order-confirmed";
    },

    onFailure: ({ message }) => { console.error(message); },
    onCancel:  () => { /* shopper closed the widget */ },
  });
</script>

TypeScript

// Type definitions (until @rezolvepay/sdk ships):
declare global {
  interface Window {
    RezolvePay: {
      mount(
        selector: string | Element,
        opts: {
          widgetToken: string;
          /** Display hint only; customer_phone on the token is authoritative. */
          customerPhone?: string;
          customerEmail?: string;
          /** Widget theme. Defaults to 'light'; any other value falls back to 'light'. */
          theme?: 'light' | 'dark';
          /** Fires immediately when payment is confirmed. Widget stays visible. */
          onSuccess?: (r: { paymentId: string }) => void;
          /** Fires when the shopper clicks "Continue to shop". Use for navigation. */
          onContinueToShop?: () => void;
          onFailure?: (r: { message: string }) => void;
          onCancel?:  () => void;
        },
      ): { unmount: () => void } | null;
    };
  }
}

export function mountCheckout(
  containerId: string,
  widgetToken: string,
  customerEmail?: string,
  customerPhone?: string,
) {
  return window.RezolvePay.mount(`#${containerId}`, {
    widgetToken,
    customerPhone,
    customerEmail,
    onSuccess: ({ paymentId }) => {
      console.log("Payment confirmed:", paymentId);
    },
    onContinueToShop: () => {
      window.location.href = "/order-confirmed";
    },
    onFailure: ({ message }) => console.error(message),
  });
}

React

import { useEffect, useRef } from "react";

interface CheckoutWidgetProps {
  /** Single-use widget token minted by YOUR backend via POST /api/v2/checkout/init */
  widgetToken: string;
  customerPhone?: string;
  customerEmail?: string;
  /** Fires immediately when payment is confirmed. Widget stays visible. */
  onSuccess?: (paymentId: string) => void;
  /** Fires when the shopper clicks "Continue to shop". Use for navigation. */
  onContinueToShop?: () => void;
  onFailure?: (message: string) => void;
}

export function CheckoutWidget({
  widgetToken, customerPhone, customerEmail, onSuccess, onContinueToShop, onFailure
}: CheckoutWidgetProps) {
  const containerRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    if (!containerRef.current || !window.RezolvePay) return;
    const handle = window.RezolvePay.mount(containerRef.current, {
      widgetToken,
      customerPhone,
      customerEmail,
      onSuccess: ({ paymentId }) => onSuccess?.(paymentId),
      onContinueToShop: () => onContinueToShop?.(),
      onFailure: ({ message }) => onFailure?.(message),
    });
    // Return cleanup to prevent listener leaks if the component unmounts.
    // onSuccess fires immediately (notification hook), not on unmount, so widget
    // stays visible until onContinueToShop (shopper-triggered navigation).
    return () => handle?.unmount?.();
  }, [widgetToken, customerPhone, customerEmail, onSuccess, onContinueToShop, onFailure]);

  return <div ref={containerRef} />;
}

// Add the <script src=".../widget/1.1.4/rezolvepay.js"> tag to your index.html
// (see "Script tag with SRI" above) so window.RezolvePay is defined at runtime.

Server-side: mint a widget token

Run this on your backend. The X-Merchant-Api-Key never leaves your server. Return the resulting widget_token to your fetchWidgetToken SDK callback.

Node.js

// Server-side: mint a widget token, then render the page with it.
// Your merchant API key never reaches the browser.

import express from "express";

const app = express();
app.use(express.json());

app.get("/checkout/:orderId", async (req, res) => {
  const order = await loadOrder(req.params.orderId);  // your own logic

  const upstream = await fetch(`https://pay.rezolve.com/api/v2/checkout/init`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-Merchant-Id":      process.env.REZOLVEPAY_MERCHANT_ID,
      "X-Merchant-Api-Key": process.env.REZOLVEPAY_MERCHANT_API_KEY,
    },
    body: JSON.stringify({
      amount:   order.amountMinor,    // e.g. 2599
      currency: order.currency,       // e.g. "GBP"
      order_id: order.id,             // your order reference
      customer_phone: order.phone,    // merchant-supplied shopper phone
      customer_email: order.email,    // optional backup contact
    }),
  });

  if (!upstream.ok) {
    return res.status(upstream.status).json(await upstream.json());
  }
  const { widget_token } = await upstream.json();

  // Render your checkout page, embedding the token in the script context.
  res.render("checkout", {
    widgetToken: widget_token, customerPhone: order.phone, customerEmail: order.email,
  });
});

Use the value for your environment from Environments.

cURL

# Mint a widget token (server-side only)
curl -X POST "https://pay.rezolve.com/api/v2/checkout/init" \
  -H "Content-Type: application/json" \
  -H "X-Merchant-Id: $REZOLVEPAY_MERCHANT_ID" \
  -H "X-Merchant-Api-Key: $REZOLVEPAY_MERCHANT_API_KEY" \
  -d '{ "amount": 2599, "currency": "GBP", "order_id": "ORD-4421", "customer_phone": "+447700900123", "customer_email": "[email protected]" }'

# Response
# { "widget_token": "wt_xxxxxxxxxxxxxxxxx" }

Use the value for your environment from Environments.

Widget postMessage events

The widget communicates with its host page via window.postMessage with source: 'rezolve-pay-widget'. The SDK callbacks (onSuccess, onContinueToShop, etc.) are wrappers around these raw events.

Event typeWhen firedSDK callback
widget:successPayment confirmed by provider. Widget remains visible.onSuccess({ paymentId })
widget:continue-to-shopShopper clicked Continue to shop on the success screen. SDK cleans up after firing.onContinueToShop()
widget:failurePayment declined. SDK cleans up.onFailure({ message })
widget:cancelShopper cancelled. SDK cleans up.onCancel()
widget:resizeWidget height changed. SDK resizes the iframe automatically.—

Webhook signature verification

Each outbound webhook includes X-RezolvePay-Signature, X-RezolvePay-Timestamp, and X-RezolvePay-Event-Id headers. Verify the signature with the signing secret from your merchant settings.

import { createHmac } from "crypto";

function verifyWebhookSignature(
  rawBody: string,
  secret: string,
  headers: {
    "x-rezolvepay-signature": string;
    "x-rezolvepay-timestamp": string;
  },
): boolean {
  const expected = createHmac("sha256", secret)
    .update(headers["x-rezolvepay-timestamp"] + "." + rawBody)
    .digest("hex");
  return expected === headers["x-rezolvepay-signature"];
}

Did this page help you?