diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheetFlowController.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheetFlowController.swift index 9bda6afe056..05773198a1d 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheetFlowController.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/PaymentSheetFlowController.swift @@ -518,7 +518,7 @@ class AuthenticationContext: NSObject, PaymentSheetAuthenticationContext { presentingViewController.present(authenticationViewController, animated: true, completion: nil) } - func presentPollingVCForAction(action: STPPaymentHandlerActionParams, type: STPPaymentMethodType, safariViewController: SFSafariViewController?) { + func presentPollingVCForAction(action: STPPaymentHandlerPaymentIntentActionParams, type: STPPaymentMethodType, safariViewController: SFSafariViewController?) { let pollingVC = PollingViewController(currentAction: action, viewModel: PollingViewModel(paymentMethodType: type), appearance: self.appearance, safariViewController: safariViewController) presentingViewController.present(pollingVC, animated: true, completion: nil) diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/BottomSheetViewController.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/BottomSheetViewController.swift index 808fb7868a9..a126b9f0c4c 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/BottomSheetViewController.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/BottomSheetViewController.swift @@ -451,7 +451,7 @@ extension BottomSheetViewController: PaymentSheetAuthenticationContext { self.removeBlurEffect(animated: true, completion: completion) } - func presentPollingVCForAction(action: STPPaymentHandlerActionParams, type: STPPaymentMethodType, safariViewController: SFSafariViewController?) { + func presentPollingVCForAction(action: STPPaymentHandlerPaymentIntentActionParams, type: STPPaymentMethodType, safariViewController: SFSafariViewController?) { let pollingVC = PollingViewController(currentAction: action, viewModel: PollingViewModel(paymentMethodType: type), appearance: self.appearance, safariViewController: safariViewController) pushContentViewController(pollingVC) diff --git a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/PollingViewController.swift b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/PollingViewController.swift index 9d4e42641a6..d42e0efad7b 100644 --- a/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/PollingViewController.swift +++ b/StripePaymentSheet/StripePaymentSheet/Source/PaymentSheet/ViewControllers/PollingViewController.swift @@ -25,14 +25,12 @@ class PollingViewController: UIViewController { // MARK: State private var oneSecondTimer: Timer? - private let currentAction: STPPaymentHandlerActionParams + private let currentAction: STPPaymentHandlerPaymentIntentActionParams private let appearance: PaymentSheet.Appearance private let viewModel: PollingViewModel private let safariViewController: SFSafariViewController? private lazy var intentPoller: IntentStatusPoller = { - guard let currentAction = currentAction as? STPPaymentHandlerPaymentIntentActionParams else { fatalError() } - let intentPoller = IntentStatusPoller(retryInterval: viewModel.retryInterval, intentRetriever: currentAction.apiClient, clientSecret: currentAction.paymentIntent.clientSecret) @@ -161,7 +159,7 @@ class PollingViewController: UIViewController { // MARK: Overrides - init(currentAction: STPPaymentHandlerActionParams, viewModel: PollingViewModel, appearance: PaymentSheet.Appearance, safariViewController: SFSafariViewController? = nil) { + init(currentAction: STPPaymentHandlerPaymentIntentActionParams, viewModel: PollingViewModel, appearance: PaymentSheet.Appearance, safariViewController: SFSafariViewController? = nil) { self.currentAction = currentAction self.appearance = appearance self.viewModel = viewModel @@ -350,8 +348,6 @@ extension PollingViewController: SheetNavigationBarDelegate { extension PollingViewController: IntentStatusPollerDelegate { func didUpdate(paymentIntent: STPPaymentIntent) { - guard let currentAction = currentAction as? STPPaymentHandlerPaymentIntentActionParams else { return } - if paymentIntent.status == .succeeded { setErrorStateWorkItem.cancel() // cancel the error work item incase it was scheduled currentAction.paymentIntent = paymentIntent // update the local copy of the intent with the latest from the server diff --git a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetLPMConfirmFlowTests.swift b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetLPMConfirmFlowTests.swift index ba0550a02ce..629824273b2 100644 --- a/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetLPMConfirmFlowTests.swift +++ b/StripePaymentSheet/StripePaymentSheetTests/PaymentSheet/PaymentSheetLPMConfirmFlowTests.swift @@ -610,7 +610,7 @@ extension PaymentSheet_LPM_ConfirmFlowTests: PaymentSheetAuthenticationContext { completion?() } - func presentPollingVCForAction(action: STPPaymentHandlerActionParams, type: STPPaymentMethodType, safariViewController: SFSafariViewController?) { + func presentPollingVCForAction(action: STPPaymentHandlerPaymentIntentActionParams, type: STPPaymentMethodType, safariViewController: SFSafariViewController?) { guard let currentAction = action as? STPPaymentHandlerPaymentIntentActionParams else { return } // Simulate that the intent transitioned to succeeded // If we don't update the status to succeeded, completing the action with .succeeded may fail due to invalid state diff --git a/StripePayments/StripePayments/Source/PaymentHandler/STPPaymentHandler.swift b/StripePayments/StripePayments/Source/PaymentHandler/STPPaymentHandler.swift index 9fdfefc3cbf..e7f4d915193 100644 --- a/StripePayments/StripePayments/Source/PaymentHandler/STPPaymentHandler.swift +++ b/StripePayments/StripePayments/Source/PaymentHandler/STPPaymentHandler.swift @@ -1269,6 +1269,10 @@ public class STPPaymentHandler: NSObject { case .BLIKAuthorize: // The customer must authorize the transaction in their banking app within 1 minute if let presentingVC = currentAction.authenticationContext as? PaymentSheetAuthenticationContext { + guard let currentAction = currentAction as? STPPaymentHandlerPaymentIntentActionParams else { + currentAction.complete(with: .failed, error: _error(for: .unexpectedErrorCode, loggingSafeErrorMessage: "Handling BLIKAuthorize next action with SetupIntent is not supported")) + return + } // If we are using PaymentSheet, PollingViewController will poll Stripe to determine success and complete the currentAction presentingVC.presentPollingVCForAction(action: currentAction, type: .blik, safariViewController: nil) } else { @@ -1282,6 +1286,10 @@ public class STPPaymentHandler: NSObject { case .upiAwaitNotification: // The customer must authorize the transaction in their banking app within 5 minutes if let presentingVC = currentAction.authenticationContext as? PaymentSheetAuthenticationContext { + guard let currentAction = currentAction as? STPPaymentHandlerPaymentIntentActionParams else { + currentAction.complete(with: .failed, error: _error(for: .unexpectedErrorCode, loggingSafeErrorMessage: "Handling upiAwaitNotification next action with SetupIntent is not supported")) + return + } // If we are using PaymentSheet, PollingViewController will poll Stripe to determine success and complete the currentAction presentingVC.presentPollingVCForAction(action: currentAction, type: .UPI, safariViewController: nil) } else { @@ -1315,7 +1323,10 @@ public class STPPaymentHandler: NSObject { currentAction.complete(with: .failed, error: _error(for: .unsupportedAuthenticationErrorCode, loggingSafeErrorMessage: "PayNow is not supported outside of PaymentSheet.")) return } - + guard let currentAction = currentAction as? STPPaymentHandlerPaymentIntentActionParams else { + currentAction.complete(with: .failed, error: self._error(for: .unexpectedErrorCode, loggingSafeErrorMessage: "Handling payNowDisplayQrCode next action with SetupIntent is not supported")) + return + } _handleRedirect(to: hostedInstructionsURL, fallbackURL: hostedInstructionsURL, return: returnURL) { safariViewController in // Present the polling view controller behind the web view so we can start polling right away presentingVC.presentPollingVCForAction(action: currentAction, type: .paynow, safariViewController: safariViewController) @@ -1341,6 +1352,10 @@ public class STPPaymentHandler: NSObject { currentAction.complete(with: .failed, error: _error(for: .unsupportedAuthenticationErrorCode, loggingSafeErrorMessage: "PromptPay is not supported outside of PaymentSheet.")) return } + guard let currentAction = currentAction as? STPPaymentHandlerPaymentIntentActionParams else { + currentAction.complete(with: .failed, error: self._error(for: .unexpectedErrorCode, loggingSafeErrorMessage: "Handling promptpayDisplayQrCode next action with SetupIntent is not supported")) + return + } _handleRedirect(to: hostedInstructionsURL, fallbackURL: hostedInstructionsURL, return: returnURL) { safariViewController in // Present the polling view controller behind the web view so we can start polling right away @@ -2384,7 +2399,7 @@ extension STPPaymentHandler { @_spi(STP) public protocol PaymentSheetAuthenticationContext: STPAuthenticationContext { func present(_ authenticationViewController: UIViewController, completion: @escaping () -> Void) func dismiss(_ authenticationViewController: UIViewController, completion: (() -> Void)?) - func presentPollingVCForAction(action: STPPaymentHandlerActionParams, type: STPPaymentMethodType, safariViewController: SFSafariViewController?) + func presentPollingVCForAction(action: STPPaymentHandlerPaymentIntentActionParams, type: STPPaymentMethodType, safariViewController: SFSafariViewController?) } @_spi(STP) public protocol FormSpecPaymentHandler {