Set up Apple Pay payments

DOCS

Last updated: Aug 15th, 7:09am

Complete the steps to check out using Apple Pay.

Know before you code

Apple Pay has specific user experience and identity guidelines, which Apple might enforce during the App Store review process. Read these guidelines as well as Apple's developer information when designing your Apple Pay payment flow.

Step 1: Set up Apple Pay certificate and merchant ID

To use Apple Pay on a mobile device, you must configure an Apple Pay merchant ID and an Apple Pay certificate in Apple's Developer Center. Follow the Apple Pay Programming Guide to learn how to create a merchant ID and a Payment Processing certificate.

Step 2: Display the Apple Pay button

Before presenting the Apple Pay option to the buyer, determine whether Apple Pay is available. If so, present a PKPaymentButton.

    1// Conditionally show Apple Pay button based on device availability
    2if (PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [.visa, .masterCard])) {
    3 let applePayButton = PKPaymentButton(paymentButtonType: .buy, paymentButtonStyle: .whiteOutline)
    4 applePayButton.addTarget(self, action: #selector(applePayCheckoutTapped(_:)), for: .touchUpInside)
    5 self.view.addSubview(button)
    6}

    Step 3: Create a PKPaymentRequest

    Before you can start a user-facing Apple Pay experience, initialize a payment request:

      1func setupPaymentRequest() -> PKPaymentRequest {
      2 let paymentRequest = PKPaymentRequest()
      3 // We recommend collecting billing address information, at minimum
      4 // billing postal code, and passing that billing postal code with all
      5 // Apple Pay transactions as a best practice.
      6 paymentRequest.requiredBillingContactFields = [.postalAddress]
      7
      8 // Set other PKPaymentRequest properties here
      9 paymentRequest.merchantCapabilities = .capability3DS
      10 paymentRequest.paymentSummaryItems = [
      11 PKPaymentSummaryItem(label: "Subtotal", amount: NSDecimalNumber(string: "12.75")),
      12 PKPaymentSummaryItem(label: "Discount", amount: NSDecimalNumber(string: "-2.00")),
      13 // Last entry should be the total amount to be charged:
      14 PKPaymentSummaryItem(label: "&ltYour Company Name&gt", amount: NSDecimalNumber(string: "10.75"))
      15 ]
      16
      17 return paymentRequest
      18}

      Construct a PKPaymentRequest.

      • paymentSummaryItems: Make sure the total amount for this required value does not exceed the amount that you authorized or submitted for settlement.
      • supportedNetworks: This SDK supports only Visa and MasterCard networks.
      • requiredBillingContactFields: Include PKContactFieldPostalAddress.

      If you don't set the following properties on your PKPaymentRequest, the SDK populates them with default values based on your merchant account setup:

      • currencyCode
      • countryCode
      • merchantCapabilities
      • merchantIdentifier

      Step 4: Check out with Apple Pay

      Use the PYPLClient to call checkoutWithApplePay with a valid PayPal orderID. The SDK notifies your app when the Apple Pay checkout UI is ready to be presented and dismissed using the BTViewControllerPresentingDelegate protocol.

      Call the applePayResultHandler with a boolean to indicate the success or failure of your payment authorization or capture. This is so the SDK can notify the user of the payment's status.

        1func tappedApplePay() {
        2 // Create a PKPaymentRequest
        3 let paymentRequest = setupPaymentRequest()
        4
        5 // Call checkoutWithApplePay
        6 client?.checkoutWithApplePay("orderID", paymentRequest: paymentRequest) { (result, error, applePayResultHandler) in
        7 guard let result = result else {
        8 // handle error
        9 applePayResultHandler(false)
        10 return
        11 }
        12
        13 // Send orderID to your server to process the payment
        14 // Capture or authorize the orderID
        15
        16 applePayResultHandler(true)
        17 }
        18}

        Next step

        Process the order