How to check if Payment Pass already exists in Wallet

Hi!



I am working for a Financial Institution. We would like to give our customers the ability to add one of our credit or debit to their iOS device wallet, but only if the card has not been added to the device yet.



We have obtained the necessary entitlement fromApple, and I have reviewed the documentation that describes how to provision a credit or debit card for Apple Pay.


To start, we actually just want to add the "Add To Wallet" button next to our cards inside the mobile app. For that we, of course, want to check if the card was already added. The intention is to launch the Wallet via PKPassLibrary.OpenPaymentSetup() after that - no automatic adding of cards for now.



From the documentation provided to us by Apple, it seems obvious that I can invoke the following API call:

-[PKPassLibrary canAddPaymentPassWithPrimaryAccountIdentifier:]



Question 1: Can this be tested with one of Apple's sandbox card (provided here: https://developer.apple.com/apple-pay/sandbox-testing/) What I am essentially asking: can I add a sandbox card to the wallet for ApplePay and then get a "false" from the canAddPaymentPassWithPrimaryAccountIdentifier call for that sandbox card (since it was already added)?



Question 2: Is there a simple way to retrieve all current PKPaymentPasses for the device, or do I need to implement the entire process that generates the payload to instantiate a PKPaymentPass as in what I would need for the PKAddPaymentPassRequest call? I assume there is no shortcut to query the API for an already added card by PAN?



Question 3: Reading more about this topic, I found that I could potentially also use PKPassLibrary.containsPass(pass: PKPass). Again, I would have to pass an instance of PKPass. I assume that I can only do that with the fully generated payload as outlined in the documentation for the PKAddPaymentPassRequest call - is that correct?





I appreciate any help anybody can provide on this subject.

Replies

Hi,


Did you manage to test in-app provisioning with the provided Apple's sandbox card?

You can access all passes from the library with PXPassLibrary().passes()
Then you can check in this list if you already have the pass for your properties
exemple with primaryAccountId

Code Block let allPasses = walletPassLibrary?.passes()
    currentWalletPass = allPasses?.first(where: { (onePass) -> Bool in
      if let passPrimaryAccountId = onePass.paymentPass?.primaryAccountIdentifier, passPrimaryAccountId == "one account id"
      {
        return true
      }
      else
      {
        return false
      }
    })


you can also check wether the pass is on the iPhone or on a remote device (like a watch)


From what I understand the passes method returns the list of passes that have already been added to the wallet of the device.

Similarly, the remoteSecureElementPasses method returns the list of passes that have already been added to a paired Apple Watch.

Given a pass identifier I want to show the "Add to Apple Wallet" button if either of the following is true:

  1. The pass is not present in the current device's passes (passes).
  2. There is a paired Apple Watch AND the pass is not present in the Apple Watch passes (remoteSecureElementPasses).

The problem arises on point 2. Since remoteSecureElementPasses returns an empty list if the pass has not been added to the Apple Watch yet OR if there is no paired Apple Watch, I can't decide wether to show the button or not:

  • If pass has not been added, I should show the button
  • If there is not paired Apple Watch, I should hide the button

How can I tell these two cases apart?

  • @zucca I have the same issue/question, did you manage to solve this?

  • You can use a Watch Connectivity session to find out if the device has a paired Apple Watch, only then check its remote passes. Otherwise just check the devices passes.

Add a Comment

Hello, Does anyone have a solution for a web application for the same problem?

I was using canAddSecureElementPass(primaryAccountIdentifier:) to determine whether a connected device existed and if it could add a pass and it was working great until recently. I displayed the Add card to Apple Wallet button if there were no passes or if the canAddSecureElementPass(primaryAccountIdentifier:) function returned true. Now the function has started to return false if a pass has been added to the phone even if there is a watch paired and there is no pass in the watch.

Any info on why this function isn't working is really appreciated. I'm implementing a solution which uses Watch Connectivity to check if a Watch is paired and then checking the remote passes as mentioned here above since the simple useful function stopped working :(

Documentation for the function https://developer.apple.com/documentation/passkit/pkpasslibrary/3543354-canaddsecureelementpass?changes=lat__5_8_8_8.

Add a Comment