Skip to content

Instantly share code, notes, and snippets.

@nspeet
Last active February 7, 2019 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nspeet/ffa23a6cadd20935673f051b14a98dd2 to your computer and use it in GitHub Desktop.
Save nspeet/ffa23a6cadd20935673f051b14a98dd2 to your computer and use it in GitHub Desktop.
//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