Skip to main content
Use WKWebView to embed frames in native iOS applications. The WebView communicates with frames via JavaScript message handlers and script injection.
Read the manual integration overview for core concepts before you continue.

Setup

Dependencies

The examples below use swift-crypto for X25519 key exchange, but you can use any library that supports X25519 and AES-GCM.

Key generation

Decryption utility

Base frame controller

Create a reusable base view controller for frame communication:

Handle JavaScript dialogs

In test mode, the Apple Pay frame renders a mock button and uses window.confirm to simulate the Apple Pay payment sheet. By default, WKWebView silently dismisses window.confirm, alert, and prompt — the JavaScript call returns false with no UI shown — and the frame interprets that as the customer cancelling, so every test transaction comes back with status: "failed". This WKWebView requirement is captured on the Apple Pay frame reference, which is the source of truth. To surface the simulated payment sheet, conform your base view controller to WKUIDelegate and present the confirm panel as a UIAlertController:
OK simulates a successful test transaction (the frame emits complete with a non-failed status); Cancel simulates a failed transaction (the frame emits complete with status: "failed").
Wire the UI delegate even if you only plan to ship live mode. The WKWebView default behaviour applies to any window.confirm, alert, or prompt the frame might surface, and it makes test-mode debugging impossible without it.

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.

Check controller

Usage


Connect frame

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

Connect controller

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.

Auth controller

Usage


Apple Pay frame

The Apple Pay frame renders a native Apple Pay button and handles the payment flow. See Apple Pay frame reference for event details.

Apple Pay controller

Usage


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.

Add Card controller

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

Buy controller

Challenge handling

When the buy frame emits a challenge event, present a MoonPayChallengeViewController with the challenge URL. On completion, cancellation, or error, call dispose() on the buy view controller:

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.

Buy Button controller

For 3-D Secure, reuse challenge handling from the Buy frame section.

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 a WKWebView, including payment collection and transaction confirmation. See pay with widget for a full walkthrough.

Widget controller

Usage


Reset frame

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

Reset controller

Usage