Like the headless Buy frame, the buy
button can emit a
challenge event mid-pipeline. Render a separate challenge
frame using
client.setupChallenge() at
the URL from the event payload.Setup buy button
Parameters
| Property | Type | Required | Description |
|---|---|---|---|
quote | string | ✅ | The quote signature returned from getQuote. |
container | HTMLElement | ✅ | A DOM element to render the buy button into. |
onEvent | (event: BuyButtonEvent) => void | Callback invoked for buy-button events. See BuyButtonEvent. |
BuyButtonEvent
onEvent receives events as the buy pipeline progresses.
| kind | Payload | When you receive it |
|---|---|---|
"ready" | — | The button is rendered and ready for the customer to tap. For Apple Pay and Google Pay, this fires once the device is confirmed to support the wallet. Use it to hide any loading placeholder. |
"complete" | { transaction: FrameTransaction } | The pipeline finished. Inspect the FrameTransaction to detect the failure variant. |
"challenge" | { kind: string; url: string } | Verification is required before the transaction can proceed. Render the challenge frame at the provided url. |
"error" | BuyButtonEventError | The flow encountered an error. Surface to logs and tear down the frame. |
FrameTransaction
FrameTransaction is a discriminated union — the failure variant carries failureReason, the non-failure variant always carries id. Pass id to client.getTransaction() to poll for the final status.
| Field | Type | Required | Description |
|---|---|---|---|
status | string | ✅ | The transaction status. On the failure variant, "failed". |
id | string | Required on the non-failure variant; optional when status is "failed". | |
failureReason | string | Present only on the failure variant (status === "failed"). |
BuyButtonEventError
| Field | Type | Required | Description |
|---|---|---|---|
code | string | ✅ | The error category. Includes configurationError, invalidQuote, and backend-specific error codes. |
message | string | ✅ | Developer-friendly details. Not intended to be rendered in UI. |
Result
client.setupBuyButton() returns a Result<BuyButtonFrame, SetupBuyButtonError>.
Result envelope
Result<BuyButtonFrame, SetupBuyButtonError>
| Field | Type | Required | Description |
|---|---|---|---|
ok | boolean | ✅ | Whether the operation succeeded. |
value | BuyButtonFrame | Present when ok is true. | |
error | SetupBuyButtonError | Present when ok is false. |
BuyButtonFrame
| Field | Type | Required | Description |
|---|---|---|---|
setQuote | (signature: string) => void | ✅ | Updates the quote signature used by the frame. Use this when the current quote expires before the customer taps the button — fetch a new quote and pass its signature. |
dispose | () => void | ✅ | Unmounts the frame. After you call this, no further events are dispatched to your onEvent callback. |
SetupBuyButtonError
| Field | Type | Required | Description |
|---|---|---|---|
kind | "configurationError" | "genericError" | ✅ | The error category. |
message | string | ✅ | Developer-friendly details. |
TS Definitions
TS Definitions
types.ts