> ## 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.

# App Publishers

> Start by accepting card, Apple Pay and Google Pay and renewing subscriptions from the saved card, with one Payrails workflow and payment routing setup.

This guide takes you from a staging account to live payments, one step at a time. Each step says who does the work and what done looks like. The guide uses cards, Apple Pay, and Google Pay as the example. The same setup also carries PayPal, local methods, and any other payment method you enable.

The guide is for everyone on your side: the payments or product owner who tracks the project, and the engineers who do the work. The [Glossary](#glossary) explains the Payrails terms it uses, such as instrument, execution, and cascade. Start as soon as your initial account administrator can sign in to your staging Portal at `<yourcompany>.staging.payrails.io`.

At the end of this guide, you have:

* A staging checkout that takes a test card, Apple Pay, and Google Pay through one Payrails workflow, and renews a subscription from a saved card.
* The same setup in production, taking real payments.

## Assumptions

This guide assumes that:

* Your go-live includes cards, Apple Pay, and Google Pay. Other methods, for example PayPal or local methods, go live with them or later on the same instances and workflow.
* Apple Pay runs on the web under the Payrails Apple merchant identifier. You use your Apple Developer account only to create a sandbox tester for staging tests.
* Google Pay uses the Payrails-hosted button, so you need no Google Pay & Wallet Console account.
* Your checkout uses one of two integration options, and the guide marks where they differ:
  * **Option A, Drop-in or Elements (recommended):** Payrails renders the whole checkout (Drop-in) or one component per payment method (Elements), and the SDK runs the payment.
  * **Option B, Secure Fields and server-to-server:** you build the form and Payrails hosts the card fields, so your servers never handle card numbers. Your backend creates and authorizes the payment through the API. Use it only if server-to-server is a strict requirement.
* One payment workflow handles the first payment (customer-initiated transaction, CIT) and later renewals (merchant-initiated transaction, MIT).
* You go through staging once, end to end, then repeat the same steps in production.

## Go-live steps

Work through the six steps in order. Open a step to see its instructions and what done looks like.

> [accordion] Step 1: Access and credentials
>
> Create the API credentials and the mTLS certificate your backend uses to call Payrails. Both integration options need them: even with Drop-in or Elements, your backend makes one call to Payrails per checkout. Everything here is self-serve in the Portal.
>
> > [accordion] Portal access and API credentials
> >
> > **Portal access.** Your initial account administrator signs in at `<yourcompany>.staging.payrails.io` and adds colleagues under **Settings → Users**.
> >
> > **API credentials.** These identify your backend to Payrails. Full details are in [API credentials](https://docs.payrails.com/docs/account-setup/api-credentials.md).
> >
> > 1. In the Portal, open **Settings → API credentials → Create credentials** and name them, for example `checkout backend, staging`.
> > 2. Copy the **Client ID** and the **Client Secret**. The Portal shows the secret once, so store it in your secrets manager right away.
> > 3. Your backend exchanges them for an access token with `POST /auth/token/{CLIENT_ID}`, sending the secret in the `x-api-key` header. The token is valid for one hour, and every other call carries it as `Authorization: Bearer`.
>
> > [accordion] mTLS certificate
> >
> > Payrails requires mutual TLS on every API call: your backend presents a client certificate that Payrails signed. You create one per environment. Full details are in [mTLS configuration](https://docs.payrails.com/docs/account-setup/mtls-configuration.md).
> >
> > 1. Open **Settings → mTLS certificates → Create certificate**. The Portal shows an OpenSSL command.
> > 2. Run it on a machine you control. It produces a private key, which never leaves your infrastructure, and a certificate signing request (CSR).
> > 3. Paste the CSR into the Portal and download the signed certificate.
> > 4. Install the certificate and the private key on your backend, or on the proxy that connects to Payrails.
>
> > [!TIP]
> >
> > **Definition of Done**
> >
> > The token call returns an `access_token` over mTLS. That one response proves the credentials and the certificate both work.

> [accordion] Step 2: Payment instances and notifications
>
> Connect your PSP test accounts and set up the webhook that tells your backend the outcome of every payment, renewal, and refund. You enter your own PSP credentials in the Portal, and Payrails staff never handle them. Until your PSP sandbox credentials arrive, run payments from **Workflows → Test payments** on the built-in **Payrails Test PSP**, which every merchant has by default.
>
> > [accordion] Payment instances
> >
> > Create one instance per PSP merchant account / merchant ID (MID) under **Settings → Integrations → Payment → New instance**. Full details are in [Payment providers](https://docs.payrails.com/docs/integrations/payment-providers), with a setup page for each provider: [Stripe](https://docs.payrails.com/docs/integrations/payment-providers/stripe.md), [Adyen](https://docs.payrails.com/docs/integrations/payment-providers/adyen.md), and [Checkout.com](https://docs.payrails.com/docs/integrations/payment-providers/checkout-com.md).
> >
> > 1. Pick the provider you plan to use in your workflow, for example Stripe, Adyen, or Checkout.com.
> > 2. Name the instance, for example `Stripe, test`. The Portal generates an **Integration instance ID** and a **Notification URL**. Register that URL in the PSP's dashboard so the PSP's webhooks reach Payrails.
> > 3. Under **Payment methods**, tick **Card**, **Apple Pay**, and **Google Pay**. Checkout offers only the methods ticked here.
> > 4. Enter the PSP's **test** credentials. Never put live credentials in staging.
> >
> > Each provider's page lists what to enter on the form and which webhook to create on the PSP side, so your payments owner can collect it beforehand.
>
> > [accordion] Special payment cases to check early
> >
> > Every connector handles the standard flow: authorize, capture, refund, and renew. Anything beyond that varies by PSP. Some cases need an extra setting, and a few aren't available on a given connector. Checking this while you set up the instance costs little, while a gap found during testing or after go-live can delay your launch.
> >
> > List everything your business does that isn't a plain full charge. Check each case against these pages and your provider's integration page:
> >
> > * [Capture a payment](https://docs.payrails.com/docs/orchestration/payment-acceptance/capture-a-payment.md) and [Capture and cancel modes](https://docs.payrails.com/docs/orchestration/payment-acceptance/capture-and-cancel-modes.md) for capturing less than the authorized amount or capturing one order in several parts
> > * [Refund a payment](https://docs.payrails.com/docs/orchestration/payment-acceptance/refund-a-payment.md) for refunding part of a payment or refunding the same payment more than once
> > * [Cancel a payment](https://docs.payrails.com/docs/orchestration/payment-acceptance/cancel-a-payment.md) for releasing an authorization you don't plan to capture
> > * [Authorization flags](https://docs.payrails.com/docs/resources/payments/authorization-flags.md) and [Billing](https://docs.payrails.com/docs/use-cases/billing-use-cases.md) for renewing subscriptions and charging a stored card outside the billing cycle
> > * [Payment instruments and tokens](https://docs.payrails.com/docs/resources/manage-instruments.md) and [Network token lifecycle updates](https://docs.payrails.com/docs/token-vault/network-tokens/automatic-lifecycle-updates.md) for managing saved cards and keeping them current
> > * [Apple Pay Express](https://docs.payrails.com/docs/integrations/payment-methods/apple-pay/apple-pay-express.md) for collecting the customer's contact details in the Apple Pay or Google Pay sheet instead of a form (express checkout). Payrails sets these fields on your wallet configuration, not in your code, so tell Payrails which ones you need
> >
> > For anything not covered there, such as trials that start with a zero or small-amount authorization, confirm support with Payrails before you build on it.
>
> > [accordion] Notifications (webhooks)
> >
> > Notifications tell your backend the outcome of every payment, renewal, and refund. Set them up before testing, so every staging payment produces traffic to inspect. Full details are in [Receive notifications](https://docs.payrails.com/docs/orchestration/payment-acceptance/receive-notifications.md).
> >
> > 1. Open **Configurations → Settings → Notifications** and add your endpoint URL. Payrails shows an **HMAC key** for the endpoint once, so store it like a password. A URL belongs to one workspace and applies to payments created after you save it.
> > 2. Your endpoint receives a JSON `POST` and replies `200`. Payrails retries any other response, up to 10 attempts over about six hours.
> > 3. Verify each notification: compute the HMAC-SHA256 of the raw body with the key, Base64-encode it, and compare it to the `X-Signature` header.
>
> > [!TIP]
> >
> > **Definition of Done**
> >
> > The instance shows Card, Apple Pay, and Google Pay enabled, and a Test PSP payment reaches your endpoint with a valid signature.

> [accordion] Step 3: Apple Pay domain and Google Pay button
>
> Get your checkout ready to show the Apple Pay and Google Pay buttons. Both wallets run under the Payrails registrations with Apple and Google, so you need no Apple merchant ID, no certificates, and no Google Pay merchant account. Your part is small: prove to Apple that you control each domain that shows the Apple Pay button, and pass the right values to the SDK for Google Pay. Both buttons come from the Payrails Web SDK in either integration option. In Option A, the SDK also authorizes the wallet payment. In Option B, the button only saves the wallet token, and your backend authorizes it like a card.
>
> > [accordion] Apple Pay domain (web-only flow)
> >
> > Payments run under the Payrails Apple merchant identifier, and Apple verifies every domain that shows the Apple Pay button against that identifier. Full details are in [Apple Pay](https://docs.payrails.com/docs/integrations/payment-methods/apple-pay).
> >
> > 1. Decide the exact hostnames that render the checkout, in staging and production, for example `pay.yourbrand.com`. Use a dedicated subdomain if the domain already serves Apple Pay through another provider. A host holds only one verification file, and replacing it breaks the other provider's Apple Pay.
> > 2. Download the [Payrails domain association file](https://api-pub.payrails.io/.well-known/apple-developer-merchantid-domain-association). Host it, unchanged, at `https://<host>/.well-known/apple-developer-merchantid-domain-association` on each production hostname. Staging doesn't need it, because Apple skips verification for sandbox accounts.
> > 3. Keep the file there permanently and serve it without redirects. Apple checks it again whenever the domain's TLS certificate renews.
> > 4. Register each hostname in the Portal under **Settings → Apple Pay Domains → Add Domain**. Do this in staging and again in production. It shows as Registered once Apple accepts it. You need no ticket and no certificates.
> > 5. Test in staging with an [Apple Pay sandbox tester account](https://developer.apple.com/apple-pay/sandbox-testing/) and Apple's test cards. Production works with real Apple IDs. The button shows in Safari and in other browsers on Apple devices, and [Apple's guidance on where Apple Pay works](https://support.apple.com/en-us/120364) lists the browser and device requirements.
>
> > [accordion] Google Pay button (Payrails-hosted Element)
> >
> > The button renders inside a Payrails frame under the Payrails Google registration. In staging and production alike, you need no Google Pay & Wallet Console account, no Google merchant ID, and no domain registration with Google. Full details are in [Google Pay](https://docs.payrails.com/docs/integrations/payment-methods/google-pay.md).
> >
> > 1. Google Pay is already ticked on your payment instance from [step 2](#step-2-payment-instances-and-notifications). Payrails sets the allowed card networks and authentication methods for your workspace before go-live, so you have nothing else to configure.
> > 2. In the SDK, pass `merchantName` (the name shown in the Google Pay sheet) and nothing else.
> > 3. Test in staging with a Google Account that has a card from [Google's test card suite](https://developers.google.com/pay/api/web/guides/resources/test-card-suite).
>
> > [accordion] Express checkout: collect contact details in the wallet sheet
> >
> > Many app publishers sell from a screen with no form at all. The customer taps Apple Pay or Google Pay, and the wallet sheet collects the email and name the app needs for the account. Payrails calls this express checkout. Payrails turns it on for you, not in your code, so plan it with your Payrails contact early. Full details are in [Apple Pay Express](https://docs.payrails.com/docs/integrations/payment-methods/apple-pay/apple-pay-express.md).
> >
> > 1. Get standard Apple Pay and Google Pay working first, including the domain registration. Express builds on that setup.
> > 2. Tell your Payrails contact which contact fields the sheet must collect, for example `email`, `name` or `postalAddress`. Payrails sets them on your wallet configuration. The Portal has no toggle and the SDK has no option for it: that field list is the switch. If you rely on the billing address or holder name in notifications, ask for the billing fields too, because Apple returns them only when you request them.
> > 3. Read the collected values from the saved instrument. They arrive in the notification under `paymentComposition[].paymentInstrument` and on `GET /payment/instruments/{id}`, not in the SDK's `success` event.
> > 4. Optionally, register a `deliveryAddressChanged` listener to reject an address before the customer pays. Keep it fast, because Apple closes the sheet after about 30 seconds. If you only need the email, skip this step.
> > 5. Test in staging, then ask Payrails to apply the same fields in production.
> >
> > Plan around two limits. The sheet can't change the total or show shipping options. Google Pay returns the email and address but not the cardholder name, while Apple Pay returns the name.
>
> > [!TIP]
> >
> > **Definition of Done**
> >
> > Your staging hostname shows Registered in the Portal, and both buttons appear in your staging checkout.

> [accordion] Step 4: Payment workflow for first payments and renewals
>
> Build the workflow that holds routing, 3DS and capture, so your checkout code never names a PSP. You build it yourself in the Portal under **Workflows → Payment acceptance**, and the [Workflow Studio quick start](https://docs.payrails.com/docs/orchestration/workflow-studio/quick-start.md) walks through a first version. Every edit is a new version and the old one stays, so nothing you try in staging breaks anything.
>
> To check the first-payment branch, run a card payment from **Workflows → Test payments** and look for a saved instrument on the execution. You test the renewal branch from your backend in [step 5](#step-5-connect-your-checkout-and-test-end-to-end).
>
> > [accordion] The five parts of the workflow
> >
> > Start building with Payrails Test PSP, which every merchant has by default, so you try the workflow before your PSP credentials arrive. Then save a new version that points at your own payment instances. A workflow for cards, wallets, and subscriptions needs these five parts.
> >
> > **1. Payment options** on the start step, with Card, Apple Pay, and Google Pay enabled. These are the buttons the checkout shows, and checkout offers only the methods ticked here.
> >
> > ![Workflow Studio Start Authorize step with Card, Apple Pay, and Google Pay enabled under Payment options](https://mintcdn.com/payrails-42074109/KV30-VXp81ZoJrBb/images/docs/use-cases/app-publishers/payment-options.png?fit=max\&auto=format\&n=KV30-VXp81ZoJrBb\&q=85\&s=0f131a78bb829df05bc96ca8f0ceda03)
> >
> > **2. One branch for first payments (CIT).** A Condition on **Transaction type** sends `Regular`, `CardOnFile`, `MOTO` and everything else to an authorization step with 3DS mode **Default**. With that mode, a 3DS challenge appears only when the issuer requests one. Set **Instrument future usage** so Payrails saves the card, or the wallet token, for renewals.
> >
> > ![Workflow Studio Transaction Type Condition with the CIT Rule and Everything else leading to the CIT Authorize step](https://mintcdn.com/payrails-42074109/KV30-VXp81ZoJrBb/images/docs/use-cases/app-publishers/cit-branch.png?fit=max\&auto=format\&n=KV30-VXp81ZoJrBb\&q=85\&s=638a99640bd55ca59cce04826ddffe89)
> >
> > **3. One branch for renewals (MIT).** Every merchant-initiated payment must carry `meta.order.processingType`: `Subscription` for a renewal, or `UnscheduledCardOnFile` for a one-off charge to a saved card. Send it when you create the execution, and never leave it out. Without it, Payrails falls back to the saved card's future usage, so the PSP can receive the wrong transaction type. The same Condition routes it to an authorization step with no 3DS, against the saved instrument, on the same payment instance that holds the card.
> >
> > ![Workflow Studio MIT Rule for Subscription and UnscheduledCardOnFile leading to the MIT Authorize step](https://mintcdn.com/payrails-42074109/KV30-VXp81ZoJrBb/images/docs/use-cases/app-publishers/mit-branch.png?fit=max\&auto=format\&n=KV30-VXp81ZoJrBb\&q=85\&s=fdb48782767bd37c20baeec4468069ba)
> >
> > **4. Capture mode set to Instant.** Payrails captures the payment with the authorization, so you make no separate capture call. The `authorize` notification is your paid signal.
> >
> > ![Workflow Studio CIT authorization step settings with 3DS mode Default and Capture mode Instant](https://mintcdn.com/payrails-42074109/KV30-VXp81ZoJrBb/images/docs/use-cases/app-publishers/capture-mode.png?fit=max\&auto=format\&n=KV30-VXp81ZoJrBb\&q=85\&s=e20c409add31dd3825fec22cb79d3e7b)
> >
> > **5. An end on every branch.** Approved and declined paths each set a final status and send a notification, so tick the webhook notification for Success and Declined on every authorization step. Optionally, a declined first payment retries once on a second instance, and Payrails calls this retry a cascade.
> >
> > ![Workflow Studio MIT authorization step settings with webhook notifications ticked for Success and Declined](https://mintcdn.com/payrails-42074109/KV30-VXp81ZoJrBb/images/docs/use-cases/app-publishers/end-every-branch.png?fit=max\&auto=format\&n=KV30-VXp81ZoJrBb\&q=85\&s=2a478a4c3c9feaa35682621df1947b02)
> >
> > Your code never refers to a workflow version. It names the workflow by its code, `payment-acceptance`, and Payrails runs whichever version you mark as **Default**.
>
> > [accordion] Common configurations for app publishers
> >
> > Most subscription apps start with the first configuration and add the others once live traffic shows where they help. Each one is a new version of the same `payment-acceptance` workflow.
> >
> > | Configuration | What it adds | Watch out for | Docs example | Template |
> > | - | - | - | - | - |
> > | One PSP for first payments and renewals | The five parts: issuer-driven 3DS and instrument saving on the first payment, renewals without 3DS, instant capture | Mark renewals `Subscription` or `UnscheduledCardOnFile`, or they go down the first-payment branch | [Authorization with 3D Secure](https://docs.payrails.com/docs/orchestration/workflow-studio/examples/authorization-with-3ds.md) | [app-publishers-one-psp.json](https://docs.payrails.com/images/docs/use-cases/app-publishers/app-publishers-one-psp.json) |
> > | Cascade to a second PSP | A declined first payment retries once on a second payment instance | Renewals must go to a PSP that holds the saved card, so check the renewal branch after adding the cascade | [Workflow Studio overview](https://docs.payrails.com/docs/orchestration/workflow-studio/overview.md) | [app-publishers-cascade.json](https://docs.payrails.com/images/docs/use-cases/app-publishers/app-publishers-cascade.json) |
> > | Fraud screening on first payments | A fraud check before 3DS and authorization, rejecting high-risk payments and sending the rest through risk-based 3DS | Keep it off the renewal branch: the customer isn't present and the card already passed screening | [Full authorization with fraud and 3DS](https://docs.payrails.com/docs/orchestration/workflow-studio/examples/full-authorization.md) | [app-publishers-fraud-screening.json](https://docs.payrails.com/images/docs/use-cases/app-publishers/app-publishers-fraud-screening.json) |
> > | Routing by currency or payment method | A Condition step that sends, for example, wallets or one currency to a different payment instance | Every new branch needs its own final status and notification | [Provider routing](https://docs.payrails.com/docs/orchestration/workflow-studio/examples/provider-routing.md) | [app-publishers-currency-routing.json](https://docs.payrails.com/images/docs/use-cases/app-publishers/app-publishers-currency-routing.json) |
> >
> > Each template is a complete `payment-acceptance` workflow, built from the Portal's default template with the transaction type branches from this step. The currency template routes `USD` to a second payment instance as an example. To use a template:
> >
> > 1. Download it, then in the Portal open **Workflows → Payment acceptance** and select **New version**.
> > 2. Select **Upload workflow configuration**. The file opens in Workflow Studio as an unsaved version.
> > 3. Select your payment instance on every authorization step, because the templates name no instances. In the cascade and currency templates, pick a different instance on the second-PSP or `USD` steps, and change `USD` to your own currency.
> > 4. In the fraud screening template, select your fraud provider on the fraud check step.
> > 5. Check that the start step offers Card, Apple Pay, and Google Pay as payment options.
> > 6. In **Workflow settings**, set **Instrument future usage** to `Subscription`. The file doesn't carry this setting, so an uploaded version starts without it.
> > 7. Save the version, test it from **Workflows → Test payments**, then mark it **Default**.
>
> > [!TIP]
> >
> > **Definition of Done**
> >
> > You publish the version, and a test card payment goes through the first-payment branch and saves an instrument.

> [accordion] Step 5: Connect your checkout and test end to end
>
> Pick how your checkout collects payment details, build it, and run the staging tests. Use Drop-in or Elements unless your architecture strictly requires server-to-server card payments. With either one, the SDK creates and authorizes the payment, runs 3DS and saves the instrument, and your backend makes one call per checkout. In every option your code never names a PSP, so later routing changes need no release.
>
> > [accordion] Choose an integration option
> >
> > | Integration | What Payrails provides | What you build | Use it when |
> > | - | - | - | - |
> > | Drop-in (recommended) | The whole checkout UI: card form, saved cards, wallet buttons, and the pay button | One backend call per checkout and a container on the page | You want a ready-made checkout with the standard Payrails look |
> > | Elements (recommended) | One component per payment method: card form, pay button, and the Apple Pay and Google Pay buttons | One backend call per checkout and your own page layout around the components | You want control over layout and styling, with the SDK still running the payment |
> > | Secure Fields and server-to-server | Hosted card number, expiry, and CVC fields, so card data never touches your servers | The form, plus execution creation, authorization, 3DS redirects, and result handling in your backend | Server-to-server authorization is a strict requirement |
> >
> > Related guides:
> >
> > * [Checkout SDKs](https://docs.payrails.com/docs/sdks/checkout-sdks.md)
> > * [Web SDK](https://docs.payrails.com/docs/sdks/web.md)
> > * [Add Apple Pay and Google Pay](https://docs.payrails.com/docs/sdks/web/guides/add-apple-pay-and-google-pay.md)
> > * [Collect card data with Secure Fields](https://docs.payrails.com/docs/sdks/web/guides/collect-card-data-with-secure-fields-collect-container.md)
> > * [Server-to-server integration reference architecture](https://docs.payrails.com/docs/use-cases/server-to-server-integration-reference-architecture.md)
>
> > [accordion] Option A: Drop-in or Elements
> >
> > 1. Backend: call `POST /merchant/client/init` with your customer ID as `holderReference` and your workspace ID, and return the response to the browser. Reuse the same `holderReference` for each customer, so saved cards line up.
> > 2. Frontend: install the SDK, initialize it with that response, and mount either Drop-in or the Elements you need. Wallet buttons show only where the device supports them.
> > 3. Use the SDK's `success` and `failed` events for the screen only. Confirm the order from the webhook.
> >
> > ```bash theme={null}
> > npm install @payrails/web-sdk
> > ```
> >
> > ```js theme={null}
> > import { Payrails } from "@payrails/web-sdk";
> >
> > const payrails = await Payrails.init(clientInitResponse);
> >
> > payrails.on("success", (event) => showConfirmation());
> > payrails.on("failed", (event) => showError(event.data?.code));
> >
> > // Drop-in: the whole checkout in one container
> > payrails.dropin({}).mount("#dropin");
> >
> > // Or Elements: one component per payment method
> > payrails.cardForm({ showCardHolderName: true }).mount("#card-form");
> > payrails.paymentButton({ translations: { label: "Pay now" } }).mount("#pay-button");
> >
> > const applePay = payrails.applePayButton({});
> > applePay.isAvailable.then((ok) => ok && applePay.mount("#apple-pay-button"));
> >
> > const googlePay = payrails.googlePayButton({ merchantName: "Your Store" });
> > googlePay.isAvailable.then((ok) => ok && googlePay.mount("#google-pay-button"));
> > ```
>
> > [accordion] Option B: Secure Fields and server-to-server
> >
> > 1. Backend: call `client/init` with `type: tokenization`. This one session serves both the hosted card fields and the wallet buttons. Frontend: mount the card number, expiry, and CVC fields in your own form, then tokenize them to get a payment instrument ID.
> > 2. Backend: create an execution, then call `authorize` on it with the instrument ID.
> > 3. 3DS: when the execution status is `authorizePending`, redirect the customer to `requiredAction.href`. Then read the result from the webhook or by long-polling the execution.
> > 4. Wallets: mount the Apple Pay and Google Pay buttons in the same session. In a `tokenization` session, a button saves the wallet token as an instrument instead of paying. The SDK `success` event with action `TOKENIZE` returns the instrument ID. Your backend then runs steps 2 and 3 with it, exactly as for a card. See [Server-to-server integration reference architecture](https://docs.payrails.com/docs/use-cases/server-to-server-integration-reference-architecture.md) for the button code.
> >
> > ```js theme={null}
> > // Frontend: hosted card fields, then save the card as an instrument
> > import { ElementType } from "@payrails/web-sdk";
> >
> > const container = payrails.collectContainer({});
> > container.createCollectElement({ type: ElementType.CARD_NUMBER }).mount("#cardNumber");
> > container.createCollectElement({ type: ElementType.EXPIRATION_DATE, format: "MM/YY" }).mount("#expiryDate");
> > container.createCollectElement({ type: ElementType.CVV }).mount("#cvv");
> >
> > const instrument = await container.tokenize({ storeInstrument: true, futureUsage: "Subscription" });
> > // send instrument.id to your backend
> > ```
> >
> > ```http theme={null}
> > // Backend: create the execution
> > POST /merchant/workflows/payment-acceptance/executions
> > X-Idempotency-Key: <UUID, reused on retry>
> > {
> >   "merchantReference": "order-1234",
> >   "holderReference": "customer-5678",
> >   "workspaceId": "<workspace id>",
> >   "meta": {
> >     "order": { "reference": "order-1234" },
> >     "customer": { "reference": "customer-5678" }
> >   }
> > }
> >
> > // Backend: authorize it with the saved instrument
> > POST /merchant/workflows/payment-acceptance/executions/{executionId}/authorize
> > X-Idempotency-Key: <UUID, reused on retry>
> > {
> >   "amount": { "value": "9.99", "currency": "EUR" },
> >   "returnInfo": { "success": "https://pay.yourbrand.com/return/{executionId}" },
> >   "paymentComposition": [{
> >     "paymentMethodCode": "card",
> >     "integrationType": "api",
> >     "amount": { "value": "9.99", "currency": "EUR" },
> >     "paymentInstrumentId": "<instrument.id>"
> >   }]
> > }
> > ```
>
> > [accordion] Workspace ID and renewals
> >
> > **Workspace ID.** Pass your workspace ID on the call that starts a payment: `client/init`, or create execution. [Workspaces](https://docs.payrails.com/docs/account-setup/workspaces.md) explains where to find it and how multiple workspaces work.
> >
> > **Renewals, both options.** Your billing job creates an execution with `meta.order.processingType` set to `Subscription`, then authorizes it against the saved instrument. No customer is present and no 3DS runs. Set the processing type when you create the execution, because the workflow's Transaction type condition reads it before the authorize call. Send an `X-Idempotency-Key` UUID with each request, and reuse it when the job retries the same renewal, so a retry never charges twice. [Authorization flags](https://docs.payrails.com/docs/resources/payments/authorization-flags.md) lists the values for subscriptions and one-off charges to a saved card.
> >
> > ```http theme={null}
> > // Create the execution with the processing type
> > POST /merchant/workflows/payment-acceptance/executions
> > X-Idempotency-Key: <UUID, reused on retry>
> > {
> >   "merchantReference": "renewal-1234",
> >   "holderReference": "customer-5678",
> >   "workspaceId": "<workspace id>",
> >   "meta": {
> >     "order": { "reference": "renewal-1234", "processingType": "Subscription" }
> >   }
> > }
> >
> > // Authorize it against the saved instrument
> > POST /merchant/workflows/payment-acceptance/executions/{executionId}/authorize
> > X-Idempotency-Key: <UUID, reused on retry>
> > {
> >   "amount": { "value": "9.99", "currency": "EUR" },
> >   "meta": {
> >     "order": { "processingType": "Subscription" }
> >   },
> >   "paymentComposition": [{
> >     "paymentMethodCode": "card",
> >     "integrationType": "api",
> >     "amount": { "value": "9.99", "currency": "EUR" },
> >     "paymentInstrumentId": "<saved instrument id>"
> >   }]
> > }
> > ```
>
> > [accordion] Flags per transaction type
> >
> > App publishers run three kinds of card payment against the same saved card: the signup, an upsell, and the renewal. Each one carries a different value in `meta.order.processingType`, and the Condition on **Transaction type** in the workflow from [step 4](#step-4-payment-workflow-for-first-payments-and-renewals) routes on it. Transaction type is the Portal's name for the processing type.
> >
> > Send the processing type on the call that creates the execution: `client/init` in Option A, or create execution in Option B. The workflow reads it before the authorize call, so a value sent only on the authorize call doesn't change the branch.
> >
> > `Regular` and `CardOnFile` go down the first-payment branch, where the issuer can ask for 3DS. `Subscription` and `UnscheduledCardOnFile` go down the renewal branch with no 3DS. The values come from [Authorization flags](https://docs.payrails.com/docs/resources/payments/authorization-flags.md).
> >
> > | Transaction | Who starts it | `meta.order.processingType` | Save the card | Workflow branch |
> > | - | - | - | - | - |
> > | Signup, first payment | The customer, in the app | `Regular` | Yes: `storeInstrument: true` and `futureUsage: Subscription` | First payment, 3DS if the issuer asks |
> > | Upsell with the customer present, for example an upgrade confirmed in the app | The customer, on the saved card | `CardOnFile` | No, already saved | First payment, 3DS if the issuer asks |
> > | Upsell or top-up without the customer, for example a one-off charge your backend triggers | You, off-session | `UnscheduledCardOnFile` | No | Renewal, no 3DS |
> > | Renewal | You, on the billing schedule | `Subscription` | No | Renewal, no 3DS |
> >
> > You set `futureUsage` once, when you save the card, and `Subscription` is the right value for a subscription app. When you later charge the same card for a different reason, send the `processingType` that matches that payment, as in the table, and the saved card still works. In Option A, a customer-present upsell goes through the SDK like the first payment, so put `processingType: CardOnFile` in the `meta.order` you pass to `client/init`.
> >
> > **Upsell example, off-session.** The same two calls as the renewal, with `UnscheduledCardOnFile` and a different amount:
> >
> > ```http theme={null}
> > // Create the execution with the processing type
> > POST /merchant/workflows/payment-acceptance/executions
> > X-Idempotency-Key: <UUID, reused on retry>
> > {
> >   "merchantReference": "topup-1234",
> >   "holderReference": "customer-5678",
> >   "workspaceId": "<workspace id>",
> >   "meta": {
> >     "order": { "reference": "topup-1234", "processingType": "UnscheduledCardOnFile" }
> >   }
> > }
> >
> > // Authorize it against the saved instrument
> > POST /merchant/workflows/payment-acceptance/executions/{executionId}/authorize
> > X-Idempotency-Key: <UUID, reused on retry>
> > {
> >   "amount": { "value": "4.99", "currency": "EUR" },
> >   "meta": {
> >     "order": { "processingType": "UnscheduledCardOnFile" }
> >   },
> >   "paymentComposition": [{
> >     "paymentMethodCode": "card",
> >     "integrationType": "api",
> >     "amount": { "value": "4.99", "currency": "EUR" },
> >     "paymentInstrumentId": "<saved instrument id>"
> >   }]
> > }
> > ```
>
> > [accordion] Notifications and customer data
> >
> > **Notifications.** Before you write the handler, read [Receive notifications](https://docs.payrails.com/docs/orchestration/payment-acceptance/receive-notifications.md) for the events and fields to rely on. Match orders by execution ID and your `merchantReference`, never by amount.
> >
> > **Send real customer data.** The Portal's Test payments page fills in a name, email, and billing address for you. Your backend must send the same fields in `meta`. Otherwise a PSP rule that passed from the Portal can fail from your checkout.
> >
> > Once you connect the checkout, run the staging cases in [Test cases](#test-cases).
>
> > [!TIP]
> >
> > **Definition of Done**
> >
> > You tick every staging item in the [go-live checklist](#go-live-checklist). Expect two or three rounds of fixes, which is normal.

> [accordion] Step 6: Go live in production
>
> Production is steps 1 to 4 again with production values, and your code changes only in configuration. Ask your account representative for the production environment (`<yourcompany>.payrails.io`) when you start step 5, with the list of administrator users.
>
> > [accordion] Network tokens and BIN lookup
> >
> > **Network tokens.** To run renewals on Visa and Mastercard network tokens instead of raw card numbers, start the network onboarding at the same time. Payrails registers you with the card networks as an on-behalf-of token requestor, and you supply your legal entity and app details. [Onboarding to networks](https://docs.payrails.com/docs/token-vault/network-tokens/onboarding-to-networks.md) lists the fields for each network. Your Payrails representative confirms when onboarding is complete. You then choose which cards get tokens, with rules or per instrument, as described in [Provision network tokens](https://docs.payrails.com/docs/token-vault/network-tokens/provision-network-tokens.md).
> >
> > **BIN lookup.** BIN lookup fills in the issuer, issuer country, network, and card type on each instrument. That includes Apple Pay and Google Pay tokens. You need it if your workflow routes on any of those fields, or if your backend reads them. Payrails turns it on per environment, so ask your account representative to confirm it's on in staging before you test, and in production before go-live. Instruments created before Payrails turned it on may not carry the BIN data.
>
> > [accordion] What changes in production
> >
> > | Step | What is different in production |
> > | - | - |
> > | 1. Credentials | New API credentials and a new mTLS certificate, because both are per environment |
> > | 2. Instances and notifications | Live PSP credentials, the production Notification URL registered in each PSP dashboard, and your production webhook endpoint with its HMAC key |
> > | 3. Wallets | The same Apple Pay file hosted on the production hostname, and the hostname registered in the production Portal. Google Pay needs nothing |
> > | 4. Workflow | Export the staging version, import it in production, then finish the manual steps under **Move your workflow to production** in this step |
> >
> > Then point your backend at production:
> >
> > | Setting | Staging | Production |
> > | - | - | - |
> > | API base URL | `https://api.eu.staging.payrails.io` | `https://api.payrails.io` |
> > | Client ID and secret | Staging pair | Production pair |
> > | mTLS certificate | Staging certificate | Production certificate |
> > | Workspace ID in requests | Staging workspace | Production workspace |
> > | Web SDK | No change | No change |
> >
> > The Web SDK needs no change. The `client/init` response carries the environment, and the SDK passes it to the Apple Pay and Google Pay buttons. Google Pay switches from Google's TEST mode to PRODUCTION on its own, and nothing in your page code changes.
>
> > [accordion] Move your workflow to production
> >
> > The workflow file carries the logic you tested in staging, but not the links to your staging payment instances, which don't exist in production.
> >
> > 1. In the staging Portal, open **Workflows → Payment acceptance**, select the version that passed your staging tests, and export it to a file.
> > 2. In the production Portal, import that file on the same page. It arrives as a new version, not yet the default.
> >
> > Then make these changes by hand in the imported version:
> >
> > 1. Point every authorization step at your production payment instances.
> > 2. Do the same for every retry or cascade step.
> > 3. Check that the start step offers Card, Apple Pay, and Google Pay, each on a production instance.
> > 4. Check that every branch still ends with a final status and a notification.
> > 5. Publish the version and mark it **Default**. Your code calls `payment-acceptance`, so production picks it up with no release.
>
> > [accordion] Test in production and roll out
> >
> > **Test end to end in production before you roll out.** Before you route any customer to Payrails, run the full journey in production with real cards and accounts: a card payment, both wallets, a refund, and a renewal. Check each one in the Portal, at your webhook endpoint, and in the PSP dashboard. Live cards don't let you force declines or 3DS challenges, so those cases stay proven in staging.
> >
> > The Payrails side of this step is configuration. The slow parts are usually on your side: a production deploy window, live PSP credentials arriving, and waiting for a billing period to end before the first renewal.
> >
> > **First live payment.** Use one internal user, one real card, and your cheapest plan. Check the three places it must show up: the Portal execution, your webhook, and the PSP dashboard. Refund it from the Portal, then repeat with a real Apple ID and a real Google Account. Then open to customers behind your own feature flag, for example 10% of traffic for the first days.
> >
> > **First renewal.** A renewal only happens when a billing period ends, so give the internal test account a short trial. Aim for one merchant-initiated renewal to succeed in production in the first week.
>
> > [!TIP]
> >
> > **Definition of Done**
> >
> > The first live payment and the first real renewal succeed in production, and your traffic runs fully on Payrails.

## Test cases

Run every case in staging before you request go-live. Each one shows up in three places: the SDK event or API response, the execution in the Portal, and the notification at your webhook endpoint.

| Test | Expected |
| - | - |
| Card approved, no 3DS | `success` event, then an `executionActionCompleted` webhook with action `authorize`, and the instrument saved |
| Card with 3DS challenge | `pending`, then `success` after the challenge, and the webhook after the challenge |
| Card declined | `failed` with a reason code and a webhook, then a cascade to the second instance if configured |
| Apple Pay, sandbox tester | Approved, instrument saved |
| Google Pay, test card | Approved, instrument saved |
| Renewal on the saved instrument | Approved without 3DS, on the same PSP as the first payment |
| Refund from the API or the Portal | Refund webhook, and payment status `Refunded` |

Test card numbers come from each PSP: [Stripe testing](https://docs.stripe.com/testing), [Adyen test card numbers](https://docs.adyen.com/development-resources/testing/test-card-numbers/), and [Checkout.com testing](https://www.checkout.com/docs/developer-resources/testing). To simulate payments from the Portal without a PSP account, use [Test payments](https://docs.payrails.com/docs/orchestration/payment-acceptance/test-payments.md).

## Go-live checklist

### Timeline at a glance

Steps 1 to 4 are Portal configuration and fit in the first week. The checkout build in step 5 takes the longest. These estimates are typical for app publishers with dedicated people on the implementation.

| Step | Who does it | Your effort | Elapsed time |
| - | - | - | - |
| 1. Access and credentials | Your backend engineer | One to two hours | First day |
| 2. Payment instances and notifications | Your payments owner (PSP credentials) and backend engineer (webhook endpoint) | Half a day | First two days |
| 3. Apple Pay domain and Google Pay button | Your engineer hosts one Payrails domain association file and registers the domain in the Portal | One hour, then wait | Second day |
| 4. Workflow for first payments and renewals | Your payments owner | One to two hours | Second or third day |
| 5. Connect your checkout and test end to end | Your engineers | Option A (Drop-in or Elements): three to five days to build and two to three days to test. Option B (Secure Fields and server-to-server): five to eight days to build and three days to test | First three weeks |
| 6. Go live in production | You repeat steps 1 to 4 with production values once Payrails provisions the environment, then test end to end in production before rolling out to customers | One day of setup, then end-to-end production tests | Third or fourth week for the first live payment, then one to two weeks of ramp |

> [!TIP]
>
> In total, expect about three weeks with **Payrails Drop-in or Elements** and about four weeks with **Payrails Secure Fields and server-to-server** to the first live payment. Ramping to full traffic takes another one to two weeks. Ask Payrails for the production environment at the start of step 5, so it's ready when your staging tests pass.

### Staging

* [ ] Access token returned over mTLS
* [ ] BIN lookup confirmed as on in staging, if your workflow or backend uses the issuer, country, or card type
* [ ] PSP test instance created with Card, Apple Pay, and Google Pay ticked, and the Notification URL registered at the PSP
* [ ] Webhook endpoint registered and the signature check passing on a Test PSP payment
* [ ] Staging hostname registered under Apple Pay Domains in the Portal
* [ ] Workflow version published with first-payment and renewal branches
* [ ] Card payment approved, 3DS challenge completed, decline handled
* [ ] Apple Pay payment with a sandbox tester account
* [ ] Google Pay payment with a test card
* [ ] Renewal charged from your backend on the saved instrument, no 3DS
* [ ] Refund from the API or Portal, with the webhook received

### Production

* [ ] Production environment requested with the administrator user list
* [ ] BIN lookup confirmed as on in production, if your workflow or backend uses the issuer, country, or card type
* [ ] If you use network tokens: [network onboarding](https://docs.payrails.com/docs/token-vault/network-tokens/onboarding-to-networks.md) details sent to Payrails, onboarding confirmed, and provisioning rules set
* [ ] Production credentials and mTLS certificate installed
* [ ] Live PSP instances created and the production webhook registered
* [ ] Apple Pay file hosted on the production hostname and the hostname registered in the production Portal
* [ ] If you use express checkout: the contact fields you tested in staging applied by Payrails in production
* [ ] Production workflow published and reviewed with Payrails
* [ ] Internal live payment approved and refunded, and wallets tested with real accounts
* [ ] First real renewal seen in production
* [ ] Traffic ramped to 100%

## Common pitfalls

> [accordion] A payment failed. Where do I find the reason?
>
> Every payment is an execution under **Operations** in the Portal, with its status, each action, and the PSP's request and response. [Monitoring workflow executions](https://docs.payrails.com/docs/orchestration/workflow-studio/monitoring.md) explains how to inspect one. [Operation results](https://docs.payrails.com/docs/resources/payments/operation-results.md) and [Error codes](https://docs.payrails.com/docs/resources/error-codes.md) explain the codes it shows. If you contact Payrails support, include the execution ID.

> [accordion] Google Pay works in staging, but every production attempt fails with `OR_BIBED_11`
>
> Your SDK configuration passes `merchantInfo.merchantId`. That replaces the Payrails Google registration, which production rejects. Remove it and pass only `merchantName`.

> [accordion] My domain doesn't show as Registered under Apple Pay Domains, or Apple Pay stopped working on it
>
> Apple couldn't verify the domain association file on that hostname. Open `https://<host>/.well-known/apple-developer-merchantid-domain-association` in a browser and check each of these:
>
> * The file is the Payrails file, byte for byte. Download it again from the link in [step 3](#step-3-apple-pay-domain-and-google-pay-button) rather than copying its contents, which can change line endings.
> * The host serves it directly with a `200`: no redirect (including `http` to `https` or to a `www` host), no login page, and no bot or firewall challenge.
> * The hostname you registered in the Portal is exactly the one that serves the file and shows the button. `yourbrand.com` and `pay.yourbrand.com` are separate registrations.
> * No other provider's file sits at the same path. A host holds only one file, so if another provider already uses it, move the Payrails checkout to a dedicated subdomain.
> * The file is still there. Apple checks it again when the domain's TLS certificate renews, so a deploy that removed it can break Apple Pay weeks later.
> * You registered the hostname in the right Portal. Staging and production each need their own registration.
>
> After fixing the file, remove the domain under **Settings → Apple Pay Domains** and add it again. Full details are in [Apple Pay](https://docs.payrails.com/docs/integrations/payment-methods/apple-pay).

> [accordion] Apple Pay fails in staging with `merchant url validation failed`
>
> You're paying with a real Apple ID. Staging accepts only an [Apple Pay sandbox tester account](https://developer.apple.com/apple-pay/sandbox-testing/), so a real Apple ID returns this error. Real Apple IDs work in production.

## Glossary

| Term | Meaning |
| - | - |
| CIT | Customer-initiated transaction: the customer is present and pays, for example the first subscription payment |
| MIT | Merchant-initiated transaction: you charge a saved card or wallet token later, for example a renewal |
| Payment instance | A PSP merchant account (MID) connected in the Portal. The workflow routes payments to instances |
| Workflow | The rules that set 3DS, routing, capture, and notifications for each payment, versioned in the Portal |
| Execution | One run of the workflow for one payment, listed under **Operations** in the Portal |
| Instrument | A saved card or wallet token that the first payment creates and renewals charge |
| Cascade | A retry of a declined payment on a second payment instance, set up in the workflow |
| Notification | The webhook Payrails sends your backend when a payment, renewal, or refund completes |
| mTLS | Mutual TLS: your backend presents a Payrails-signed certificate on every API call |
| Drop-in | Web SDK option: Payrails renders the whole checkout in one container: card form, saved cards, wallet buttons, and the pay button |
| Elements | Web SDK option: Payrails renders one component per payment method, such as the card form and the wallet buttons, and you lay out the page |
| Secure Fields | Web SDK option: you build the form and Payrails hosts only the card number, expiry, and CVC fields |
| Test PSP | The Payrails built-in simulator, which approves or declines based on the card details you enter, no account needed |


## Related topics

- [Apple Pay](https://docs.payrails.com/docs/integrations/payment-methods/apple-pay.md)
- [Accept APMs without a redirect in the web SDK](https://docs.payrails.com/docs/sdks/web/guides/accept-alternative-payment-methods-without-a-redirect.md)
- [Apple Pay Express](https://docs.payrails.com/docs/integrations/payment-methods/apple-pay/apple-pay-express.md)


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