# Apple Pay

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 ApplePay <a href="#initiate-a-wallet-payment-using-applepay" id="initiate-a-wallet-payment-using-applepay"></a>

Check also our [API](/api-reference/open-api-references/ecommerce.md) documentation.

1. Enable ApplePay 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 ApplePay 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 successfully 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](/api-reference/open-api-references/ecommerce.md).

### 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 on the `validatemerchant` event and provide 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));
  };
}
```


---

# 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.
