From ffabbb034c8b4721316972c3da5d9e94100b8946 Mon Sep 17 00:00:00 2001 From: Charlie Cruzan Date: Mon, 24 Oct 2022 15:20:58 -0700 Subject: [PATCH] fix issue with incorrect payment request values never resolving --- ios/StripeSdk.swift | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ios/StripeSdk.swift b/ios/StripeSdk.swift index bd467c099..71d9de9cc 100644 --- a/ios/StripeSdk.swift +++ b/ios/StripeSdk.swift @@ -528,17 +528,20 @@ class StripeSdk: RCTEventEmitter, STPBankSelectionViewControllerDelegate, UIAdap applePaymentMethodFlowCanBeCanceled = true createNativePayPaymentMethodResolver = resolve - applePaymentAuthorizationController = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest) - applePaymentAuthorizationController?.delegate = self - DispatchQueue.main.async { - let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()) - vc.present( - self.applePaymentAuthorizationController!, - animated: true, - completion: nil - ) - } - + self.applePaymentAuthorizationController = PKPaymentAuthorizationViewController(paymentRequest: paymentRequest) + if let applePaymentAuthorizationController = self.applePaymentAuthorizationController { + applePaymentAuthorizationController.delegate = self + DispatchQueue.main.async { + let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()) + vc.present( + applePaymentAuthorizationController, + animated: true, + completion: nil + ) + } + } else { + resolve(Errors.createError(ErrorType.Failed, "Invalid in-app payment request. Search the iOS logs for `NSUnderlyingError` to get more information.")) + } } @objc(dismissApplePay:rejecter:)