Search code examples
swiftswift3ios10applepayios10.2

Unable to present Apple Pay Authorization Controller


When I attempt to present a PKPaymentAuthorizationController with present(completion: _) it fails without any further information.

Here's how I'm presenting it:

let paymentSummaryItems: [PKPaymentSummaryItem] = <HIDDEN>

let paymentRequest = PKPaymentRequest()
paymentRequest.paymentSummaryItems = paymentSummaryItems
paymentRequest.merchantIdentifier = <HIDDEN>
paymentRequest.merchantCapabilities = .capability3DS
paymentRequest.countryCode = "US"
paymentRequest.currencyCode = "USD"
paymentRequest.supportedNetworks = [.visa, .amex, .masterCard, .discover]
paymentRequest.requiredShippingAddressFields = [.email]

let paymentController = PKPaymentAuthorizationController(paymentRequest: paymentRequest)
paymentController.delegate = self

paymentController.present { success in
    if success {
      print("Presented payment controller")
    } else {
      print("Failed to present payment controller")
    }
}

Every time I try, I get the message "Failed to present payment controller", and no Apple Pay Authorization modal appears.

I added a PKPaymentAuthorizationController.canMakePayments() check, and that returns true. I'm not sure what could be going wrong. The same code (with a different merchantIdentifier) works in my other Apple Pay projects with no problems.


Solution

  • I figured it out, for anybody who encounters this issue in the future.

    It turns out there was a problem with one of the NSDecimalNumbers in my array of PKPaymentSummaryItems, it didn't properly convert to a decimal and resulted in amount being set to NaN. Once I fixed it, the controller appeared properly.