Last active
February 7, 2019 15:45
-
-
Save nspeet/ffa23a6cadd20935673f051b14a98dd2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1. Check if the PKPaymentAuthorizationViewController can make payments | |
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) { | |
// develop your payment request | |
let request = PKPaymentRequest() | |
request.merchantIdentifier = "merchant.yourmerchantid" //add more info to the payment request as needed | |
//2. Then present the Apple Pay authorizationViewController | |
let authorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: request) | |
if let viewController = authorizationViewController { | |
viewController.delegate = self | |
self.present(viewController, animated: true, completion: nil) | |
} | |
} | |
//3. handle auth completion | |
public func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, completion: ((PKPaymentAuthorizationStatus) -> Void)) { | |
completion(PKPaymentAuthorizationStatus.success) | |
} | |
public func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) { | |
controller.dismiss(animated: true, completion: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment