Skip to main content
Use WebView to embed frames in native Android applications. The WebView communicates with frames via JavaScript interfaces and evaluateJavascript.
Read the manual integration overview for core concepts before you continue.

Setup

Dependencies

The examples below use Tink for cryptographic operations, but you can use any library that supports X25519 and AES-GCM.

Key generation

Decryption utility

Base frame fragment

Create a reusable base fragment 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. Android’s WebView returns false for window.confirm, alert, and prompt unless you attach a WebChromeClient that handles them — so without this, every test transaction silently comes back with status: "failed". Surface the simulated payment sheet with an AlertDialog:
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").
Attach the WebChromeClient even if you only plan to ship live mode. The default WebView behaviour applies to any window.confirm, alert, or prompt the frame might surface, and 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 fragment

Usage


Connect frame

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

Connect fragment

Usage with Activity


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 fragment

Usage with Activity


Buy frame

The buy frame processes a card payment for a quote. It is headless — rendered at zero size — while the customer completes payment. If 3-D Secure is required, the frame emits a challenge event with a URL you open in a separate challenge frame. See buy frame reference for event details.

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 fragment

Challenge handling

When the buy fragment receives a challenge URL, add a MoonPayChallengeFragment to present the 3-D Secure flow. On completion, cancellation, or error, remove both the challenge and buy fragments:

Usage with Activity


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.

Enable the Payment Request API

Google Pay relies on the Payment Request API, which is disabled by default in Android WebView. Enable it before loading the frame. The embedding requirements (minimum versions, the androidx.webkit:webkit:1.14.0 dependency, and the AndroidManifest.xml <queries> entries) live on the Google Pay frame reference. Meet those first. Enable the Payment Request API on the WebView in your base fragment’s onCreateView:

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

Google Pay fragment

Usage with Activity


Widget frame

Apple Pay is not available on Android. Use the widget frame instead to render the full MoonPay buy experience — including payment-method selection (credit/debit card, Google Pay, bank transfers, and more) 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

Widget fragment

Usage with Activity