# Apple Pay

## Purpose&#x20;

Triumph takes payment through Apple Pay for fraud reduction purposes.&#x20;

## Background &#x20;

{% hint style="info" %}
This background section is for your own information, and not neccesary to integrate with Triumph. Move on to [Roadmap](#roadmap) if you're not interested in the internal mechanics of Apple Pay -- we provide detailed steps so you can integrate with ease.&#x20;
{% endhint %}

Apple Pay is a service offered by Apple that allows users that have added payment cards to their Apple Wallet to make purchases in apps. At a high level when a user makes a purchase, `PassKit` (Apple Pay and Wallet) will encrypt the user's payment details and hand the result off to us. Triumph then passes this encrypted information to our backend, which will decrypt the token process the payment.

Apple requires each app that utilizes Apple Pay to do the following

1. Create a `merchantID`
2. Upload a `Certificate Signing Request (CSR)`
3. Enable the Apple Pay capability with the `merchantID` created above&#x20;

Traditionally, when creating a CSR the developer will create and hold a private key associated with the CSR. The CSR itself does not contain private information but instead has the corresponding "public key" that will be used encrypt the Apple Pay tokens. When the developer uploads the CSR they do it under the `merchantId` they previously created and Apple gives them back an **Apple Pay Payment Processing Certificate**. The developer then adds their `merchantId` to their app's configuration.

This allows apple to encrypt the Apple Pay tokens with the correct public key so that only the developer (or whoever has access to both the secret **and** the Apple Pay Processing Certificate) can decrypt the tokens.

## Roadmap

{% hint style="info" %}
Triumph will be the sole custodian of the corresponding secret keys for each CSR, which lasts 25 months.&#x20;
{% endhint %}

Since Triumph will decrypt Apple Pay tokens on your behalf, the Apple Pay flow is slightly different from the normal case above. You will:

1. Create a `merchantID`
2. Download a Triumph generated CSR and upload it to Apple
3. Download an Apple Payment Processing Certificate from Apple and upload this to Triumph.&#x20;
4. Add the merchantID to your game.

<figure><img src="/files/Gl0RXAFC3itZyr4lrJUM" alt=""><figcaption><p>Apple Pay Configuration Flow</p></figcaption></figure>

## Creating a MerchantID&#x20;

To create a merchantID, log in to your Apple Business Developer Account [here](https://idmsa.apple.com/IDMSWebAuth/signin?appIdKey=891bd3417a7776362562d2197f89480a8547b108fd934911bcbea0110d07f757\&path=%2Faccount%2F\&rv=1), and and click **Identifiers under** **Certificates, Identifiers & Profiles.**&#x20;

<figure><img src="/files/B4MzaLLPjE5IuEwJ5qhA" alt=""><figcaption><p>Click Identifiers Under Certificates, Indentifiers, and Profiles</p></figcaption></figure>

Under **Identifiers**, click the **+** button to add an identifier.

<figure><img src="/files/E5efqcql6YdnQM8xaeVK" alt=""><figcaption></figcaption></figure>

Scroll down to **Merchant IDs,** select it, and click Continue in the upper right corner.&#x20;

<figure><img src="/files/7vhTvK1Eo2OYYzUikqon" alt=""><figcaption></figcaption></figure>

Give a description for your `merchantID` and an identifier of the form `merchant.{yourGameName}.triumph.` Hit Continue.

<figure><img src="/files/dIziAQNsDcBvLd3HYUYK" alt=""><figcaption></figcaption></figure>

Confirm that the identifier has been successfully added to your list of identifiers.

<figure><img src="/files/GeaNQSFzNuioFupXR6jj" alt=""><figcaption></figcaption></figure>

## Upload Triumph CSR to Apple

### Generate CSR

Navigate to the Triumph Dashboard, and click on `Settings -> Apple Pay.` Click dowload certificate signing request. Note: this may take up to 30 seconds to generate and download. The file will be named **triumph-certificate-signing-request.csr.** Do not change the name of this file.

<figure><img src="/files/sJiQo0NYnemZ13fJ4oC6" alt=""><figcaption></figcaption></figure>

### Upload to Apple

Navigate to the link [here](https://developer.apple.com/account/resources/certificates/add), and scroll down, and select **Apple Payment Processing Certificate**. Click continue at the upper right corner of the page.

<figure><img src="/files/V4ghOqr41iLzvxOXzGHo" alt=""><figcaption></figcaption></figure>

Next, select the `merchantID` you generated in the previous step on the drop down menu and hit continue.

<figure><img src="/files/ufoQWD0k3iAKei7P1Awp" alt=""><figcaption></figcaption></figure>

Click **Create Certificate.**

<figure><img src="/files/Upmt5AjMcTApiioPwcSx" alt=""><figcaption></figcaption></figure>

Select **no** for the question about Mainland China (Triumph does not operate in China) and hit continue.

<figure><img src="/files/YdkSFpODCXXFzTjxb9yt" alt=""><figcaption></figcaption></figure>

Upload the **CSR file** you generated in the previous step and click **Continue**. &#x20;

<figure><img src="/files/MTj4BC9voRONSKxPXhUr" alt=""><figcaption></figcaption></figure>

Download the Apple Payment Processing Certificate. This should be named **apple\_pay.cer**.

## Upload Apple Payment Processing Certificate to Triumph

Finally, go back to the Triumph Dashboard and upload the generated Payment Processing Cerificate to Triumph.

<figure><img src="/files/nNYE7TlYLGwrcLGjgFft" alt=""><figcaption></figcaption></figure>

## Add MerchantID to Your Game

All thats left to do is add the merchantID to your game. This is simple.

{% tabs %}
{% tab title="Unity" %}
Navigate to the`TriumphAPI` prefab, and change the `merchantID` variable to what you just created. Make sure this name is exactly matched, or you will not be able to process payments.

```csharp
using UnityEngine;
using TriumphKit;

public class TriumphUnityNativeMethods: MonoBehaviour, ITriumphUnityNativeMethods {
    
    // REQUIRED CONFIG IMPLEMENTATION 
    
   /*
    * This is where you will put your game's gameId, which you will
    * provision on the Triumph dashboard later. For now, leave this
    * as the empty string to load the SDK in sandbox mode.
    */
    public static readonly string gameId = ""
    
   /*
    * Add the merchantId to this variable
    */
    public static readonly string merchantId = "merchant.gameName.triumph"
```

###

{% endtab %}

{% tab title="Swift" %}

### Swift&#x20;

Navigate to `Info.plist`, and add to the Apple Pay Capability (for a reminder on how to do this go [here](/triumph-sdk/keys-and-permissions.md)). You should now see the `merchantID` you created as an option. Select it. If you don't see your `merchantID`, restart Xcode. You may needc to do this a few times

<figure><img src="/files/Z6UDFN3Epjr1mlnq7lex" alt=""><figcaption><p>Select the merchantId you just created </p></figcaption></figure>
{% endtab %}
{% endtabs %}

## Next Steps

You're now ready to build your project!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.triumpharcade.com/triumph-sdk/apple-pay.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
