Skip to main content
Use iframes and postMessage to embed frames directly in web applications without installing any MoonPay packages.
Read the manual integration overview for core concepts before you continue.

Setup

Encryption

The connect and check frames require X25519 key exchange to encrypt client credentials. The examples below use @noble/curves, but you can use any library that supports X25519 and AES-GCM.

Message utilities

Create helper functions for sending and receiving frame messages. All messages follow the frames protocol.
messageUtils.ts

Encryption utility

The connect and check frames return encrypted credentials. Generate an X25519 keypair and provide the public key to the frame.

Key generation

crypto.ts

Decryption

decrypt.ts

Check frame

The check frame verifies whether a customer already has an active connection. It’s headless — no UI is rendered. Use it to skip the connect flow for returning customers. See check frame reference for event details.

Initialize the frame

Handle events

Usage


Connect frame

The connect frame establishes a customer connection to your application. See connect frame reference for event details.

Initialize the frame

Handle events

Usage


Auth frame

The auth frame authenticates a customer with email or SMS one-time passcode and returns fully scoped credentials — without the hosted KYC UI in the connect frame. Launch it after the check frame returns connectionRequired, typically when you drive onboarding through the Customer API. See auth frame reference for event details.

Initialize the frame

Handle events

Usage


Apple Pay frame

The Apple Pay frame renders the Apple Pay button and handles the payment flow. See Apple Pay frame reference for event details.
Apple Pay only works on Safari (macOS and iOS). Check availability before rendering.

What you’ll need

Before you initialize the Apple Pay frame, you need:
  1. A clientToken from a successful connect flow
  2. A valid quote signature for the transaction

Initialize the frame

Handle events

Update the quote

When the quote expires or changes, send a new quote to the frame:

Google Pay frame

The Google Pay frame renders the Google Pay button and handles the payment flow. See Google Pay frame reference for event details.
The Google Pay frame requires the payment permission policy. When using a sandboxed iframe, include allow-scripts, allow-popups, allow-same-origin, and allow-forms. See Google Pay inside sandboxed iframe for details.

What you’ll need

Before you initialize the Google Pay frame, you need:
  1. A clientToken from a successful connect flow
  2. A valid quote signature for the transaction

Initialize the frame

Handle events

Update the quote

When the quote expires or changes, send a new quote to the frame:

Add Card frame

The add card frame lets a customer save a new card to their account. See add card frame reference for event details.

What you’ll need

Before you initialize the add card frame, you need:
  1. A clientToken from a successful connect flow

Initialize the frame

Handle events

Usage


Buy frame

The buy frame processes a card or bank-transfer payment for a quote. It is headless — rendered at zero size — while the customer completes payment. For cards, if 3-D Secure is required, the frame emits a challenge event with a URL you open in a separate challenge frame. For bank transfers (SEPA, EUR), quote with paymentMethod.type set to "sepa"; the complete event returns a transaction that stays pending and carries a bankTransferDepositInfo object you render natively so the customer can send the deposit. See the buy frame reference for event details, and Pay with bank transfer for the full bank-transfer walkthrough.
For bank transfers, the customer must include the payment reference from bankTransferDepositInfo with their transfer, or it is rejected. Render the deposit details, including the reference, in your own UI. See the transaction object.

What you’ll need

Before you initialize the buy frame, you need:
  1. A clientToken from a successful connect flow
  2. A valid quote signature for the transaction

Initialize the frame

Handle events

Update the quote

When the quote expires or changes, send a new quote to the frame:

Challenge handling

When the buy frame emits a challenge event, open the challenge URL in a new iframe inside a modal. The challenge frame is self-driving after the handshake:

Usage


Buy Button frame

The Buy Button frame consolidates Apple Pay, Google Pay, and card into a single MoonPay-hosted button that matches the payment method in your quote. It runs the same buy pipeline as the buy frame and supports guest checkout when your quote allows it. See buy button frame reference and Pay with the buy button.

What you’ll need

Before you initialize the Buy Button frame, you need:
  1. A clientToken from a successful connect flow
  2. A valid quote signature for the transaction

Initialize the frame

Handle events

The Buy Button frame uses the same events as the buy frame. Reuse setupBuyListener, updateBuyQuote, and challenge handling — point them at the Buy Button iframe instead of the headless buy iframe.

Widget frame

For payment methods beyond Apple Pay — including credit/debit cards, Google Pay, bank transfers, and more — use the widget frame. It renders the full MoonPay buy experience inside an iframe, including payment collection and transaction confirmation. See pay with widget for a full walkthrough.

What you’ll need

Before you initialize the widget frame, you need:
  1. A clientToken from a successful connect flow
  2. A valid quote signature for the transaction

Initialize the frame

The widget iframe requires the payment permission policy to process payments.

Handle events

Usage


Reset frame

The reset frame is headless. Use it when the customer signs out of your app to clear MoonPay session state on MoonPay’s domain. See reset frame reference. Pass the same clientToken you received from connect or auth so your domain is authorized to embed the frame. Do not block sign-out if reset fails or times out.

Initialize the frame

Handle events

Usage