Documentation Index
Fetch the complete documentation index at: https://dev.moonpay.com/llms.txt
Use this file to discover all available pages before exploring further.
Render the Google Pay frame into your UI and initiate a transaction with an executable quote signature.
import { createClient, type GooglePayEvent } from "@moonpay/platform";
const clientResult = createClient({ sessionToken: "c3N0XzAwMQ==" });
if (!clientResult.ok) {
// Handle error
}
const client = clientResult.value;
const googlePayResult = await client.setupGooglePay({
quote: quoteResult.value.signature,
container: document.querySelector("#googlePayContainer"),
onEvent: (event: GooglePayEvent) => {
switch (event.kind) {
case "ready":
break;
case "complete":
console.log(event.payload.transaction);
break;
case "quoteExpired":
// Fetch a new quote, then update the frame:
// event.payload.setQuote(newQuote.signature);
break;
case "challenge":
// Render the challenge frame at the provided URL
// See: /platform/guides/handling-challenges
console.log(event.payload.url);
break;
case "error":
console.error(event.payload.message);
break;
case "unsupported":
break;
}
},
});
if (!googlePayResult.ok) {
// Handle error
console.error(googlePayResult.error);
}
const googlePay = googlePayResult.value;
Parameters
| Property | Type | Required | Description |
|---|
quote | string | ✅ | The quote signature returned from getQuote. |
container | HTMLElement | ✅ | A DOM element to render the Google Pay frame into. |
externalTransactionId | string | | Partner-assigned identifier for this transaction attempt. Useful for reconciliation. |
onEvent | (event: GooglePayEvent) => void | ✅ | Callback invoked for Google Pay flow events. See GooglePayEvent. |
This method does not require a clientToken parameter. The client uses stored credentials from an active connection.
GooglePayEvent
onEvent receives events as the Google Pay flow progresses. Use event.kind to decide how to handle each event.
| kind | Payload | When you receive it |
|---|
"ready" | — | The Google Pay UI is rendered and ready to be shown. |
"complete" | { transaction: [Transaction](#transaction) } | The Google Pay flow finished and a transaction was created. |
"challenge" | { kind: "frame"; url: string } | Verification required. Render the challenge frame at the provided URL. |
"quoteExpired" | { setQuote: (quoteSignature: string) => void } | The quote signature expired. Fetch a new quote and call payload.setQuote(...). |
"error" | GooglePayEventError | The flow encountered an error. |
"unsupported" | — | Google Pay isn’t supported or available in the user’s current environment. |
Transaction
This is the transaction object returned when the Google Pay flow completes. See the API reference for details.
| Field | Type | Required | Description |
|---|
status | "complete" | "pending" | "failed" | ✅ | The current transaction status. |
id | string | | Present when status is "complete" or "pending". |
failureReason | string | | Present when status is "failed". A developer-friendly reason. |
GooglePayEventError
| Field | Type | Required | Description |
|---|
kind | "configurationError" | "invalidQuote" | "quoteExpired" | "genericError" | ✅ | The error category. |
message | string | ✅ | Developer-friendly details. |
Google Pay unavailability is signalled separately through the "unsupported" event, not as an error.
Result
client.setupGooglePay() returns a Result<GooglePayFrame, SetupGooglePayError>.
Result envelope
Result<GooglePayFrame, SetupGooglePayError>
| Field | Type | Required | Description |
|---|
ok | boolean | ✅ | Whether the operation succeeded. |
value | GooglePayFrame | | Present when ok is true. |
error | SetupGooglePayError | | Present when ok is false. |
GooglePayFrame
| Field | Type | Required | Description |
|---|
setQuote | (quoteSignature: string) => void | ✅ | Updates the quote signature used by the frame. Use this in response to quoteExpired. |
dispose | () => void | ✅ | Unmounts the frame. After you call this, no further events are dispatched to your onEvent callback. |
SetupGooglePayError
| Field | Type | Required | Description |
|---|
kind | "invalidQuote" | "quoteExpired" | "googlePayUnavailable" | "genericError" | ✅ | The error category. |
message | string | ✅ | Developer-friendly details. |
type GooglePayFrame = {
setQuote: (quoteSignature: string) => void;
dispose: () => void;
};
type Transaction =
| {
id: string;
status: "complete" | "pending";
}
| {
status: "failed";
failureReason: string;
};
type GooglePayEvent =
| {
kind: "ready";
}
| {
kind: "complete";
payload: {
transaction: Transaction;
};
}
| {
kind: "challenge";
payload: {
kind: "frame";
/** Fully-formed URL to pass directly as the challenge frame src. */
url: string;
};
}
| {
kind: "quoteExpired";
payload: {
setQuote: (quoteSignature: string) => void;
};
}
| {
kind: "error";
payload: GooglePayEventError;
}
| {
kind: "unsupported";
};
type GooglePayEventError = {
kind: "configurationError" | "invalidQuote" | "quoteExpired" | "genericError";
message: string;
};
type SetupGooglePayError = {
kind:
| "invalidQuote"
| "quoteExpired"
| "googlePayUnavailable"
| "genericError";
message: string;
};