***

title: Add Apple Pay to your integration
iconPrefix: fab
icon: apple
intro: Set up Apple Pay to run transactions with our gateway.
published: true
---------------------

For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see https://docs.payroc.com/full-stack-guides/take-payments/apple-pay/llms.txt. For full documentation content, see https://docs.payroc.com/full-stack-guides/take-payments/apple-pay/llms-full.txt.

Allow your merchants to accept Apple Pay as a payment method.

## Integration steps

**Step 1.** Integrate with the Apple Pay JS API.\
**Step 2.** Integrate with the Payroc API:\
Step 2a - Start an Apple Pay session.\
Step 2b - Run a sale.

## Before you begin

### Bearer tokens

Use our Identity Service to generate a Bearer token to include in the header of your requests. To generate your Bearer token, complete the following steps:

1. Include your API key in the x-api-key parameter in the header of a POST request.
2. Send your request to [https://identity.payroc.com/authorize](https://identity.payroc.com/authorize).

<Note>
  **Note:** You need to generate a new Bearer token before the previous Bearer token expires.
</Note>

#### Example request

```sh
curl --location --request POST  'https://identity.payroc.com/authorize' --header 'x-api-key: <api key>'
```

#### Example response

If your request is successful, we return a response that contains your Bearer token, information about its scope, and when it expires.

```json
{
  "access_token": "eyJhbGc....adQssw5c",
  "expires_in": 3600,
  "scope": "service_a service_b",
  "token_type": "Bearer"
}
```

### Headers

To create the header of each GET request, you must include the following parameters:

* **Content-Type:** Include application/json as the value for this parameter.
* **Authorization:** Include your Bearer token in this parameter.

```sh
curl
  -H "Content-Type: application/json"
  -H "Authorization: <Bearer token>"
```

To create the header of each POST request, you must include the following parameters:

* **Content-Type:** Include application/json as the value for this parameter.
* **Authorization:** Include your Bearer token in this parameter.
* **Idempotency-Key:** Include a UUID v4 to make the request idempotent.

```sh
curl
  -H "Content-Type: application/json"
  -H "Authorization: <Bearer token>"
  -H "Idempotency-Key: <UUID v4>"
```

### Errors

If your request is unsuccessful, we return an error. For more information about errors, see [Errors](/api/errors).

## Step 1. Integrate with the Apple JS API

To integrate with the Apple Pay JS API, go to [https://developer.apple.com/apple-pay/](https://developer.apple.com/apple-pay/).

Your integration with Apple must retrieve the following information:

* **Validation URL** - Apple provides the validation URL that you send to us when you create an Apple Pay session.
* **Encrypted payment details** - Apple encrypts the cardholder's payment details and returns them to your integration. After you receive the encrypted payment details, convert them to hexidecimal.

## Step 2. Integrate with the Payroc API

Use our API to start the merchant session with Apple Pay and retrieve the startSessionResponse object. After you use the Apple Pay JS API to encrypt the cardholder's payment details, use our API to run the sale.

### Step 2a. Start an Apple Pay session

To start an Apple Pay session with Apple, send a request to our Apple Pay sessions endpoint.

| Endpoint   | Prefix     | URL                                                                                                                                                                                            |
| :--------- | :--------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Test       | `api.uat.` | [https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/apple-pay-sessions](https://api.uat.payroc.com/v1/processing-terminals/\{processingTerminalId}/apple-pay-sessions) |
| Production | `api.`     | [https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/apple-pay-sessions](https://api.payroc.com/v1/processing-terminals/\{processingTerminalId}/apple-pay-sessions)         |

In the body of your request, include the following parameters:

* **appleDomainId** - You can view the appleDomainId after you add the merchant's domain to the Self-Care Portal.
* **appleValidationUrl** - Apple provides the validation URL as part of your integration with the Apple Pay JS API.

In the response, we return the startSessionResponse object. Send the content of the startSessionResponse object to Apple to retrieve the cardholder's encrypted payment details.

### Request parameters

To create the body of your request, use the following parameters:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/apple-pay-sessions" selector="request.body" />

### Example request

<EndpointRequestSnippet endpoint="POST /processing-terminals/{processingTerminalId}/apple-pay-sessions" />

### Response fields

If your request is successful, our gateway starts the merchant session with Apple and returns the following fields:

<EndpointSchemaSnippet endpoint="POST /processing-terminals/{processingTerminalId}/apple-pay-sessions" selector="response.body" />

### Example response

<EndpointResponseSnippet endpoint="POST /processing-terminals/{processingTerminalId}/apple-pay-sessions" example="applePayResponseSession" />

### Step 2b. Run a sale

After you retrieve the cardholder's encrypted payment details from Apple, use our payments endpoint to run a sale.

| Endpoint   | Prefix     | URL                                                                              |
| :--------- | :--------- | :------------------------------------------------------------------------------- |
| Test       | `api.uat.` | [https://api.uat.payroc.com/v1/payments](https://api.uat.payroc.com/v1/payments) |
| Production | `api.`     | [https://api.payroc.com/v1/payments](https://api.payroc.com/v1/payments)         |

In your request, send the following parameters in the paymentMethod object:

**type** - Provide a value of `digitalWallet`.\
**serviceProvider** - Provide a value of `apple`.\
**encryptedData** - Provide the encrypted payment details that you retrieved from the Apple Pay JS API. The payment details must be in hexadecimal format.

### Request parameters

To create the body of your request, use the following parameters:

<EndpointSchemaSnippet endpoint="POST /payments" selector="request.body" />

### Example request

<EndpointRequestSnippet endpoint="POST /payments" example="Apple Pay Payment" />

### Response fields

If your request is successful, our gateway uses the card details to run a sale. The response contains the following fields:

<EndpointSchemaSnippet endpoint="POST /payments" selector="response.body" />

### Example response

<EndpointResponseSnippet endpoint="POST /payments" example="applePaySaleResponse" />

## Next steps

After you integrate with the Apple Pay JS API and the Payroc API, complete the following steps:

* **Set up Apple Pay for each merchant** - To set up Apple Pay for a merchant to run transactions, go to [Set up Apple Pay for a Merchant](/guides/take-payments/apple-pay/set-up-apple-pay-for-a-merchant).
* **Set up a Sandbox Apple Account** - To run test transactions with Apple Pay, set up a Sandbox Apple Account. To set up a Sandbox Apple Account, contact our Integrations Team at [integrationsupport@payroc.com](mailto:integrationsupport@payroc.com).