how to call the apple wallet from ios app using swift
Asked Answered
W

1

2

I want to display apple wallet add cards page whenever user clicks the add cards to wallet button in my ios app. how to call the apple wallet from ios app. I enabled wallet capabilities in my ios app and also generate the wallet entitlements to my app. How to use PKAddPaymentPassViewControler using swift. please give some idea about it

Wardroom answered 27/6, 2018 at 10:45 Comment(0)
B
6

NOTE: This is for Card Issuers only. If you want to redirect a user to add a payment method, use the openPaymentSetup method. See my answer here for more details.

For Card Issuers, you need a special entitlement issued by Apple.

Your app must include this entitlement before you can use this class. For more information on requesting this entitlement, see the Card Issuers section at developer.apple.com/apple-pay/.

From this answer:

PKAddPaymentPassViewController requires the com.apple.developer.payment-pass-provisioning entitlement key for your app. The bad news is that not anyone can submit apps with this entitlement as it requires special permission from Apple, which I believe is reserved for card issuers like banks and similar. If you believe that you qualify you need to contact Apple directly at [email protected]

You need to implement the delegate methods, and initialise it with a configuration.

import UIKit
import PassKit

class ViewController: UIViewController, PKAddPaymentPassViewControllerDelegate {

  override func viewDidLoad() {
    super.viewDidLoad()
    if (!PKAddPaymentPassViewController.canAddPaymentPass()){
      // use other payment method / alert user
    }
    let config = PKAddPaymentPassRequestConfiguration.init(encryptionScheme: PKEncryptionScheme.ECC_V2)
    let addPaymentPassVC = PKAddPaymentPassViewController.init(requestConfiguration: config!, delegate: self)
    self.present(addPaymentPassVC!, animated: true, completion: nil)
  }

  func addPaymentPassViewController(_ controller: PKAddPaymentPassViewController, generateRequestWithCertificateChain certificates: [Data], nonce: Data, nonceSignature: Data, completionHandler handler: @escaping (PKAddPaymentPassRequest) -> Void) {

  }

  func addPaymentPassViewController(_ controller: PKAddPaymentPassViewController, didFinishAdding pass: PKPaymentPass?, error: Error?) {
    // pass added
  }

}
Biannulate answered 5/7, 2018 at 17:11 Comment(13)
Hii. I have a doubt that is if I want to store the user card details in apple wallet can I take the permission from the apple or is it ok with adding entitlements in my app. When the user clicks the add cards button from my app then is it open wallet app or customize the page myself. Thank youWardroom
If I understand you correctly, you need special permissions to add cards to apple pay. See this thread: forums.developer.apple.com/thread/13576 You would not be creating the page yourself, the card would be added from the Wallet app or an area managed by Apple.Biannulate
My issue is when user clicks the addcards button then he redirects to apple wallet to add the card details? is it possible?Wardroom
hii. I got error at self.present(addPaymentPassVC!, animated: true, completion: nil) that is Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value. addPaymentPassVC stores the nill value.Wardroom
initWithRequestConfiguration will return nil if you do not have the special entitlement from Apple.Biannulate
See: developer.apple.com/documentation/passkit/apple_pay/…Biannulate
Already i have the apple pay certificate because i used apple pay as payment methods and for processing i used the stripe so when the time of creation of payment processing certificate i download the .certSigningRequest from the stripe and submit it in that. so is it ok?Wardroom
Again I created the apple pay payment processing certtificate but it shows nil valueWardroom
I have added an edit with more details on the entitlement key needed. It is reserved for card issuers. If you are just looking to create a payment,Biannulate
Also, see here: #50436558. "You can test push provisioning to producation only by testflight or appstore. You can request for sandbox env into your device from Apple. They can enable QA env in your device by installing a profile. Then you can test push provisioning in QA env as well."Biannulate
I have added an edit which links to a comment for people who are not card issuers but want to prompt a user to add a card.Biannulate
We are not issuing cards to any user. Just we want give access to user to store the card details into apple wallet when user clicks the add card to wallet button. In that case can we use that class or can we get the permission from the appleWardroom
You can use the PKPaymentButton by just enabling Apple Pay for your App ID within Xcode. There’s a code snippet within my answer I linked. Please mark this answer as correct now.Biannulate

© 2022 - 2024 — McMap. All rights reserved.