Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove precondition on presentPaymentMethod #1048

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Sources/PrimerSDK/Classes/User Interface/PrimerUIManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,16 @@ internal class PrimerUIManager: PrimerUIManaging {
func presentPaymentMethod(type: String) {
let paymentMethodTokenizationViewModel = PrimerAPIConfiguration.paymentMethodConfigViewModels.filter({ $0.config.type == type }).first

precondition(paymentMethodTokenizationViewModel != nil, "PrimerUIManager should have validated that the view model exists.")
guard let paymentMethodTokenizationViewModel else {
let error = PrimerError.unableToPresentPaymentMethod(
paymentMethodType: type,
userInfo: .errorUserInfoDictionary(
additionalInfo: ["message": "paymentMethodTokenizationViewModel was not present when calling presentPaymentMethod"]
),
diagnosticsId: UUID().uuidString)
ErrorHandler.handle(error: error)
return
}

var imgView: UIImageView?
if let squareLogo = PrimerAPIConfiguration.paymentMethodConfigViewModels.filter({ $0.config.type == type }).first?.uiModule.icon {
Expand All @@ -101,21 +110,21 @@ internal class PrimerUIManager: PrimerUIManaging {

PrimerUIManager.primerRootViewController?.showLoadingScreenIfNeeded(imageView: imgView, message: nil)

paymentMethodTokenizationViewModel?.checkoutEventsNotifierModule.didStartTokenization = {
paymentMethodTokenizationViewModel.checkoutEventsNotifierModule.didStartTokenization = {
PrimerUIManager.primerRootViewController?.showLoadingScreenIfNeeded(imageView: imgView, message: nil)
}

paymentMethodTokenizationViewModel?.willPresentPaymentMethodUI = {
paymentMethodTokenizationViewModel.willPresentPaymentMethodUI = {
PrimerUIManager.primerRootViewController?.showLoadingScreenIfNeeded(imageView: imgView, message: nil)
}

paymentMethodTokenizationViewModel?.didPresentPaymentMethodUI = {}
paymentMethodTokenizationViewModel.didPresentPaymentMethodUI = {}

paymentMethodTokenizationViewModel?.willDismissPaymentMethodUI = {
paymentMethodTokenizationViewModel.willDismissPaymentMethodUI = {
PrimerUIManager.primerRootViewController?.showLoadingScreenIfNeeded(imageView: imgView, message: nil)
}

paymentMethodTokenizationViewModel?.start()
paymentMethodTokenizationViewModel.start()
}

func prepareRootViewController() -> Promise<Void> {
Expand Down
Loading