> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dintero.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tokenization and MIT

> Create a token from Apple Pay, retrieve it from the transaction, and charge it later as a merchant initiated transaction.

Apple Pay tokenizes the customer's underlying card. When you tokenize an Apple Pay payment
through Dintero the same tokenization flow that applies to card payments applies here. See
[Card tokenization overview](https://docs.dintero.com/docs/checkout/tokenization.md) for background on token types.

The apple pay token can be charged using an *unscheduled payment*, *recurrence* and *CIT* payments
are not supported.

> [!NOTE]
>
> Tokenization with Apple Pay is supported only via `dintero_psp.applepay`. If you are using Worldline (`bambora.applepay` in the API) [contact support](https://dintero.com/contact-us) for help changing your gateway.

## Create a token without a payment

To store a token without withdrawing any money, call [Payment token session][payment token session]
with `token_provider.payment_product_type` set to `dintero_psp.applepay`.

**Request**

```json highlight={17-20} theme={null}
{
  "session": {
    "order": {
      "currency": "NOK",
      "merchant_reference": "order-number"
    },
    "url": {
      "return_url": "https://example.com/accept",
      "callback_url": "https://example.com/callback?method=GET",
      "merchant_terms_url": "https://example.com/terms.html"
    },
    "customer": {
      "email": "john.doe@example.com",
      "phone_number": "+4799999999"
    }
  },
  "token_provider": {
    "payment_product_type": "dintero_psp.applepay",
    "token_types": ["payment_token"]
  }
}
```

**Response**

```json theme={null}
{
  "id": "T11223445.5cyWnV68vzJ1kYjZPrKWWm",
  "url": "https://checkout.test.dintero.com/v1/view/T11223445.5cyWnV68vzJ1kYjZPrKWWm"
}
```

Redirect the customer to the `url` to confirm the card with Apple Pay.

## Create a token while taking payment

For a session that also has an amount to pay, set `generate_payment_token` to `true` under
`configuration.dintero_psp.applepay`. The customer pays with Apple Pay as normal, and a
payment token is created from the same authorization.

**Request**

```json highlight={30} theme={null}
{
  "url": {
    "return_url": "https://example.com/accept",
    "callback_url": "https://example.com/callback?method=GET"
  },
  "customer": {
    "email": "john.doe@example.com",
    "phone_number": "+4799999999"
  },
  "order": {
    "amount": 29990,
    "currency": "NOK",
    "vat_amount": 6000,
    "items": [
      {
        "line_id": "1",
        "description": "Stablestol",
        "quantity": 1,
        "amount": 29990,
        "vat_amount": 6000,
        "vat": 25
      }
    ],
    "merchant_reference": "order-1"
  },
  "configuration": {
    "dintero_psp": {
      "applepay": {
        "enabled": true,
        "generate_payment_token": true
      }
    }
  },
  "profile_id": "default"
}
```

See [create session] for the full session schema.

> [!NOTE]
>
> Apple Pay does not support the `generate_payment_token_config` option with a
> `save_card_checkbox`, which is available for
> [`dintero_psp.creditcard`](https://docs.dintero.com/docs/checkout/tokenization-create-token#save-card-checkbox-dintero_psp-creditcard).
> When `generate_payment_token` is `true` for Apple Pay, the card is always tokenized.

## Retrieve the payment token

When the payment completes, the token is stored on the transaction. Call
[get transaction details] with the `includes` query parameter to have the token returned:

```
?includes=card.payment_token
```

The token is then available as `card.payment_token` in the response.

For token status, expiry dates, and how to store the token securely, see
[Fetch and store payment tokens](https://docs.dintero.com/docs/checkout/tokenization-fetching-storing.md).

## Charge the token as an unscheduled MIT

To charge the stored token without involving the customer, use the `unscheduled_purchase`
operation with [Create and pay merchant initiated session][post session pay].

**Request**

```json highlight={9-13, 35-38} theme={null}
{
  "session": {
    "url": {
      "callback_url": "https://example.com/callback?method=GET"
    },
    "customer": {
      "email": "john.doe@example.com",
      "phone_number": "+4799999999",
      "tokens": {
        "dintero_psp.applepay": {
          "payment_token": "<token previously acquired>"
        }
      }
    },
    "order": {
      "amount": 29990,
      "currency": "NOK",
      "vat_amount": 6000,
      "items": [
        {
          "line_id": "1",
          "description": "Stablestol",
          "quantity": 1,
          "amount": 29990,
          "vat_amount": 6000,
          "vat": 25
        }
      ],
      "merchant_reference": "order-1"
    },
    "configuration": {
      "auto_capture": false
    }
  },
  "payment": {
    "payment_product_type": "dintero_psp.applepay",
    "operation": "unscheduled_purchase"
  }
}
```

Before you retry a failed merchant initiated transaction, read
[Tokenization error handling](https://docs.dintero.com/docs/checkout/tokenization-error-handling.md) for the retry
limits enforced by Visa and Mastercard and for how to prevent duplicate transactions.

## Manage stored tokens

Use the card token endpoints to inspect and remove tokens you have stored:

* [List card tokens](https://docs.dintero.com/api-reference/card-tokens/card_tokens_get.md)
* [Get card token](https://docs.dintero.com/api-reference/card-tokens/card_tokens_token_id_get.md)
* [Delete card token](https://docs.dintero.com/api-reference/card-tokens/card_tokens_token_id_delete.md)

## Tokenization life cycle

Apple Pay can provision two different token forms. Currently Dintero only provides DPAN tokens.

* **DPAN** (*Device Primary Account Number*): a device-specific token tied to a particular device.
  Will expire when the user replaces their device or the card expires.
* **MPAN** (*Merchant Primary Account Number*): a merchant-specific token intended for recurring or
  card-on-file usage with the same merchant. Continues to work when user replace their device or
  the physical card expires.

## Tokenized cards in the Apple Wallet app

### Card tokens

If the customer opens their *Wallet* app, click on their card and open the
"Card details" and select the "Pre-Autorised Payments" section they can see
their **MPAN** payment tokens. Since Dintero only provides **DPAN** tokens,
they are not listed in the end customers app.

> [!NOTE]
>
> Not all issuers support showing and revoking tokens in the "Pre-Autorised Payments" section,
> it only works in cases where the provisioned card token is an **MPAN**. Currently Dintero only
> provides **DPAN** tokens.

### Unscheduled payments

Unscheduled payments where the token is used are not shown to the customer in the "Latest
Transactions" history in the *Wallet* app.

[create session]: https://docs.dintero.com/api-reference/session/checkout_session_profile_post.md

[payment token session]: https://docs.dintero.com/api-reference/session/checkout_payment_token_session_post.md

[get transaction details]: https://docs.dintero.com/api-reference/transactions/transactions_id_get.md

[post session pay]: https://docs.dintero.com/api-reference/payment/checkout_session_pay_post.md


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.