# Apple Pay Integration

Accept Apple Pay payments using the Widget SDK.

## How It Works

The SDK renders an Apple Pay button directly on your checkout page. When the customer clicks it, the native Apple Pay payment sheet opens with the amount you specified. After the customer authorizes, the SDK delivers a token via `onTokenizationComplete`. There is no separate `tokenize()` call — the button click is the trigger. For complete reference, see [UI SDK reference](/docs/ui-sdk-reference).

## Prerequisites

- A registered Apple Pay merchant identifier
- Safari or an Apple Pay-capable browser/device
- Domain verification with Apple — you must host the Apple domain verification file at `/.well-known/apple-developer-merchantid-domain-association` on your registered domain


## Step 1 — Load the SDK

```html
<script src="https://cdn.nelnetpay.com/sdk/v1.0.0/widget-sdk.js"></script>
```

## Step 2 — Add a container

```html
<div id="apple-pay-button"></div>
```

## Step 3 — Initialize the SDK

Provide your session token along with your Apple Pay merchant identifier and registered domain.

```js
const wg = new Widget({
  sessionToken: '<SESSION_TOKEN>',
  partnerInternalMerchantIdentifier: '<MERCHANT_IDENTIFIER>',
  domainName: 'checkout.example.com',
  // ...additional options — see UI SDK Reference

  onTokenizationComplete: (result) => {
    // Forward result.token to your backend
  },

  onError: (error) => {
   
  }
});
```

## Step 4 — Render the Apple Pay button

Call `renderApplePayButton` with the container selector and the payment options. The SDK renders the button and wires up the Apple Pay flow.

```js
wg.renderApplePayButton('#apple-pay-button', {
  amount: 75.00 
});
```

If `countryCode` and `currencyCode` are not provided, they default to `US` and `USD`. When the customer clicks the button, the native Apple Pay sheet opens with the amount. After they authorize, `onTokenizationComplete` is invoked with the token.

When the customer clicks the button, the native Apple Pay sheet opens with the amount. After they authorize, `onTokenizationComplete` is invoked with the token.

## Step 5 — Process the payment

Send the `token` to your backend. Your server submits it to the [Payments API](https://docs.nelnetpay.com/apis/osi-payments-api/other/processpaymentrequest) to process the charge.

### Multi-merchant payment

For platforms that split a single checkout across multiple merchants. Apple Pay generates one token per merchant.

```js
wg.renderApplePayButton('#apple-pay-button', {
  amount:110.00   
  lineItems: [      
    { label: 'AAA University', amount: '100.00' },
    { label: 'BBB Service Fee', amount: '10.00' }
  ],
  multiTokenContexts: [
    {
      partnerMerchantIdentifier: 'TESTCLIENT_a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
      entityId: 'A-123',
      merchantName: 'AAA University',
      amount: '100.00'
    },
    {
      partnerMerchantIdentifier: 'TESTCLIENT_a1b2c3d4-e5f6-g7h8-i9j0-k1l2m3n4o5p6',
      entityId: 'B-456',
      merchantName: 'BBB Service Fee',
      amount: '10.00'
    }
  ]
});
```

### Recurring payment

```js
wg.renderApplePayButton('#apple-pay-button', {
  amount: 4.99,
  lineItems: [
    { label: 'Recurring', amount: '4.99' }
  ],
  recurringPaymentRequest: {
    paymentDescription: 'A description of the recurring payment to display to the user in the payment sheet.',
    regularBilling: {
      label: 'Recurring',
      amount: '4.99'
    },
    billingAgreement: 'A localized billing agreement displayed to the user in the payment sheet prior to the payment authorization.',
    managementURL: 'https://applepaydemo.apple.com'
  }
});
```

## Complete example (one-time)

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Checkout</title>
</head>
<body>
  <h1>Checkout</h1>
  <div id="apple-pay-button"></div>

  <script src="https://cdn.nelnetpay.com/sdk/v1.0.0/widget-sdk.js"></script>
  <script>
    const wg = new Widget({
      sessionToken: window.__SESSION_TOKEN__,
      partnerInternalMerchantIdentifier: '<MERCHANT_IDENTIFIER>',
      applePayDomain: window.location.hostname,

      onTokenizationComplete: (result) => {
        // Forward result.token to your backend
      },

      onError: (error) => {
       //errors
      }
    });

    wg.renderApplePayButton('#apple-pay-button', {
      amount: 75.00
    });
  </script>
</body>
</html>
```