# Create Apple Pay token

Connect an Apple Pay token to the specified account.

Read our [Apple Pay tutorial](https://docs.moov.io/guides/sources/cards/apple-pay/#register-your-domains) to learn more. The `token` data is defined by Apple Pay and should be passed through from Apple Pay's response unmodified.

To access this endpoint using an [access token](https://docs.moov.io/api/authentication/access-tokens/) you'll need to specify the `/accounts/{accountID}/cards.write` scope.

## Request

POST

/accounts/{accountID}/apple-pay/tokens

### Shell Example

```shell
curl -X POST "https://api.moov.io/accounts/{accountID}/apple-pay/tokens" \
  -H "Authorization: Bearer {token}" \
  -H "X-Moov-Version: v2026.04.00" \
  -d '{
  "token": {
    "paymentData": {
      "version": "EC_v1",
      "data": "3+f4oOTwPa6f1UZ6tG...CE=",
      "signature": "MIAGCSqGSIb3DQ.AAAA==",
      "header": {
        "publicKeyHash": "l0CnXdMv...D1I=",
        "transactionId": "32b...4f3"
      }
    },
    "paymentMethod": {
      "displayName": "Visa 1234",
      "network": "Visa",
      "type": "debit"
    },
    "transactionIdentifier": "32b...4f3"
  }
}'
```

### Go Example

```go
mc, _ := moov.NewClient()

var accountID string

address := moov.ApplePayBillingContact{
  AddressLines: []string{
    "123 Sesame Street",
  },
  Locality:           "Phoenix",
  PostalCode:         "30345",
  AdministrativeArea: "AZ",
  CountryCode:        "US",
}

token := moov.ApplePayToken{
  PaymentData: moov.ApplePaymentData{
    Version:   "EC_v1",
    Data:      "3+f4oOTwPa6f1UZ6tG...CE=",
    Signature: "MIAGCSqGSIb3DQ.AAAA==",
    Header: moov.ApplePaymentDataHeader{
      EphemeralPublicKey: "MFkwEK...Md==",
      PublicKeyHash:      "l0CnXdMv...D1I=",
      TransactionId:      "32b...4f3",
    },
  },
  PaymentMethod: moov.ApplePaymentMethod{
    DisplayName: "Visa 1234",
    Network:     "Visa",
    Type:        "debit",
  },
  TransactionIdentifier: "32b...4f3",
}

mc.LinkApplePayToken(ctx, accountID,
  moov.LinkApplePay{
    Token:          token,
    BillingContact: address,
  })
```

### TypeScript Example

```typescript
import { Moov } from "@moovio/sdk";

const moov = new Moov({
  security: {
    username: "",
    password: "",
  },
});

async function run() {
  const result = await moov.applePay.linkToken({
    accountID: "bf498c07-3852-4060-b561-bf992e26a851",
    linkApplePay: {
      token: {
        paymentData: {
          version: "EC_v1",
          data: "3+f4oOTwPa6f1UZ6tG...CE=",
          signature: "MIAGCSqGSIb3DQ.AAAA==",
          header: {
            ephemeralPublicKey: "MFkwEK...Md==",
            publicKeyHash: "l0CnXdMv...D1I=",
            transactionId: "32b...4f3",
          },
        },
        paymentMethod: {
          displayName: "Visa 1234",
          network: "Visa",
          type: "debit",
        },
        transactionIdentifier: "32b...4f3",
      },
      billingContact: {
        addressLines: [
          "123 Sesame Street",
        ],
        locality: "Phoenix",
        postalCode: "30345",
        administrativeArea: "AZ",
        countryCode: "US",
      },
    },
  });

console.log(result);
}

run();
```

### PHP Example

```php
declare(strict_types=1);

require 'vendor/autoload.php';

use Moov	o;
use Moov	o	oModels;

$sdk = MoovPhp	o::builder()
    ->setSecurity(
        new Components	oSecurity(
            username: '',
            password: '',
        )
    )
    ->build();

$linkApplePay = new Components	oLinkApplePay(
    token: new Components	oLinkApplePayToken(
        paymentData: new Components	oLinkApplePaymentData(
            version: 'EC_v1',
            data: '3+f4oOTwPa6f1UZ6tG...CE=',
            signature: 'MIAGCSqGSIb3DQ.AAAA==',
            header: new Components	oApplePayHeader(
                ephemeralPublicKey: 'MFkwEK...Md==',
                publicKeyHash: 'l0CnXdMv...D1I=',
                transactionId: '32b...4f3',
            ),
        ),
        paymentMethod: new Components	oLinkApplePaymentMethod(
            displayName: 'Visa 1234',
            network: 'Visa',
            type: 'debit',
        ),
        transactionIdentifier: '32b...4f3',
    ),
    billingContact: new Components	oAppleBillingContact(
        addressLines: [
            '123 Sesame Street',
        ],
        locality: 'Phoenix',
        postalCode: '30345',
        administrativeArea: 'AZ',
        countryCode: 'US',
    ),
);

$response = $sdk->applePay->linkToken(
    accountID: 'bf498c07-3852-4060-b561-bf992e26a851',
    linkApplePay: $linkApplePay
);

if ($response->linkedApplePayPaymentMethods !== null) {
    // handle response
}
```

### Java Example

```java
package hello.world;

import io.moov.sdk.Moov;
import io.moov.sdk.models.components.*;
import io.moov.sdk.models.errors.GenericError;
import io.moov.sdk.models.errors.LinkApplePayError;
import io.moov.sdk.models.operations.LinkApplePayTokenResponse;
import java.lang.Exception;
import java.util.List;

public class Application {

public static void main(String[] args) throws GenericError, LinkApplePayError, Exception {

Moov sdk = Moov.builder()
                .security(Security.builder()
                    .username("")
                    .password("")
                    .build())
            .build();

LinkApplePayTokenResponse res = sdk.applePay().linkToken()
                .accountID("bf498c07-3852-4060-b561-bf992e26a851")
                .linkApplePay(LinkApplePay.builder()
                    .token(LinkApplePayToken.builder()
                        .paymentData(LinkApplePaymentData.builder()
                            .version("EC_v1")
                            .data("3+f4oOTwPa6f1UZ6tG...CE=")
                            .signature("MIAGCSqGSIb3DQ.AAAA==")
                            .header(ApplePayHeader.builder()
                                .publicKeyHash("l0CnXdMv...D1I=")
                                .transactionId("32b...4f3")
                                .ephemeralPublicKey("MFkwEK...Md==")
                                .build())
                            .build())
                        .paymentMethod(LinkApplePaymentMethod.builder()
                            .displayName("Visa 1234")
                            .network("Visa")
                            .type("debit")
                            .build())
                        .transactionIdentifier("32b...4f3")
                        .build())
                    .billingContact(AppleBillingContact.builder()
                        .addressLines(List.of(
                            "123 Sesame Street"))
                        .locality("Phoenix")
                        .postalCode("30345")
                        .administrativeArea("AZ")
                        .countryCode("US")
                        .build())
                    .build())
                .call();

if (res.linkedApplePayPaymentMethods().isPresent()) {
            System.out.println(res.linkedApplePayPaymentMethods().get());
        }
    }
}
```

### Python Example

```python
from moovio_sdk import Moov
from moovio_sdk.models import components

with Moov(
    security=components.Security(
        username="",
        password="",
    ),
) as moov:

res = moov.apple_pay.link_token(account_id="bf498c07-3852-4060-b561-bf992e26a851", token={
        "payment_data": {
            "version": "EC_v1",
            "data": "3+f4oOTwPa6f1UZ6tG...CE=",
            "signature": "MIAGCSqGSIb3DQ.AAAA==",
            "header": {
                "ephemeral_public_key": "MFkwEK...Md==",
                "public_key_hash": "l0CnXdMv...D1I=",
                "transaction_id": "32b...4f3",
            },
        },
        "payment_method": {
            "display_name": "Visa 1234",
            "network": "Visa",
            "type": "debit",
        },
        "transaction_identifier": "32b...4f3",
    }, billing_contact={
        "address_lines": [
            "123 Sesame Street",
        ],
        "locality": "Phoenix",
        "postal_code": "30345",
        "administrative_area": "AZ",
        "country_code": "US",
    })

# Handle response
    print(res)
```

### Ruby Example

```ruby
require 'moov_ruby'

Models = ::Moov::Models
s = ::Moov::Client.new(
  security: Models::Components::Security.new(
    username: '',
    password: ''
  )
)
res = s.apple_pay.link_token(account_id: 'bf498c07-3852-4060-b561-bf992e26a851', link_apple_pay: Models::Components::LinkApplePay.new(
  token: Models::Components::LinkApplePayToken.new(
    payment_data: Models::Components::LinkApplePaymentData.new(
      version: 'EC_v1',
      data: '3+f4oOTwPa6f1UZ6tG...CE=',
      signature: 'MIAGCSqGSIb3DQ.AAAA==',
      header: Models::Components::ApplePayHeader.new(
        ephemeral_public_key: 'MFkwEK...Md==',
        public_key_hash: 'l0CnXdMv...D1I=',
        transaction_id: '32b...4f3'
      )
    ),
    payment_method: Models::Components::LinkApplePaymentMethod.new(
      display_name: 'Visa 1234',
      network: 'Visa',
      type: 'debit'
    ),
    transaction_identifier: '32b...4f3'
  ),
  billing_contact: Models::Components::AppleBillingContact.new(
    address_lines: [
      '123 Sesame Street',
    ],
    locality: 'Phoenix',
    postal_code: '30345',
    administrative_area: 'AZ',
    country_code: 'US'
  )
))

unless res.linked_apple_pay_payment_methods.nil?
  # handle response
end
```

### C# Example

```csharp
using Moov.Sdk;
using Moov.Sdk.Models.Components;
using System.Collections.Generic;

var sdk = new MoovClient(security: new Security() {
    Username = "",
    Password = "",
});

var res = await sdk.ApplePay.LinkTokenAsync(
    accountID: "bf498c07-3852-4060-b561-bf992e26a851",
    body: new LinkApplePay() {
        Token = new LinkApplePayToken() {
            PaymentData = new LinkApplePaymentData() {
                Version = "EC_v1",
                Data = "3+f4oOTwPa6f1UZ6tG...CE=",
                Signature = "MIAGCSqGSIb3DQ.AAAA==",
                Header = new ApplePayHeader() {
                    EphemeralPublicKey = "MFkwEK...Md==",
                    PublicKeyHash = "l0CnXdMv...D1I=",
                    TransactionId = "32b...4f3",
                },
            },
            PaymentMethod = new LinkApplePaymentMethod() {
                DisplayName = "Visa 1234",
                Network = "Visa",
                Type = "debit",
            },
            TransactionIdentifier = "32b...4f3",
        },
        BillingContact = new AppleBillingContact() {
            AddressLines = new List<string>() {
                "123 Sesame Street",
            },
            Locality = "Phoenix",
            PostalCode = "30345",
            AdministrativeArea = "AZ",
            CountryCode = "US",
        },
    }
);

// handle response
```

---

A unique identifier used to trace requests.

The server could not understand the request due to invalid syntax.

---

The request contained missing or expired authentication.

---

The user is not authorized to make the request.

---

The requested resource was not found.

---

The request conflicted with the current state of the target resource.

---

The request was well-formed, but the contents failed validation. Check the request for missing or invalid fields.

---

Request was refused due to rate limiting.

---

The request failed due to an unexpected error.

---

The request failed because a downstream service failed to respond.
