Skip to content

Embedding the checkout

Besides redirecting the payer to the payment link, a merchant can open the checkout on its own page: on desktop the payment happens in a modal (an iframe), and on phones the payer is redirected to the checkout page. Phones are redirected because wallet apps and their links work most reliably in a full page.

A payment completed in a modal on the merchant’s page

Mode Description
Redirect (default) After creating the order, send the payer to checkout_url; they return to return_url when done
Modal / iframe The page loads /pay/embed.js; the checkout opens in a modal on desktop and by redirect on phones

This page covers the second mode. Creating orders is described in the Integration guide.

Step 1: register the sites allowed to embed

Section titled “Step 1: register the sites allowed to embed”

By default the checkout cannot be embedded. In the console under Merchant & checkout → Merchant and look, in the merchant card, enter the https origins of the merchant’s sites in Sites allowed to embed the checkout, one per line, for example:

https://shop.example

The checkout allows only these sites to embed it, through the frame-ancestors directive of its Content Security Policy. A site that is not listed cannot load the checkout in an iframe, and the embed script redirects instead.

Load the embed script from the checkout’s domain on the merchant page. Replace https://pay.example.com in the examples with the address of your own deployment.

Give a button the data-flowpay-checkout attribute with the order’s checkout_url; a click opens the checkout:

<script src="https://pay.example.com/pay/embed.js" defer></script>
<button data-flowpay-checkout="https://pay.example.com/pay/0b3f5a52-8f7e-4c1e-9d2a-6c1f0e9b7a31">Pay</button>
const checkout = FlowPay.open(order.checkout_url, {
mode: 'auto', // auto (default: modal on desktop, redirect on phones) | modal | redirect
onPaid(e) { /* { order_id, status: 'paid', return_url } */ },
onExpired(e) { /* { order_id, status: 'expired' } */ },
onClose(e) { /* { order_id, reason: 'closed' | 'return' | 'blocked' | 'replaced' } */ },
redirectOnReturn: true, // "Return to merchant" on the result page sends the top-level page to the signed return_url
fallback: true, // redirect to the checkout when embedding is refused (not ready within 10 s); false only fires onClose(reason: 'blocked')
});
checkout?.close(); // null in redirect mode

The same events are also dispatched on window, with the same detail as the callback arguments above:

window.addEventListener('flowpay:paid', (e) => refreshOrder(e.detail.order_id));
// also flowpay:expired and flowpay:closed
Option Description
mode auto (default): modal on desktop, redirect on phones; modal: always a modal; redirect: always a redirect
onPaid Called when the payment reaches the required confirmations
onExpired Called when the order expires
onClose Called when the modal closes; reason says why
redirectOnReturn When true, pressing “Return to merchant” on the result page sends the top-level page to the signed return_url
fallback When true, a refused embed (not ready within 10 seconds) redirects to the checkout; when false, only onClose fires, with reason set to blocked
Event Source When
paid The checkout iframe The payment reached the required confirmations and the result page is shown
expired The checkout iframe The order expired
closed The embed script The payer closed the modal (close button, Esc or a click on the backdrop), or pressed “Return to merchant” on the result page (reason: 'return')
  • The checkout sends events only when the embedding page belongs to the sites allowed to embed it; the postMessage target origin is fixed to that site, and the checkout accepts no messages from the parent page.
  • The embed script accepts only messages that come from the checkout iframe and whose origin is the checkout’s domain.
  • The result page inside the modal never loads the merchant page into the iframe: returning to the merchant is done by the top-level page.

docs/developers/examples/embed.html in the source repository is a complete example page. Replace the checkout domain and the order link in it with your own.

  • Integration guide: creating orders, verifying the return signature and deciding when to ship.
  • Webhooks: events and signature verification.
  • Payment flow: the payer’s steps at the checkout.