[SOLVED] Device selection on Apple Pay In-App provisioning

Issue

I work in a fintech company that offers support to Apple Pay in our cards, i.e. our users have the option add their cards to Apple Pay using our app (in-app provisioning). Our company already got the proper In-App provisioning entitlements from Apple and the entire in-app provisioning process is working as expected.

When an user taps on the button "Add to Apple Wallet" in our app to provision his card, we call the following code below:

let config = PKAddPaymentPassRequestConfiguration()
config.cardholderName = "\(firstName) \(lastName)"
config.localizedDescription = "MyApp Card"
config.primaryAccountSuffix = String(cardSuffix)
config.paymentNetwork = .visa

// Present the Apple Pay ViewController
let controller = PKAddPaymentPassViewController(requestConfiguration: config, delegate: self)
UIApplication.shared.delegate?.window??.rootViewController?.present(controller!, animated: true)

If the user has an Apple Watch paired, he is greeted with a screen asking him to select on which device he wants to add the card: on his iPhone or on the Apple Watch (please see the screenshot attached). After the user selects the device, the provisioning process continues successfully as expected.

However, if the user taps on the "Add to Apple Wallet" button and he already has the card added to one of the devices (the Apple Watch, for example), then the code above is called again, but he is once again greeted with the same screen asking him to select on which devices he wants to add the card, on his iPhone or on his Apple Watch, even though the card is already added on the Apple Watch.

The way I understand it, since the card is already added on the Apple Watch, only iPhone should appear as a valid option to have the card added.

Is there anything else that I need to do in the code above to make sure only the available devices (I mean, only the devices that don’t have the card added on Apple Pay yet) are listed in the device selection?

Solution

I found the answer to this so I’m answering my own question:

After you create the PKAddPaymentPassRequestConfiguration object you need to set the field primaryAccountIdentifier with an unique identifier for the customer’s bank account (you will probably get this information from the bank).

If you look at the code that I posted in my question, you will notice that I set many fields in the PKAddPaymentPassRequestConfiguration object, but not the primaryAccountIdentifier. That’s why it was not working for me.

Here is the correct code, with the primaryAccountIdentifier added in the end:

let config = PKAddPaymentPassRequestConfiguration()
config.cardholderName = "\(firstName) \(lastName)"
config.localizedDescription = "MyApp Card"
config.primaryAccountSuffix = String(cardSuffix)
config.paymentNetwork = .visa
config.primaryAccountIdentifier = "some unique identifier"

With this update after you add a device to Apple Pay, it will no longer appear as a provision option when you want to add a second device with the same account.

Answered By – vegidio

Answer Checked By – Pedro (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.