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
1 Answers
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 thecom.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 atapple-pay-inquiries@apple.com
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
}
}

- 1,902
- 16
- 20
-
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 you – vijju Jul 16 '18 at 04:53
-
If I understand you correctly, you need special permissions to add cards to apple pay. See this thread: https://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. – Scott Condron Jul 16 '18 at 12:02
-
My issue is when user clicks the addcards button then he redirects to apple wallet to add the card details? is it possible? – vijju Jul 17 '18 at 05:10
-
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. – vijju Aug 06 '18 at 07:31
-
`initWithRequestConfiguration` will return nil if you do not have the special entitlement from Apple. – Scott Condron Aug 06 '18 at 13:16
-
See: https://developer.apple.com/documentation/passkit/apple_pay/setting_up_apple_pay_requirements – Scott Condron Aug 06 '18 at 13:17
-
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? – vijju Aug 06 '18 at 14:20
-
Again I created the apple pay payment processing certtificate but it shows nil value – vijju Aug 07 '18 at 05:46
-
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, – Scott Condron Aug 07 '18 at 09:48
-
Also, see here: https://stackoverflow.com/questions/50436058/pkaddpasspaymentrequest-not-able-to-send-a-request/50475819#50475819. "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." – Scott Condron Aug 07 '18 at 09:50
-
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. – Scott Condron Aug 07 '18 at 15:22
-
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 apple – vijju Aug 08 '18 at 04:06
-
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. – Scott Condron Aug 08 '18 at 09:20