5

I work for a bank and I am working on a project that programmatically add a user’s credit/bank card to their apple wallet. The card has been issued by our bank.

Our app already has the entitlement com.apple.developer.payment-pass-provisioning. I am able to populate the config and call PKAddPaymentPassViewController. The modal loads correctly and once the user clicks next I get a response with the certificates, nonce, and nonceSignature.

I am now trying to call the PKAddPaymentPassRequest which requires the fields activationData, encryptedPassData, wrappedKey, ephemeralPublicKey

I’m reading the documentation here

https://developer.apple.com/documentation/passkit/pkaddpaymentpassrequest?language=objc

My understanding is the app will need to pass the certificates, nonce, and nonceSignature to our api which then uses those certificates to encrypt the credit card info etc. Our api will respond with activationData, encryptedPassData, wrappedKey, ephemeralPublicKey and then the app can call PKAddPaymentPassRequest with that data to complete the process.

I am not sure where to start with the api side. How can I use the certificates to properly produce the required encrypted strings? What is the json format for a payment pass? There's lots of examples of different passes but no a payment pass.

Is there any example code that takes the certificates and produces the encryptedPassData and the other fields? I see there’s some pass example code on developer.apple.com but there is not any example code for a payment pass.

This question is the closest I could find to what I am asking. There's some comments asking about server side implementation but the answers are not clear

PKAddPassPaymentRequest not able to send a Request

coder
  • 1,274
  • 1
  • 13
  • 19
  • @s-p-balu-kommur you seem to have experience with this. Any ideas? – coder Oct 22 '20 at 13:59
  • @luca-taccagni as well – coder Oct 22 '20 at 14:00
  • 1
    Please refer : https://developer.apple.com/library/archive/documentation/UserExperience/Conceptual/PassKit_PG/YourFirst.html#//apple_ref/doc/uid/TP40012195-CH2-SW1 – Darshan Oct 26 '20 at 13:20
  • 1
    https://stackoverflow.com/questions/58626074/how-to-create-pkpass-file-for-apple-wallet-on-serverside-and-get-it-on-ios-side – Darshan Oct 26 '20 at 13:20

2 Answers2

3

You can add a credit card into apple wallet by creating .pkpass on the server-side

and download that file on the ios side it will add to the ios wallet

Here is the code to download the .pkpass (passbook file) from server with completion handler and show pkpassviewcontroller for further adding into the apple wallet.

  import PassKit


let url : NSURL! = NSURL(string: "YOUR .pkpass URL GOES HERE")
        let request: NSURLRequest = NSURLRequest(url:
            url as URL)
        let config = URLSessionConfiguration.default
        let session = URLSession(configuration: config)

    let task : URLSessionDataTask = session.dataTask(with: request as URLRequest, completionHandler: {(data, response, error) in

        var error: NSError?
        let pass = try? PKPass(data: data!, error: &error)
        if error != nil {
            DispatchQueue.main.async {
                let alertView = UIAlertView(title: "Error", message: (error?.localizedDescription)!, delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "Cancel")
                alertView.show()
            }
        }
        else {
            let passLibrary = PKPassLibrary()
            if passLibrary.containsPass(pass!) {
                DispatchQueue.main.async {
                    let alertView = UIAlertView(title: "Already Exist", message: "This pass already added in wallet. Thanks!", delegate: nil, cancelButtonTitle: "OK", otherButtonTitles: "Cancel")
                    alertView.show()
                    self.hideLoading()
                }
            } else {
                let pkvc = PKAddPassesViewController(pass: pass!)
                pkvc.delegate = self
                self.present(pkvc, animated: true, completion: {() -> Void in
                    // Do any cleanup here
                    self.hideLoading()
                })

            }
        }

    })
    task.resume()

PHP library to create passes for iOS wallet app

https://github.com/flexible-agency/php-pkpass

Darshan
  • 2,272
  • 3
  • 31
  • 43
  • I'll be writing this in C# but i may be able to get what I need by looking at this php project. The links and this php project gives me a lot to work with. I'll let you know. Thanks! – coder Oct 26 '20 at 16:31
  • Accept the ans if it’s okay for you – Darshan Oct 26 '20 at 16:33
  • I will if this is the correct answer. it is looking like this is for regular passes, not payment passes. Payment passes can't take a pkpass. That's why i'm asking this question. payment passes seem a lot different than regular passes – coder Oct 26 '20 at 18:03
  • 1
    this solution is not going to work since its for regular passes and not payment passes. Payment passes have a very different workflow. – coder Oct 26 '20 at 18:58
1

The implementation details are considered confidential and you must contact apple for the proper documentation

coder
  • 1,274
  • 1
  • 13
  • 19