Our iOS Drop-in renders Apple Pay in your payment form. When the shopper selects Apple Pay, Drop-in invokes the payment sheet, where shoppers select the card they want to use, provide contact details and shipping address, and then authenticate the payment through Face ID or Touch ID.
Before you begin
This page explains how to add Apple Pay to your existing iOS Drop-in integration. The iOS Drop-in integration works the same way for all payment methods. If you haven't done this integration yet, refer to our Drop-in integration guide.
Before starting your Apple Pay integration, you need to:
- Make sure that you have set up your back end implementation, and added Drop-in to your payment form.
- Add Apple Pay in your test Customer Area.
- Enable Apple Pay.
Show Apple Pay in your payment form
After you have finished enabling Apple Pay, you can show Apple Pay in your payment form:
-
Drop-in uses the
countryCode
and theamount.currency
from your /paymentMethods request to show the available payment methods to your shopper. From your server, make a /paymentMethods request specifying:- countryCode: Country where Apple Pay is supported. For example, NL.
- amount.currency: Any supported currency. For example, EUR.
-
When creating an instance of Drop-in, include the required configuration for Apple Pay.
// Import this to use the PKPaymentSummaryItem class // See documentation https://developer.apple.com/documentation/passkit/pkpaymentsummaryitem import PassKit // Submit the payment details here, including the amount, currency, and country code let payment = Payment(amount: Payment.Amount(value: 15445, currencyCode: "EUR"), countryCode: "NL") let configuration = DropInComponent.PaymentMethodsConfiguration() // Your Apple merchant identifier // See Apple Pay documentation https://developer.apple.com/documentation/apple_pay_on_the_web/applepayrequest/2951611-merchantidentifier configuration.applePay.merchantIdentifier = "adyen.test.merchant" // A set of line items that explain recurring payments, additional charges, and discounts. // See Apple Pay documentation for sample values. https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentrequest/1916120-lineitems configuration.applePay.summaryItems = [ PKPaymentSummaryItem(label: "Jeans", amount: NSDecimalNumber(string: "98.99"), type: .final), PKPaymentSummaryItem(label: "Bag", amount: NSDecimalNumber(string: "55.46"), type: .final) ] // To initiliaze Apple Pay in Drop-in, include the payment class let dropInComponent = DropInComponent(paymentMethods: paymentMethods, paymentMethodsConfiguration: configuration) dropInComponent.payment = payment dropInComponent.delegate = self dropInComponent.environment = .test present(dropInComponent.viewController, animated: true)
For more information on iOS Drop-in classes, see our reference documentation page.
Make a payment
When the shopper proceeds to pay, Drop-in invokes the didSubmit
method which contains data.paymentMethod
. On the app, Apple Pay shows a loading page and waits to be informed when the payment has been completed.
- Pass
data.paymentMethod
to your server. -
From your server, make a /payments request, specifying:
paymentMethod
: Thedata.paymentMethod
from thedidSubmit
event from your client app.
curl https://checkout-test.adyen.com/v66/payments \ -H "x-API-key: YOUR_X-API-KEY" \ -H "content-type: application/json" \ -d '{ "merchantAccount":"YOUR_MERCHANT_ACCOUNT", "reference":"YOUR_ORDER_NUMBER", "amount":{ "currency":"EUR", "value":1000 }, "{hint:data.paymentMethod from didSubmit}paymentMethod{/hint}":{ "type":"applepay", "applePayToken": "QWIwMmI0YzAhQlFBQkFnQjMv.." } }'
# Set your X-API-KEY with the API key from the Customer Area. adyen = Adyen::Client.new adyen.api_key = "YOUR_X-API-KEY" response = adyen.checkout.payments({ :amount => { :currency => "EUR", :value => 1000 }, :reference => "YOUR_ORDER_NUMBER", :paymentMethod => { :type => "applepay", :applePayToken => "QWIwMmI0YzAhQlFBQkFnQjMv.." }, :merchantAccount => "YOUR_MERCHANT_ACCOUNT" })
// Set YOUR_X-API-KEY with the API key from the Customer Area. // Change to Environment.LIVE and add the Live URL prefix when you're ready to accept live payments. Client client = new Client("YOUR_X-API-KEY", Environment.TEST); Checkout checkout = new Checkout(client); PaymentsRequest paymentsRequest = new PaymentsRequest(); String merchantAccount = "YOUR_MERCHANT_ACCOUNT"; paymentsRequest.setMerchantAccount(merchantAccount); Amount amount = new Amount(); amount.setCurrency("EUR"); amount.setValue(15000L); paymentsRequest.setAmount(amount); ApplePayDetails applePayDetails = new ApplePayDetails(); applePayDetails.setApplePayToken(state.data.paymentMethod.applePayToken); paymentsRequest.setPaymentMethod(applePayDetails); paymentsRequest.setReference("YOUR_ORDER_NUMBER"); PaymentsResponse paymentsResponse = checkout.payments(paymentsRequest);
// Set your X-API-KEY with the API key from the Customer Area. $client = new \Adyen\Client(); $client->setXApiKey("YOUR_X-API-KEY"); $service = new \Adyen\Service\Checkout($client); $params = array( "amount" => array( "currency" => "EUR", "value" => 1000 ), "reference" => "YOUR_ORDER_NUMBER", "paymentMethod" => array( "type" => "applepay", "applePayToken" => "QWIwMmI0YzAhQlFBQkFnQjMv.." ), "merchantAccount" => "YOUR_MERCHANT_ACCOUNT" ); $result = $service->payments($params);
#Set your X-API-KEY with the API key from the Customer Area. adyen = Adyen.Adyen() adyen.client.xapikey = 'YOUR_X-API-KEY' result = adyen.checkout.payments({ 'amount': { 'value': 1000, 'currency': 'EUR' }, 'reference': 'YOUR_ORDER_NUMBER', 'paymentMethod': { 'type': 'applepay', 'applePayToken': 'QWIwMmI0YzAhQlFBQkFnQjMv..' }, 'merchantAccount': 'YOUR_MERCHANT_ACCOUNT' })
// Set your X-API-KEY with the API key from the Customer Area. var client = new Client ("YOUR_X-API-KEY", Environment.Test); var checkout = new Checkout(client); var amount = new Model.Checkout.Amount("EUR", 1000); var details = new Model.Checkout.DefaultPaymentMethodDetails{ Type = "applepay", ApplePayToken = "QWIwMmI0YzAhQlFBQkFnQjMv.." }; var paymentRequest = new Adyen.Model.Checkout.PaymentRequest { Reference = "YOUR_ORDER_NUMBER", Amount = amount, MerchantAccount = "YOUR_MERCHANT_ACCOUNT", PaymentMethod = details }; var paymentResponse = checkout.Payments(paymentsRequest);
// Set your X-API-KEY with the API key from the Customer Area. const {Client, Config, CheckoutAPI} = require('@adyen/api-library'); const config = new Config(); // Set your X-API-KEY with the API key from the Customer Area. config.apiKey = '[API_KEY]'; config.merchantAccount = '[YOUR_MERCHANT_ACCOUNT]'; const client = new Client({ config }); client.setEnvironment("TEST"); const checkout = new CheckoutAPI(client); checkout.payments({ amount: { currency: "EUR", value: 1000 }, paymentMethod: { type: 'applepay', applePayToken: 'QWIwMmI0YzAhQlFBQkFnQjMv..' }, reference: "YOUR_ORDER_NUMBER", merchantAccount: config.merchantAccount }).then(res => res);
The response contains the result of the payment.
Present the payment result
Get the payment result from the resultCode
that you receive in the /payments response. Because Apple Pay shows a loading page on the app, you need to call the stopLoading
class to inform Apple Pay that the payment has been completed, and of the payment result.
-
Determine the result from the
resultCode
.The
resultCode
values you can receive for Apple Pay are:resultCode Description Action to take Authorised The payment was successful. Call stopLoading(withSuccess: true)
.Refused The payment was refused by the shopper's bank. Call stopLoading(withSuccess: false)
.
Ask the shopper to try the payment again using a different payment method. -
Call the
stopLoading
class and pass the payment result.// Set to true if the payment was successful dropInComponent.stopLoading(withSuccess: true)
Depending on the values you pass, Apple Pay shows the following on the app:
- true: Apple Pay informs the shopper that the payment was successful.
- false: Apple Pay informs the shopper that the payment failed.
- Dismiss the Drop-in's
viewController
.
Recurring payments
To make recurring Apple Pay payments, you first need to create a shopper token and then make subsequent recurring transactions with the token.
Refer to Tokenization for more information and detailed instructions.
Test and go live
Use Apple's test card numbers to test your integration.
Card Type | Card number | Expiry date | CVC/CID |
---|---|---|---|
Discover | 6011 0009 9446 2780 | 11/2022 | 111 |
Mastercard | 5204 2477 5000 1471 | 11/2022 | 111 |
Visa | 4761 1200 1000 0492 | 11/2022 | 533 |
For a full list of test cards and instructions how to add these to your test device, see Sandbox testing on Apple's Developer website.
Check the status of an Apple Pay test payment in your Customer Area > Transactions > Payments.
To process live Apple Pay payments, your API credential needs to have the API Clientside Encryption Payments role. You can check this in your live Customer Area or ask your Admin user to verify.