# 2 - Validate Merchant

## Implementation Flow

### Step 1: Frontend Request Handling

When Apple Pay initiates a merchant validation request, your frontend application should capture the validation parameters and forward them to your backend server for processing.

### Step 2: Backend Server Processing

Your merchant server (such as an AWS Lambda function) will handle the core validation logic through the following steps:

1.  **Obtain OAuth Access Token**
    -   Request an access token from the OAuth token endpoint
    -   Use your client credentials for authentication - [POST Generate an authentication token for Direct and Order API](https://novatti.portal.swaggerhub.com/proxy/docs/novatti-unify-authentication-api-v-1-0-0#/Authentication/generateToken)
2.  **Transform Request Data**
    -   Convert Apple Pay validation parameters to our API format
    -   Ensure all required fields are properly formatted
3.  **Call our Validation Endpoint**
    -   Send the validation request using Bearer token authentication - [POST Validate Apple Pay Merchant](https://novatti.portal.swaggerhub.com/proxy/docs/apple-pay-v-1-0-0#/default/validateMerchant)
    -   Include all necessary merchant and transaction details
4.  **Process Response**
    -   Transform Novatti's response back to Apple Pay's expected format
    -   Return the merchant session object to your frontend

## API Request Examples

### OAuth Token Request

**Endpoint:** `POST OAUTH_TOKEN_ENDPOINT`

**Request Body:**

```text
{
  "client_id": "your_oauth_client_id",
  "client_secret": "your_oauth_client_secret", 
  "audience": "your_oauth_audience",
  "grant_type": "client_credentials"
}
```

### Novatti Merchant Validation Request

**Endpoint:** `POST [Novatti's Validation Endpoint]`

**Headers:**

```text
Authorization: Bearer {access_token}
```

**Request Body:**

```text
{
  "Header": {
    "TransactionType": "ValidateApplePayMerchant",
    "MerchantID": "your_merchant_id",
    "UserID": "your_proxy_user_id",
    "Version": "2"
  },
  "Merchant": {
    "InitiativeContext": "yourdomain.com",
    "Initiative": "web", 
    "DisplayName": "Your Store Name",
    "MerchantIdentifier": "See Important Notes Below"
  }
}
```

**Important Notes:**

-   Ensure `MerchantID` is in uppercase format
-   The `MerchantIdentifier` for sandbox: merchant.demo.novattipayments.com
-   The `MerchantIdentifier` for production: merchant.com.novatti.applepay

### Expected Response from Novatti

```text
{
  "Result": {
    "ResponseCode": "1000",
    "ResponseMessage": "Request successful", 
    "ResponseTimestamp": "10092025201518",
    "MerchantTimestamp": "2025-09-10T22:15:18.782 NZST",
    "MerchantID": "BWAQOK8PLRDMCJW"
  },
  "Merchant": {
    "PspId": "...",
    "Retries": 0,
    "OperationalAnalyticsIdentifier": "...",
    "Signature": "...",
    "DisplayName": "Your Store Name",
    "DomainName": "yourdomain.com", 
    "MerchantIdentifier": "...",
    "Nonce": "...",
    "MerchantSessionIdentifier": "...",
    "ExpiresAt": "...",
    "EpochTimestamp": "..."
  }
}
```

## Next Steps

Once you've successfully implemented the merchant validation flow, you'll be ready to process Apple Pay transactions through Novatti's platform. Make sure to test the validation process thoroughly in your development environment before going live.

If you have any questions about implementing this flow or need clarification on any of the API parameters, please don't hesitate to reach out to your Novatti integration team.
