@@ -77,18 +77,6 @@ final class CardPresentPaymentsOnboardingUseCase: CardPresentPaymentsOnboardingU
7777 return
7878 }
7979
80- let wcPayPlugin = cardPresentPluginsDataProvider. getWCPayPlugin ( )
81- let stripePlugin = cardPresentPluginsDataProvider. getStripePlugin ( )
82- let paymentPluginsInstalledAndActiveStatus = cardPresentPluginsDataProvider. paymentPluginsInstalledAndActiveStatus ( wcPay: wcPayPlugin,
83- stripe: stripePlugin)
84-
85- /// If both plugins are active, don't bother initializing the backend nor fetching
86- /// accounts. Fall through to updateState so the end user can fix the problem.
87- guard paymentPluginsInstalledAndActiveStatus != . bothAreInstalledAndActive else {
88- self . updateState ( )
89- return
90- }
91-
9280 let paymentGatewayAccountsAction = CardPresentPaymentAction . loadAccounts ( siteID: siteID) { [ weak self] result in
9381 self ? . updateState ( )
9482 }
@@ -155,52 +143,48 @@ private extension CardPresentPaymentsOnboardingUseCase {
155143
156144 let wcPay = cardPresentPluginsDataProvider. getWCPayPlugin ( )
157145 let stripe = cardPresentPluginsDataProvider. getStripePlugin ( )
158- let isStripeSupported = configuration. paymentGateways. contains ( StripeAccount . gatewayID)
159146
160147 // If isSupportedCountry is false, IPP is not supported in the country through any
161148 // payment gateway
162149 guard configuration. isSupportedCountry else {
163150 return . countryNotSupported( countryCode: countryCode)
164151 }
165152
166- let paymentPluginsInstalledAndActiveStatus = cardPresentPluginsDataProvider. paymentPluginsInstalledAndActiveStatus ( wcPay: wcPay, stripe: stripe)
167-
168- // If it is supported in the country, we might or might not support Stripe yet, only WCPay
169- guard isStripeSupported else {
170- if paymentPluginsInstalledAndActiveStatus == . bothAreInstalledAndActive {
171- // They have WCPay and Stripe installed and active at the same time.
172- // Deactivating Stripe is the advised way to proceed.
173- return . pluginShouldBeDeactivated( plugin: . stripe)
174- } else if paymentPluginsInstalledAndActiveStatus == . onlyStripeIsInstalledAndActive {
175- // If we only support WCPay, we don't want to ask users to set up WCPay if they already
176- // have Stripe. In that case, we can tell them that IPP is not supported for Stripe in
177- // their country yet.
178- return . countryNotSupportedStripe( plugin: . stripe, countryCode: countryCode)
179- } else {
180- return wcPayOnlyOnboardingState ( plugin: wcPay)
181- }
153+ switch ( wcPay, stripe) {
154+ case ( . some( let wcPay) , nil ) :
155+ return wcPayOnlyOnboardingState ( plugin: wcPay)
156+ case ( nil , . some( let stripe) ) :
157+ return stripeGatewayOnlyOnboardingState ( plugin: stripe)
158+ case ( . some( let wcPay) , . some( let stripe) ) :
159+ return bothPluginsInstalledOnboardingState ( wcPay: wcPay, stripe: stripe)
160+ case ( nil , nil ) :
161+ return . pluginNotInstalled
182162 }
163+ }
183164
184- // If both the Stripe plugin and WCPay are installed and activated, the user needs
185- // to deactivate one: pdfdoF-fW-p2#comment-683
186- if paymentPluginsInstalledAndActiveStatus == . bothAreInstalledAndActive {
187- return . selectPlugin
165+ func bothPluginsInstalledOnboardingState( wcPay: SystemPlugin , stripe: SystemPlugin ) -> CardPresentPaymentOnboardingState {
166+ switch ( wcPay. active, stripe. active) {
167+ case ( true , true ) :
168+ return bothPluginsInstalledAndActiveOnboardingState ( wcPay: wcPay, stripe: stripe)
169+ case ( true , false ) :
170+ return wcPayOnlyOnboardingState ( plugin: wcPay)
171+ case ( false , true ) :
172+ return stripeGatewayOnlyOnboardingState ( plugin: stripe)
173+ case ( false , false ) :
174+ return . pluginNotActivated( plugin: . wcPay)
188175 }
176+ }
189177
190- // If only the Stripe extension is installed, skip to checking Stripe activation and version
191- if let stripe = stripe,
192- paymentPluginsInstalledAndActiveStatus != . onlyWCPayIsInstalledAndActive {
193- return stripeGatewayOnlyOnboardingState ( plugin: stripe)
194- } else {
195- return wcPayOnlyOnboardingState ( plugin: wcPay)
178+ func bothPluginsInstalledAndActiveOnboardingState( wcPay: SystemPlugin , stripe: SystemPlugin ) -> CardPresentPaymentOnboardingState {
179+ if !isStripeSupportedInCountry {
180+ return . pluginShouldBeDeactivated( plugin: . stripe)
196181 }
182+
183+ return . selectPlugin
197184 }
198185
199- func wcPayOnlyOnboardingState( plugin: SystemPlugin ? ) -> CardPresentPaymentOnboardingState {
186+ func wcPayOnlyOnboardingState( plugin: SystemPlugin ) -> CardPresentPaymentOnboardingState {
200187 // Plugin checks
201- guard let plugin = plugin else {
202- return . pluginNotInstalled
203- }
204188 guard cardPresentPluginsDataProvider. isWCPayVersionSupported ( plugin: plugin)
205189 else {
206190 return . pluginUnsupportedVersion( plugin: . wcPay)
@@ -214,6 +198,14 @@ private extension CardPresentPaymentsOnboardingUseCase {
214198 }
215199
216200 func stripeGatewayOnlyOnboardingState( plugin: SystemPlugin ) -> CardPresentPaymentOnboardingState {
201+ guard isStripeSupportedInCountry else {
202+ guard let countryCode = storeCountryCode else {
203+ DDLogError ( " [CardPresentPaymentsOnboarding] Couldn't determine country for store " )
204+ return . genericError
205+ }
206+ return . countryNotSupportedStripe( plugin: . stripe, countryCode: countryCode)
207+ }
208+
217209 guard cardPresentPluginsDataProvider. isStripeVersionSupported ( plugin: plugin)
218210 else {
219211 return . pluginUnsupportedVersion( plugin: . stripe)
@@ -274,6 +266,10 @@ private extension CardPresentPaymentsOnboardingUseCase {
274266 return storeCountryCode. nonEmptyString ( )
275267 }
276268
269+ var isStripeSupportedInCountry : Bool {
270+ configurationLoader. configuration. paymentGateways. contains ( StripeAccount . gatewayID)
271+ }
272+
277273 // Note: This counts on synchronizeStoreCountryAndPlugins having been called to get
278274 // the appropriate account for the site, be that Stripe or WCPay
279275 func getPaymentGatewayAccount( ) -> PaymentGatewayAccount ? {
0 commit comments