I am working on implementing Apple Pay for my Application. While I have everything mostly figured out, I am not able to dismiss the PKPaymentAuthorizationViewController that authenticates. Here is my code..
-(void) viewDidAppear:(BOOL)animated {
// request is initialized here.
paymentPane = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
//paymentPane is not nil.
paymentPane.delegate = self;
[self presentViewController:paymentPane animated:TRUE completion:nil];
}
The above function is called and successfully presents the Apple Pay View Controller to authenticate the payment. I have implemented the following methods from the delegate as follows:
-(void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion {
NSLog(@"%@", [payment.token description]);
completion(PKPaymentAuthorizationStatusSuccess);
}
Ideally it hits the didAuthorizePayment first, where we authenticate the payment, and pass success if its successful, then the paymentAuthorizationViewControllerDidFinish is called and that is used to complete transaction and hide the Apple View Controller. I put breakpoints in there and it hits both functions, but the ViewController doesn't go away. It doesn't go even if you tap the Cancel button inside Apple Pay View.
My class declaration is as follows and does implement the required delegates.
@interface ApplePayManager : UIViewController<PKPaymentAuthorizationViewControllerDelegate, UIAlertViewDelegate>
Any ideas on what I am doing wrong? Why is the view controller not dismissing?
Lastly, I am a bit new to iOS. So I'd appreciate guides and/or links to clarify my doubts!
Already looked at: http://www.raywenderlich.com/87300/apple-pay-tutorial https://dzone.com/articles/integrating-your-ios-app-apple