1
votes

I am facing a problem in initilizing PKPaymentAuthorizationViewController returning nil in one of the device.

The device region is set to UK and I have added a UK issued card in the Apple Wallet.

The PKPaymentRequest is configured as following:

                let request = PKPaymentRequest()

                request.merchantIdentifier = "mymerchantid"
                request.supportedNetworks = [PKPaymentNetworkVisa, PKPaymentNetworkMasterCard, PKPaymentNetworkAmex]
                request.merchantCapabilities = PKMerchantCapability.Capability3DS
                request.countryCode = "US"
                request.currencyCode = "USD"

                let price: <NSDecimalNumber>

               let item : PKPaymentSummaryItem = PKPaymentSummaryItem(label: "amount", amount: price, type: .Pending)
                request.paymentSummaryItems = [
                        item
                    ]
           let paymentAuthorizationVC = PKPaymentAuthorizationViewController(paymentRequest: request) // Returning Nil

           if PKPaymentAuthorizationViewController.canMakePaymentsUsingNetworks(SupportedPaymentNetworks) // Returns true

Device: iPhone 6 OS: 10.2.2

Note: Same Card is onboared in another device for the same App its working fine.

Tried as mentioned in the below link and few other blogs- no luck Apple pay PKPaymentauthorizationViewController always returning nil when loaded with Payment request

Looking for suggestions.

1

1 Answers

2
votes

I had this same problem and the cause was using a Discover card for testing when it's not included as a supported payment network. Make sure that you are passing in all the credit card types that your user base will possibly use.

Try changing this line:

request.supportedNetworks = [PKPaymentNetworkVisa, PKPaymentNetworkMasterCard, PKPaymentNetworkAmex]

To the following:

request.supportedNetworks = [PKPaymentNetworkVisa, PKPaymentNetworkMasterCard, PKPaymentNetworkAmex, PKPaymentNetwork.discover]

In Swift3, The declaration for PKPaymentAuthorizationViewController init() is not defined as optional, even though it does return nil when it fails.