Skip to main content
Use react-native-webview to embed frames in React Native applications. The WebView communicates with your app through the ReactNativeWebView JavaScript interface.
Read the manual integration overview for core concepts before you continue.

Setup

The react-native-webview library automatically injects the ReactNativeWebView JavaScript interface into the WebView. The frame detects this interface and uses it for communication between the frame and your app. You don’t need to inject a custom JavaScript bridge.

Dependencies

Install react-native-webview 13.15.0 or later to render frames in your app. Earlier versions don’t support paymentRequestEnabled, which Google Pay needs in an Android WebView.
If targeting iOS, you may also need to run:
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. You also need a polyfill for getRandomValues (MDN) which is only available in browsers.

Base WebView component

Create a reusable base component for frame communication:
MoonPayWebView.tsx

Encryption utility

When using the connect or check frame, you generate an X25519 keypair and provide the public key to the frame. The frame encrypts the returned client credentials with this key.

Key generation

Generate an X25519 keypair for secure communication:
crypto.ts

Decryption utility

Decrypt the encrypted credentials returned from connect/check frames:
decrypt.ts

Check frame

The check frame verifies whether a customer already has an active connection. It’s headless — no UI is rendered. See check frame reference for event details.

Check component

Usage


Connect frame

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

Connect component

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 component

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.

What you’ll need

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

Add Card component

Usage


Buy Button frame

The Buy Button frame takes a quote to payment. It renders the Apple Pay, Google Pay, or card button that matches the payment method in your quote, and supports guest checkout when your quote allows it. For card and bank transfer quotes, you can also run it in headless mode behind your own purchase button. See the Buy Button frame reference for event details, and Pay with the buy button for the full walkthrough.
Apple Pay and Google Pay inside a WebView have extra requirements, and Google Pay isn’t available in an iOS WebView. See Mobile WebViews.

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

Buy Button component

The component renders the button at 44px tall. See Size. Pass headless to run the purchase without a button, as described in Headless mode.

Challenge component

When the Buy Button frame emits a challenge event, for example for 3-D Secure, render the challenge frame at the URL. Opened without resume, as below, it finishes the purchase for every payment method and sends complete. To have the customer finish an Apple Pay or Google Pay purchase on your buy button instead, see Finish on your buy button.

Usage

Headless mode

For card and bank transfer quotes, you can draw your own purchase button and pass headless to MoonPayBuyButtonFrame. The frame loads with headless=true, renders nothing, and starts the purchase as soon as it loads. Mount it at zero size when the customer confirms the purchase in your UI, not before. See Headless mode. In headless mode, the frame:
  • Sends ready, then exactly one of complete, challenge, or error.
  • Never sends buttonPressed or cancelled.
  • Accepts card and bank transfer (SEPA) quotes only. An Apple Pay or Google Pay quote returns error with unsupportedPaymentMethod.
  • Needs a connected customer. A guest checkout quote returns error with invalidQuote.
  • Reads setQuote only after an error with quoteExpired.
On challenge, render the challenge component without resume. It finishes the purchase and sends its own complete. After complete, or an error other than quoteExpired, unmount the frame. The example below leaves the screen, which unmounts it. Mount a new frame if the customer tries again. For a bank transfer (SEPA) quote, onComplete receives the transaction id. Fetch the transaction by id, and show the customer the bank details from bankTransferDepositInfo and the amount to send from source.amount natively so they can send the transfer. See Pay with bank transfer.
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.

Widget frame

To hand the whole purchase to MoonPay, including amount entry and payment method selection, use the widget frame. It renders the full MoonPay buy experience inside a WebView, including payment collection and transaction confirmation. See pay with widget for a full walkthrough.

Widget component

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 component

Usage