Skip to content

Apple Pay

Josh Monroe edited this page Apr 27, 2018 · 3 revisions

Apple Pay

As an alternative to collecting payment card details using fields, your app may also use Apple Pay to collect card details.

Configuring Apple Pay

To accept payments with Apple Pay, you must first configure your app for Apple Pay.
For more information see Configuring Your Environment in Apple's developer documentation.

When creating an Apple Pay Payment Processing Certificate be sure to use the certificate signing request (CSR) provided to you by the Gateway.

Displaying the Apple Pay Button

Apple provides the PKPaymentButton that you may use on your app's payment screens.

To determine if the device supports Apple Pay, use the canMakePayments method on PKPaymentAuthorizationController.

Constructing and using a PKPaymentRequest

For comprehensive information on how to construct and use a PKPaymentRequest see Creating Payment Requests in Apple's developer documentation.

Updating a Session with a PKPaymentToken

After the user has authorized Apple Pay, your app needs to update the Gateway session with that payment token.

To send the payment token to the gateway, you must first get the payment token as a String.

let tokenString = String(data: payment.token.paymentData, encoding.utf8)

Now, you can populate that token string into the GatewayMap as the devicePayment and specify that the token came from Apple Pay by setting the walletProvider.

var request = GatewayMap()
request[at: "sourceOfFunds.provided.card.devicePayment.paymentToken"] = tokenString
request[at: "order.walletProvider"] = "APPLE_PAY"

The GatewayMap for your request can now be sent to the Gateway using the updateSession method on the Gateway object.

gateway.updateSession("<#session id#>", apiVersion: <#Gateway API Version#>, payload: request) { (result) in
  switch result {
  case .success(let response):
    print(response.description)
  case .error(let error):
    print(error)
  }
}

Completing an Apple Pay Transaction

Once a session has been updated with the payment token from Apple Pay, the payment can be completed from your merchant service just as any other payment is completed. However, the order.walletProvider field must be set to "APPLE_PAY" when completing a payment on a session that is using Apple Pay.

Clone this wiki locally