1
votes

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.

3

3 Answers

2
votes

If you have a typo at any of the properties of PKPaymentRequest object, that will cause this behaviour. Please double check that following properties are correct:

  • merchantID should match your merchantID in Capabilities.
  • currencyCode should be three-letter ISO 4217 currency code.
  • countryCode should be two-letter ISO 3166 country code.
  • decimalNumbers in paymentSummaryItems

In my case, I was trying to just test the feature with hardcoded merchantID and it turned out it was misspelled. In that case PKPaymentRequest and PKPaymentAuthorizationController (or PKPaymentAuthorizationViewController) will be initialised successfully but when you present controller, it simply wouldn't show up.

0
votes

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.

0
votes

I fixed it using following steps: 1 of which could be correct answer.

  • In App target capabilities, enable Apple wallet and Apple pay
  • Include correct merchant id, in the Apple pay list
  • Change the merchant id in entitlements
  • If any errors in provisining, enable "Automatically manage signing" provisioning profile (uncheck/check if reqd.)

App target capabilities screenshot