Programmatically add a credit/bank card to a user’s apple wallet

Published

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

Source: Ios Questions

Published
Categorised as apple-wallet, applepay, ios, wallet Tagged , , ,

Answers

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


Shad Kutch

Leave a Reply

Your email address will not be published. Required fields are marked *

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq