You can't show UIAlertView
on the PKPaymentAuthorizationViewController
because of the security of the system.
The entire UI of PKPaymentAuthorizationViewController
is presented via a Remote View Controller. This means that outside the PKPaymentRequest you give it, it’s impossible to otherwise style or modify the contents of this view.
And for handle Apple Pay error you have to use PKPaymentAuthorizationViewControllerDelegate
delegate method to show payment is successfully complete or there are any error.
For show PKPaymentAuthorizationViewController
,
present payment view controller as:
PKPaymentAuthorizationViewController *paymentVC = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
paymentVC.delegate = self;
[self presentViewController:paymentVC animated:true completion:nil];
- The customer approves the purchase using Touch ID (or, if that fails
3 times, by entering their passcode).
- The thumbprint icon turns into a spinner, with the label “Processing”
- Your delegate receives the
paymentAuthorizationViewController(_:didAuthorizePayment:completion:)
callback
- Your application communicates asynchronously with your payment
processor and website backend to actually make a charge with those
payment details. Once this complete, you invoke the completion
handler that you’re given as a parameter with either
PKPaymentAuthorizationStatus.success or
PKPaymentAuthorizationStatus.failure depending on the result.
- The PKPaymentAuthorizationViewController spinner animates into a
success or failure icon. If successful, a notification will arrive
from PassBook indicating a charge on the customer’s credit card.
- Your delegate receives the
paymentAuthorizationViewControllerDidFinish(_:) callback. It is then
responsible for calling dismiss(animated:completion:) to dismiss the
payment screen.


- (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller
didAuthorizePayment:(PKPayment *)payment
completion:(void (^)(PKPaymentAuthorizationStatus status))completion {
//=========================================
//=========================================
// Call your api here for charge payment and according to that api result show complition as follow
//========================================
//========================================
// Use your payment processor's SDK to finish charging your customer.
// When this is done, call:
completion(PKPaymentAuthorizationStatusSuccess);
// When this is Payment not completed, call:
// completion(PKPaymentAuthorizationStatusFailure);
// When this is Supplied billing address is insufficient or otherwise invalid, call:
// completion(PKPaymentAuthorizationStatusInvalidBillingPostalAddress);
// When this is Supplied postal address is insufficient or otherwise invalid, call:
// completion(PKPaymentAuthorizationStatusInvalidShippingPostalAddress);
// When this is Supplied contact information is insufficient or otherwise invalid, call:
// completion(PKPaymentAuthorizationStatusInvalidShippingContact);
}
// Sent to the delegate when payment authorization is finished. This may occur when
// the user cancels the request, or after the PKPaymentAuthorizationStatus parameter of the
// paymentAuthorizationViewController:didAuthorizePayment:completion: has been shown to the user.
//
// The delegate is responsible for dismissing the view controller in this method.
- (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller {
[self dismissViewControllerAnimated:true completion:nil];
}
show
ing aUIAlertView
,present
ing aUIAlertController
might be a better idea. As long as you have the reference to theUIViewController
that you want to show alert on top of, this should not be a problem.