2

Apple Pay is working fine in simulator but after upgrading Xcode to 10.4, it stopped working.

  1. The Apple Pay popup appears.
  2. After click on pay with passcode, it hides without authenticating the payment.

  3. The method - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus))completion {} is not called.

Code:

NSString *merchantIdentifier = [STPPaymentConfiguration sharedConfiguration].appleMerchantIdentifier;
PKPaymentRequest *paymentRequest = [Stripe paymentRequestWithMerchantIdentifier:merchantIdentifier country:@"US" currency:currencyCode];
paymentRequest.paymentSummaryItems = @[
   [PKPaymentSummaryItem summaryItemWithLabel:@"Fancy Hat" amount:[NSDecimalNumber decimalNumberWithString:amount]],
   // The final line should represent your company;
   // it'll be prepended with the word "Pay" (i.e. "Pay iHats, Inc $50")
   [PKPaymentSummaryItem summaryItemWithLabel:@"iHats, Inc" amount:[NSDecimalNumber decimalNumberWithString:amount]],
];

if ([Stripe canSubmitPaymentRequest:paymentRequest]) {
    // Setup payment authorization view controller
    PKPaymentAuthorizationViewController *paymentAuthorizationViewController = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:paymentRequest];
    paymentAuthorizationViewController.delegate = self;

    // Present payment authorization view controller
    FlutterViewController* controller = (FlutterViewController* )[[UIApplication sharedApplication].keyWindow rootViewController];
    [controller presentViewController:paymentAuthorizationViewController animated:YES completion:nil];
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Shiv Pogra
  • 93
  • 5
  • exactly same issue after update to Xcode 10.3. Noticed that the signature for `didAuthorizePayment` method has changed to `func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void)` and it is marked as iOS11+. But changing to the new signature didn't help for me. – Vitalii Sep 17 '19 at 15:18

1 Answers1

0

They did change the signature, so that there is a new method to call for iOS11+, while the old method is still needed for iOS9 and iOS10:

 /// for iOS 9 and iOS 10
 func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
                          didAuthorizePayment payment: PKPayment,
                                           completion: @escaping (PKPaymentAuthorizationStatus) -> Void) {
    ...
 }

 @available(iOS 11.0, *)
 func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController,
                          didAuthorizePayment payment: PKPayment,
                                              handler: @escaping (PKPaymentAuthorizationResult) -> Void) {
    ...
 }

AND

It seems to be not working in 12.4 Simulator. You'll need to test on real device. Simulators with previous iOS'es seem to be working (iOS10 works for me). The simulator issue is discussed in this question: ApplePay `paymentAuthorizationViewController:didAuthorizePayment:handler:` not called in Xcode Simulator 10.3

Vitalii
  • 4,267
  • 1
  • 40
  • 45