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

# Validate Apple Pay Merchant

> Performs Apple Pay merchant validation and returns the merchant session

## Overview

Apple Pay requires merchant validation before the payment sheet can be shown. When the client's `ApplePaySession` fires `onvalidatemerchant`, pass the event's `validationURL` to this endpoint. Firmly performs the mutual-TLS `paymentSession` handshake with Apple and returns Apple's merchant session, which you pass to `session.completeMerchantValidation(...)` on the client.

> [!NOTE]
>
> This endpoint is served by the wallet service under `/api/v1/wallets/...` — it is not under `/domains/{domain}/...` like the other express endpoints. The merchant domain is sent in the request body.

> [!NOTE]
>
> The request's `Origin` (or `Referer`) header is sent to Apple as the `initiativeContext` — the web domain displaying the Apple Pay sheet. That domain must be registered for Apple Pay, so call this endpoint from the page that shows the sheet.

## Authentication

**x-firmly-authorization** `string` *required*

Device authentication token from Browser Session

## Request Body

**validationURL** `string` *required*

The validation URL provided by Apple in the `ApplePaySession` `onvalidatemerchant` event. Must be an Apple Pay gateway URL (`https://apple-pay-gateway*.apple.com/...`); any other host is rejected.

**domain** `string` *required*

The merchant domain (e.g., "merchant.example.com").

**displayName** `string`

The merchant name to show in the Apple Pay sheet. Defaults to the merchant domain when omitted.

## Response

Returns Apple's merchant session object verbatim (not wrapped in another object). Treat it as opaque and pass the whole response body unchanged to `session.completeMerchantValidation()`. Notable fields:

**merchantSessionIdentifier** `string`

Apple's identifier for this merchant session

**merchantIdentifier** `string`

The merchant identifier the session was issued for

**domainName** `string`

The web domain the session is valid for

**displayName** `string`

The merchant name shown in the Apple Pay sheet

**expiresAt** `number`

Session expiry as epoch milliseconds

**signature** `string`

Apple's signature over the session. Do not modify.

## Code Example

```javascript JavaScript theme={null}
session.onvalidatemerchant = async (event) => {
  const response = await fetch(
    'https://api.firmly.work/api/v1/wallets/apple-pay/validate-merchant',
    {
      method: 'POST',
      headers: {
        'x-firmly-authorization': authToken,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        validationURL: event.validationURL,
        domain: 'merchant.example.com',
        displayName: 'Example Store'
      })
    }
  );

  const merchantSession = await response.json();
  session.completeMerchantValidation(merchantSession);
};
```

```python Python theme={null}
import requests

response = requests.post(
    'https://api.firmly.work/api/v1/wallets/apple-pay/validate-merchant',
    headers={
        'x-firmly-authorization': auth_token,
        'Content-Type': 'application/json'
    },
    json={
        'validationURL': validation_url,
        'domain': 'merchant.example.com',
        'displayName': 'Example Store'
    }
)

merchant_session = response.json()
```

```bash cURL theme={null}
curl -X POST https://api.firmly.work/api/v1/wallets/apple-pay/validate-merchant \
  -H "x-firmly-authorization: YOUR_AUTH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"validationURL": "https://apple-pay-gateway.apple.com/paymentservices/startSession", "domain": "merchant.example.com", "displayName": "Example Store"}'
```

## Error Responses

| Code | Description |
| - | - |
| `ErrorBadRequest` | Missing `validationURL` or `domain`, invalid domain, or `validationURL` is not an Apple Pay gateway host |
| `ErrorPaymentMethodNotAvailable` | Apple rejected the merchant validation (Apple's status and message are included in the error description), or Apple Pay is not configured |

## Related Endpoints

* [Complete Apple Pay Order](https://firmly.mintlify.site/api-reference/payment/express-checkout/complete-order-apple-pay.md) - Place the order after the buyer authorizes


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