# Apple Pay

Apple Pay gives users a fast and secure way to complete purchases with OnsideKit.

To enable Apple Pay on Onside, complete these steps:

1. Create a **Merchant ID** in Apple Developer.
2. Generate an **Apple Pay Payment Processing Certificate** for that **Merchant ID**.
3. Send the certificate to Onside.
4. Configure OnsideKit with the same **Merchant ID**.

This setup connects Apple Pay to your Onside integration and lets users pay with Apple Pay in your app.

### Step 1: Create a Merchant ID

You create the **Merchant ID** in the Apple Developer portal.

The Merchant ID identifies your Apple Pay merchant configuration. You will use the same value later in your app setup and in your Onside configuration.

#### Create the Merchant ID in Apple Developer

1. Sign in to your Apple Developer account.
2. Open **Certificates, Identifiers & Profiles**.
3. Go to **Identifiers**.
4. Click **+** to create a new identifier.
5. Select **Merchant IDs**.
6. Click **Continue**.
7. Enter a unique **Merchant ID**.
8. Click **Continue**.
9. Review the values.
10. Click **Register**.

### Step 2: Generate the Apple Pay Payment Processing Certificate

To enable Apple Pay on Onside, Apple must issue an **Apple Pay Payment Processing Certificate** for your **Merchant ID**.

You first need a **Certificate Signing Request (CSR)** file.

Onside provides this CSR file on request.

Email <support@onside.io> and ask for the CSR for your Apple Pay setup.

Use the CSR file provided by Onside when you generate the certificate.

Do not create your own CSR for this step.

#### Request the CSR from Onside

Send an email to <support@onside.io> and include:

* your app name
* your **Merchant ID** from step 1
* your Onside account or publisher name

Once Onside sends you the CSR file, keep it unchanged and use it in Apple Developer.

#### Generate the certificate in Apple Developer

1. Sign in to your Apple Developer account.
2. Open **Certificates, Identifiers & Profiles**.
3. Go to **Identifiers**.
4. Select the **Merchant ID** you created earlier.
5. Open the section for **Apple Pay Payment Processing Certificate**.
6. Start the certificate generation flow for **Apple Pay Payment Processing Certificate**.
7. Upload the CSR file provided by Onside.
8. Complete the generation process.
9. Download the generated certificate file from Apple.

{% hint style="info" %}
Apple Developer can show multiple Apple Pay-related options. For Onside, generate exactly **Apple Pay Payment Processing Certificate**.
{% endhint %}

{% hint style="warning" %}
You must use the CSR file from Onside. If you upload a different CSR, Onside will not be able to use the generated Apple Pay Payment Processing Certificate for your integration.
{% endhint %}

### Step 3: Send the generated certificate to Onside

After Apple generates the certificate, send it to Onside.

Onside uses this certificate to decrypt Apple Pay tokens received during Apple Pay transactions.

Email the generated certificate file to <support@onside.io>.

#### What to include in the email

Include:

* the generated file you downloaded from Apple
* your app name
* your **Merchant ID**
* your Onside account or publisher name

### Step 4: Configure the Merchant ID in your app

After Onside receives and processes the key, configure the same **Merchant ID** in your app.

You must set the value from step 1 in `Onside.applePayMerchantIdentifier`.

Configure this property before the very first attempt to start a purchase with the SDK.

If you set it too late, Apple Pay may not be available when the purchase flow starts.

Set the property during app startup, before you present any purchase UI or call any SDK purchase API.

```swift
import OnsideKit

Onside.applePayMerchantIdentifier = "merchant.your.merchant.id"
```

#### Update your app entitlements

You must also add the same **Merchant ID** to your app entitlements.

This allows your app to present Apple Pay and use the merchant configuration linked to your Apple Developer account.

#### Enable the Apple Pay capability in Xcode

1. Open your app target in Xcode.
2. Open **Signing & Capabilities**.
3. Click **+ Capability**.
4. Add **Apple Pay**.
5. In the Apple Pay configuration, select the **Merchant ID** from step 1.
