Payment-method icon

Apple Pay Component

Add Apple Pay to an existing iOS Components integration.

This page explains how to add Apple Pay to your existing iOS Components integration.

If you are selling digital goods in your native iOS app, use Apple's in-app purchase instead of Apple Pay.

Requirements

Select which endpoint you are using:

Requirement Description
Integration type Make sure that you have built a Sessions flow iOS Components integration.
API credential roles To process live Apple Pay payments make sure that you have the following role:
  • API Clientside Encryption Payments role.
Setup steps Before you begin, make sure that you have:

API reference

You do not need to send additional fields for Apple Pay. To see optional fields that you can send for all payment methods, choose the endpoint you integrated:

If you run into an error, refer to Handle Apple Pay errors.

Component configuration

Configure and create an instance of the Apple Pay Component. Include the following when you configure the Component:

Parameter name Description
paymentRequest Your Apple Pay PKPaymentRequest object.
merchantIdentifier Your Apple Pay merchant identifier.
Create the configuration object
Expand view
Copy link to code block
Copy code
Copy code
let paymentMethods = session.sessionContext.paymentMethods
do {
guard let paymentMethod = paymentMethods.paymentMethod(ofType: ApplePayPaymentMethod.self) else {
throw // Exception if Apple Pay is not configured in the Customer Area.
}
let paymentRequest: PKPaymentRequest
// Initiate PKPaymentRequest
var config = try ApplePayComponent.Configuration(paymentRequest: paymentRequest)
let component = try ApplePayComponent(paymentMethod: paymentMethod,
context: context,
configuration: config)
component.delegate = session
} catch {
// An error occurs.
}

Optional configuration

If your integration uses iOS Components v5.0.0 or later, you can optionally include the following when you configure the Component:

Parameter name Description
requiredBillingContactFields Billing information fields that you require from the shopper to fulfill the order. Refer to Apple Pay documentation for sample values.
requiredShippingContactFields Shipping information fields that you require from the shopper to fulfill the order. Refer to Apple Pay documentation for sample values.
billingContact A prefilled billing address.
shippingContact A prefilled shipping address.
allowOnboarding Set to true to let the shopper add new cards to their Apple Pay wallet if there are none or if their cards are not supported for the payment.
By default this is set to false, and Apple Pay isn't shown as an available payment method if there are no cards in their Apple Pay wallet.
shippingType The type of shipping displayed, for example Pick Up, Ship To, or Deliver To. This is localized.
Default: PKShippingTypeShipping = .shipping.
allowShippingContact Set to false to prevent the shopper from changing the shipping contact field before showing the payment form.
Default: true.
shippingMethods An array of supported shipping methods.
applicationData Additional information that you provide about the payment request. For example, an order number or cart identifier.
This is signed and included in the resulting PKPaymentToken.
supportedCountries Only allow payments from cards issued in specific countries. This is a list of ISO 3166 country codes.
supportsCouponCode Set to true to let the shopper enter a coupon code which gets validated.
Default: false.
couponCode A coupon code that has already been applied to the payment request.
PKRecurringPaymentRequest Required for recurring payments. Include PKRecurringPaymentRequest to specify that the payment is a recurring payment.

Recurring payments

To enable recurring payments, you must include PKRecurringPaymentRequest when configuring Apple Pay.

To make recurring Apple Pay payments, you have to create a shopper token and then make subsequent recurring transactions with the token.

Test and go live

Use Apple's test card numbers to test your integration.

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.

Going live

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.

Set up Apple Pay on your Apple Pay Developer account for your live merchant identifier.

See also