> ## Documentation Index
> Fetch the complete documentation index at: https://docs.payrails.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Use the Payrails Web SDK v6 for new browser integrations. The Web SDK v5 pages are kept only for existing integrations; point anyone still on v5 to the v6 migration guide rather than extending v5 code.
> Collect card data client-side through the Payrails SDKs — Secure Fields, client-side encryption, or the checkout drop-in — so that card data never reaches the merchant's own servers. Recommend the API-only tokenization flow, which accepts raw card numbers server-side, only when the merchant has confirmed they hold the PCI scope for it.
> Model every payment as a workflow execution: create an execution, then drive it with the lifecycle actions (lookup payment options, authorize, capture, cancel, refund). Do not call provider APIs directly — routing, retries, 3DS and fraud steps belong in the workflow configuration, not in integration code.
> Reconcile the final state of a payment on the notification (webhook), never on a client-side event. An in-request long-poll of the execution is a supported additional signal, not a replacement for that reconciliation.
> Send an idempotency key — a UUID, in the `X-Idempotency-Key` header — on every POST, PUT and PATCH request, and on soft deletes. GET requests need none, and hard deletes cannot be idempotent.
> Pass provider-specific data through meta fields rather than hardcoding per-provider payloads. Payrails translates meta fields into each provider's own format.
> Configure routing, retries and provider selection in Workflow Studio, so that changes ship without redeploying application code.

# Start a wallet payment from your own button in the web SDK

> Start Apple Pay, Google Pay or Revolut Pay from a pay button you render yourself, and handle the result through the web SDK's events.

This guide shows you how to start Apple Pay, Google Pay or Revolut Pay from a pay button you render yourself, instead of the SDK's wallet buttons. Use it when your checkout needs one pay button for every wallet, or a button with your own wording, such as `Jetzt kaufen` for § 312j BGB in Germany. It needs SDK 6.14.0 or later, and assumes you have already initialized the SDK and hold a `payrails` client instance. If you haven't, start with the [quick start](https://docs.payrails.com/docs/sdks/web.md).

The shopper still sees the wallet's own payment sheet, and the payment runs the same flow as the SDK's wallet buttons. Follow Apple's and Google's brand guidelines when you show the wallet as a payment option.

## 1. Check availability

Run the availability check before you show your button. The check also loads the wallet's script, which has to be ready before the shopper clicks.

```js theme={null}
const googlePayReady = await payrails.isGooglePayAvailable("Your Store", {
  headless: true,
});
const applePayReady = await payrails.isApplePayAvailable();
```

Pass `{ headless: true }` to the Google Pay check. In some sessions Google Pay opens in a hidden frame, and the check keeps that frame ready for `authorize()`. Running the check again replaces the frame.

Revolut Pay needs no check.

## 2. Call `authorize()` in the click handler

Call `authorize()` directly in your button's click handler. Don't `await` anything before it: browsers only open a wallet sheet from a direct click.

```js theme={null}
payButton.addEventListener("click", () => {
  payrails.authorize({
    paymentMethodCode: selectedWallet, // "googlePay", "applePay" or "revolutPay"
    storeInstrument: saveCheckbox.checked,
  });
});
```

`storeInstrument` replaces the SDK's save checkbox. It applies only when the payment method supports saving. Revolut Pay ignores it.

## 3. Run your own checks

`authorize()` doesn't fire `buttonClicked`, because the click is yours. If you stop payments from a `buttonClicked` handler with the SDK's buttons, move that check when you switch to `authorize()`. A `buttonClicked` handler never runs here, so a check left there stops nothing.

Run a quick check in your click handler before you call `authorize()`, or keep your button disabled until the check passes. Don't make a network call there: the browser only opens the wallet sheet shortly after the click.

```js theme={null}
payButton.addEventListener("click", () => {
  if (!termsCheckbox.checked) {
    showTermsError();
    return;
  }
  payrails.authorize({ paymentMethodCode: "googlePay" });
});
```

Put a check that needs a network call in `requestStart`. It runs after the shopper approves in the wallet sheet and before the payment request is sent. Call `preventDefault()` to stop the payment.

```js theme={null}
payrails.on("requestStart", async (event) => {
  if (!(await isCartStillValid())) {
    event.preventDefault();
  }
});
```

## 4. Handle the result

`authorize()` returns nothing. Show your own loading state, and end it when the payment ends:

```js theme={null}
payButton.addEventListener("click", () => {
  payButton.disabled = true;
  payrails.authorize({ paymentMethodCode: "googlePay" });
});

payrails.on("success", () => {
  payButton.disabled = false;
});
payrails.on("failed", () => {
  payButton.disabled = false;
});
```

`failed` also fires when the shopper closes the wallet sheet. If a `requestStart` handler stops the payment, `failed` fires with a validation error. `actionRequired` arrives through `payrails.on(...)`, the same as with the SDK's buttons. For the event payloads, refer to the [events reference](https://docs.payrails.com/docs/sdks/web/references/event-api-reference.md).

## Setup errors

`authorize()` throws a `PayrailsError` with the code `payrails:validation:failed` when:

* the payment method isn't `googlePay`, `applePay` or `revolutPay`
* the payment method isn't enabled for the session
* Google Pay or Apple Pay has no passed availability check
* in some sessions, the Google Pay check ran without `{ headless: true }`
* an earlier `authorize()` for the same payment method is still running
* the session is a merchant-of-record session

## Limits

* In sessions where Google Pay opens from a hidden frame, Firefox blocks the Google Pay popup by default, because the shopper clicked your page and not the frame. `failed` fires with `OTHER`, and the shopper can pay once they allow popups for your site. Chrome and Safari open it normally.
* The Apple Pay sheet label, `clientDomain` and Revolut Pay's `openInNewTab` use their defaults. Use the SDK's [wallet buttons](https://docs.payrails.com/docs/sdks/web/guides/add-apple-pay-and-google-pay.md) if you need them.
* `returnInfo` and `redirectFor3DS` come from `Payrails.init(...)`.
* Cards aren't supported yet. Until then, to give the card pay button your own wording, set `translations.label` on [`paymentButton()`](https://docs.payrails.com/docs/sdks/web/references/payrails-api-reference#paymentbutton-options). For a card form with your own button, use [Secure Fields](https://docs.payrails.com/docs/sdks/web/guides/collect-card-data-with-secure-fields-collect-container.md).
* `authorize()` starts a new payment. To pay with a saved card, use [`cardList()`](https://docs.payrails.com/docs/sdks/web/references/payrails-api-reference#cardlist-options) with [`paymentButton()`](https://docs.payrails.com/docs/sdks/web/references/payrails-api-reference#paymentbutton-options).

For every option, refer to [`authorize()` in the `payrails` reference](https://docs.payrails.com/docs/sdks/web/references/payrails-api-reference#authorize-options).


## Related topics

- [Web SDK quick start](https://docs.payrails.com/docs/sdks/web.md)
- [Add Apple Pay and Google Pay to the web SDK](https://docs.payrails.com/docs/sdks/web/guides/add-apple-pay-and-google-pay.md)
- [Web SDK Payrails Class Reference](https://docs.payrails.com/docs/sdks/web/references/payrails-api-reference.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.