Payment-method icon

Decrypt Apple Pay tokens

Learn how to decrypt Apple Pay tokens.

An Apple Pay token contains encrypted data of a transaction performed with Apple Pay. Apple Pay tokens enable you to securely pass the data of your shoppers to a payment service provider, like Adyen.

Choose a decryption method

If you are PCI-compliant you have a choice of letting Adyen handle the token decryption, or handling it on your own.

Only handle the token decryption on your own in advanced setup scenarios, like when you have to submit Merchant Plug-In (MPI) data in an Apple Pay request.

A benefit of handling the decryption on your own is that the auditing of transactions becomes easier with the availability of transaction data like shopper names.

If you are not PCI-compliant you must let Adyen handle the decryption.

Let Adyen handle the decryption

In-app

After initiating the Apple Pay payment on your mobile application, you receive a callback that includes a PKPayment. This includes paymentData, a stringified version of the payment token. You need to submit this data in your payment request to Adyen.

  1. Stringify the paymentData from the token

    When the request is completed, you receive a PKPayment which contains paymentData. Apple Pay returns more data than we need for authorization, for example a shipping address, but only the paymentData is necessary for authorization.

    Convert the paymentData to a String:

    func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
    let token = payment.token.paymentData.base64EncodedString()
    }
  2. Submit the API request

    Include the encoded token from step 1 as the value of applePayToken in the paymentMethod object of your /payments request: