After initiating the Apple Pay payment on your website or mobile application, you should receive a token in the onPaymentAuthorized event.
Retrieve the paymentData
from the token and convert it to a string. Pass this to your server, and then submit it in an /payments
request to Adyen.
Step 1: Stringify the paymentData from the token
Apple Pay returns more data than we need for authorisation, for example a shipping address, but only the PaymentData
is necessary for authorisation. Take this data from the token and convert the JSON to a String and base64 encoded:
session.onpaymentauthorized = function(event) {
var token = btoa(JSON.stringify(event.payment.token.paymentData));
};
Step 2: Submit the API request
Submit the token
from the previous step in your payments request. Specify applePayToken
in your /payments request.
{
"amount": {
"currency": "USD",
"value": 1000
},
"reference": "Your order number",
"paymentMethod": {
"type": "applepay",
"applePayToken": "{hint:token from step 1}VNRWtuNlNEWkRCSm1xWndjMDFFbktkQU...{/hint}"
},
"returnUrl": "https://your-company.com/...",
"merchantAccount": "YOUR_MERCHANT_ACCOUNT"
}