# Apple Pay

Use this guide when you integrate Apple Pay through the Verifone eComm API and want direct control over merchant validation and wallet transactions.

## Use this page if

* You process Apple Pay with your own frontend and backend.
* You want to create the merchant session from your server.
* You want to send the Apple Pay token to Verifone through the API.

If you want a Verifone-hosted flow, use [Checkout Apple Pay](/online-payments/checkout/accepting-payments/apple-pay.md) instead.

### Before you start

* Enable Apple Pay in your Verifone setup.
* Collect the correct `payment_provider_contract`.
* Prepare a backend endpoint for merchant validation.
* Prepare a backend endpoint for transaction creation.
* Decide how you will generate and store a unique `merchant_reference`.

### Integration flow at a glance

1. Enable Apple Pay for your Verifone account and domain.
2. Start the Apple Pay session in the browser.
3. Validate the merchant session through your backend.
4. Receive the Apple Pay payment token from the browser.
5. Send the wallet payload to your backend.
6. Create the wallet transaction through the Verifone API.

{% hint style="info" %}
This page focuses on the direct API path. For wallet setup choices and platform-specific routing, use the [Wallet Configuration Guide](/online-payments/advanced-payment-methods-apms/wallet-configuration-guide.md).
{% endhint %}

You can also accept payments through Apple Pay via [Checkout](/online-payments/checkout/accepting-payments/apple-pay.md) (Hosted Payments Page - HPP).

Follow the integration steps below to process transactions via Verifone eComm API.

### Initiate a wallet payment using Apple Pay <a href="#initiate-a-wallet-payment-using-apple-pay" id="initiate-a-wallet-payment-using-apple-pay"></a>

Check also our [API](broken://spaces/OiXbo96Og9EN7rz2U44K/pages/OnU159hHWJkJp14gc6AP) documentation.

1. Enable Apple Pay via Verifone's Hosted Checkout or via Direct API, as per the instructions from the [Apple Pay](/online-payments/advanced-payment-methods-apms/apple-pay.md) documentation.

   <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>To enable the Apple Pay wallet with Mobile SDKs check the <a href="/pages/YzUh8iV3MKHTywVkRXDz">Apple Pay</a> information.</p></div>
2. Generate a unique `merchant_reference`.

   The `merchant_reference` needs to be unique to identify the shopper when they are redirected to your server by Apple Pay. In the next step, you will be creating a transaction through the API, the transaction will return an id that needs to be stored safely with the reference. When the shopper returns, you can use this reference to confirm either through the webhook or through the GET transaction API call if the shopper has completed the transaction.
3. Required fields.

   <table><thead><tr><th width="168">Parameters</th><th>Description</th></tr></thead><tbody><tr><td><code>payment_provider_contract</code></td><td>In the <a href="/spaces/dzivQyj8aHN5Kvmx8apX/pages/bPyZ7V1fLgXFwOyS2Ndk">Payment Provider Contracts</a> section in Verifone Central, set the <em>Payment Type</em> to <em>Apple Pay for Web</em>, select your contract and copy the Payment Provider Contract ID. Note this value is different in Sandbox and in Production.</td></tr><tr><td><code>amount</code></td><td>Amount of the transaction.</td></tr><tr><td><code>merchant_reference</code></td><td>Unique UUID you generate and can link the transaction to when the customer returns.</td></tr><tr><td><code>currency_code</code></td><td>More on the all currencies supported here: Verifone <a href="/spaces/OiXbo96Og9EN7rz2U44K/pages/OnU159hHWJkJp14gc6AP">eCommerce</a> API.</td></tr><tr><td><code>wallet_type</code></td><td>string Enum: "APPLE_PAY"</td></tr><tr><td><code>wallet_payload</code></td><td>object<br>The encrypted payload object provided by the wallet on the frontend.</td></tr></tbody></table>

### Start a payment session for Apple Pay wallet transactions <a href="#start-a-payment-session-for-apple-pay-wallet-transactions" id="start-a-payment-session-for-apple-pay-wallet-transactions"></a>

The *Create a merchant payment session* API documentation can be found [here](broken://spaces/OiXbo96Og9EN7rz2U44K/pages/OnU159hHWJkJp14gc6AP).

#### Create a merchant payment session <a href="#create-a-merchant-payment-session" id="create-a-merchant-payment-session"></a>

| Parameters                  | Description                                                                                                                                        |
| --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| `validation_url`            | <p><strong>String</strong></p><p>The ULR pointing to the Apple Pay validation location.</p>                                                        |
| `domain`                    | <p><strong>String</strong></p><p>The domain from which the payment request will be initiated.</p>                                                  |
| `payment_provider_contract` | <p><strong>String</strong> \<uuid-flexible></p><p>The identifier of payment provider contract you want to process the transaction request with</p> |

#### Web integration <a href="#web-integration" id="web-integration"></a>

An Apple Pay web integration consists of implementing both client-side and server-side components. You will need to implement the following:

* Create your Apple Pay button and initialize your Apple Pay session when clicked.
  * <a href="https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons_using_javascript" class="button primary" data-icon="apple-whole">Apple Pay Buttons</a>
* Initiate the merchant session by calling the `validatemerchant` event and providing the response to the **session.completeMerchantValidation** callback.
  * <a href="/spaces/OiXbo96Og9EN7rz2U44K/pages/OnU159hHWJkJp14gc6AP" class="button secondary" data-icon="computer">eCommerce</a>
* Use the Apple Pay token to make a wallet transaction API call and complete the Apple Pay session based on the response.
  * <a href="/spaces/OiXbo96Og9EN7rz2U44K/pages/OnU159hHWJkJp14gc6AP" class="button secondary" data-icon="computer">eCommerce</a>

**Code sample**

```json
const ApplePaymentOptions = {
  countryCode: "US",
  currencyCode: "USD",
  merchantCapabilities: ["supports3DS"],
  supportedNetworks: ["visa", "masterCard", "amex", "discover"],
  total: {
    label: "Demo (Card is not charged)",
    type: "final",
    amount: "1.99",
  },
};
const canMakePayments =
  window.ApplePaySession && window.ApplePaySession.canMakePayments();
let session;
function handleApplePayRequest(formValues) {
  if (canMakePayments) {
    session = new window.ApplePaySession(3, ApplePaymentOptions);
    session.onpaymentauthorized = makeTransaction(formValues);
    session.addEventListener("validatemerchant", validateMerchant);
    session.begin();
    console.log("INFO - BEGIN SESSION...");
  }
}
function validateMerchant(e) {
  // Pass the validation URL and domain to your server to make the wallet transaction API call
  fetch(`YOUR_ENDPOINT`, {
    method: "POST",
    headers: REQUEST_HEADERS,
    body: JSON.stringify({
      validation_url: e.validationURL,
      domain: window.location.hostname
    }),
  })
    .then((res) => res.json())
    .then((sessionObject) => {
      session.completeMerchantValidation(sessionObject);
    })
    .catch((err) => console.log("ERROR - MERCHANT VALIDATION: ", err));
}
function makeTransaction(formValues) {
  return (e) => {
    const applePaymentObject = e.payment;
    const payload = {
      token: applePaymentObject.token.paymentData,
    };
  // Pass the Apple Pay token to your server to make the wallet transaction API call
    fetch(`YOUR_ENDPOINT`, {
      method: "POST",
      headers: REQUEST_HEADERS,
      body: JSON.stringify(payload),
    })
      .then((res) => res.json())
      .then((res) => {
        // Check the response status and complete the payment session
        if (res.status === 'AUTHORIZED') {
          session.completePayment(0);
        }
      })
      .catch((err) => console.log("ERROR: ", err));
  };
}
```

### Related guides

* [Wallet Configuration Guide](/online-payments/advanced-payment-methods-apms/wallet-configuration-guide.md)
* [Apple Pay](/online-payments/advanced-payment-methods-apms/apple-pay.md)
* [Checkout Apple Pay](/online-payments/checkout/accepting-payments/apple-pay.md)


---

# 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.verifone.com/online-payments/api-integration/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.
