Skip to content

Instantly share code, notes, and snippets.

@koke
Created June 7, 2022 10:41
Show Gist options
  • Save koke/ec963cfa028d146fa0c126fcf5899794 to your computer and use it in GitHub Desktop.
Save koke/ec963cfa028d146fa0c126fcf5899794 to your computer and use it in GitHub Desktop.
diff --git a/WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/CardPresentPaymentsOnboardingUseCase.swift b/WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/CardPresentPaymentsOnboardingUseCase.swift
index d26f26b356..ff25da7b4e 100644
--- a/WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/CardPresentPaymentsOnboardingUseCase.swift
+++ b/WooCommerce/Classes/ViewRelated/Dashboard/Settings/In-Person Payments/CardPresentPaymentsOnboardingUseCase.swift
@@ -28,6 +28,26 @@ protocol CardPresentPaymentsOnboardingUseCaseProtocol {
func updateState()
}
+protocol CardPresentPaymentsOnboardingUseCaseStateCheckResultProtocol {
+ var state: CardPresentPaymentOnboardingState { get }
+ var multipleGateways: Bool { get }
+}
+
+extension CardPresentPaymentOnboardingState: CardPresentPaymentsOnboardingUseCaseStateCheckResultProtocol {
+ var state: CardPresentPaymentOnboardingState {
+ self
+ }
+
+ var multipleGateways: Bool {
+ return false
+ }
+}
+
+private struct CardPresentPaymentsOnboardingUseCaseStateCheckResult {
+ let state: CardPresentPaymentOnboardingState
+ let multipleGateways: Bool
+}
+
final class CardPresentPaymentsOnboardingUseCase: CardPresentPaymentsOnboardingUseCaseProtocol, ObservableObject {
let storageManager: StorageManagerType
let stores: StoresManager
@@ -37,6 +57,7 @@ final class CardPresentPaymentsOnboardingUseCase: CardPresentPaymentsOnboardingU
private var preferredPluginLocal: CardPresentPaymentsPlugin?
@Published var state: CardPresentPaymentOnboardingState = .loading
+ @Published var multipleGateways: Bool = false
var statePublisher: Published<CardPresentPaymentOnboardingState>.Publisher {
$state
@@ -89,7 +110,9 @@ final class CardPresentPaymentsOnboardingUseCase: CardPresentPaymentsOnboardingU
}
func updateState() {
- state = checkOnboardingState()
+ let result = checkOnboardingState()
+ state = result.state
+ multipleGateways = result.multipleGateways
}
func selectPlugin(_ plugin: CardPresentPaymentsPlugin) {
@@ -147,10 +170,10 @@ private extension CardPresentPaymentsOnboardingUseCase {
})
}
- func checkOnboardingState() -> CardPresentPaymentOnboardingState {
+ func checkOnboardingState() -> CardPresentPaymentsOnboardingUseCaseStateCheckResultProtocol {
guard let countryCode = storeCountryCode else {
DDLogError("[CardPresentPaymentsOnboarding] Couldn't determine country for store")
- return .genericError
+ return CardPresentPaymentOnboardingState.genericError
}
let configuration = configurationLoader.configuration
@@ -161,7 +184,7 @@ private extension CardPresentPaymentsOnboardingUseCase {
// If isSupportedCountry is false, IPP is not supported in the country through any
// payment gateway
guard configuration.isSupportedCountry else {
- return .countryNotSupported(countryCode: countryCode)
+ return CardPresentPaymentOnboardingState.countryNotSupported(countryCode: countryCode)
}
switch (wcPay, stripe) {
@@ -172,11 +195,11 @@ private extension CardPresentPaymentsOnboardingUseCase {
case (.some(let wcPay), .some(let stripe)):
return bothPluginsInstalledOnboardingState(wcPay: wcPay, stripe: stripe)
case (nil, nil):
- return .pluginNotInstalled
+ return CardPresentPaymentOnboardingState.pluginNotInstalled
}
}
- func bothPluginsInstalledOnboardingState(wcPay: SystemPlugin, stripe: SystemPlugin) -> CardPresentPaymentOnboardingState {
+ func bothPluginsInstalledOnboardingState(wcPay: SystemPlugin, stripe: SystemPlugin) -> CardPresentPaymentsOnboardingUseCaseStateCheckResultProtocol {
switch (wcPay.active, stripe.active) {
case (true, true):
return bothPluginsInstalledAndActiveOnboardingState(wcPay: wcPay, stripe: stripe)
@@ -185,11 +208,11 @@ private extension CardPresentPaymentsOnboardingUseCase {
case (false, true):
return stripeGatewayOnlyOnboardingState(plugin: stripe)
case (false, false):
- return .pluginNotActivated(plugin: .wcPay)
+ return CardPresentPaymentOnboardingState.pluginNotActivated(plugin: .wcPay)
}
}
- func bothPluginsInstalledAndActiveOnboardingState(wcPay: SystemPlugin, stripe: SystemPlugin) -> CardPresentPaymentOnboardingState {
+ func bothPluginsInstalledAndActiveOnboardingState(wcPay: SystemPlugin, stripe: SystemPlugin) -> CardPresentPaymentsOnboardingUseCaseStateCheckResultProtocol {
guard featureFlagService.isFeatureFlagEnabled(.inPersonPaymentGatewaySelection) else {
return legacyBothPluginsInstalledAndActiveOnboardingState(wcPay: wcPay, stripe: stripe)
}
@@ -203,10 +226,12 @@ private extension CardPresentPaymentsOnboardingUseCase {
}
if let preferredPlugin = preferredPluginLocal {
- return onboardingStateForPlugin(preferredPlugin, wcPay: wcPay, stripe: stripe)
+ let state = onboardingStateForPlugin(preferredPlugin, wcPay: wcPay, stripe: stripe)
+ return CardPresentPaymentsOnboardingUseCaseStateCheckResult(state: state, multipleGateways: true)
+
}
- return .selectPlugin
+ return CardPresentPaymentsOnboardingUseCaseStateCheckResult(state: .selectPlugin, multipleGateways: true)
}
func legacyBothPluginsInstalledAndActiveOnboardingState(wcPay: SystemPlugin, stripe: SystemPlugin) -> CardPresentPaymentOnboardingState {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment