Skip to content

Commit

Permalink
Merge pull request #12908 from woocommerce/12904-woo-pos---payments-o…
Browse files Browse the repository at this point in the history
…nboarding-handle-case-when-we-dont-know-country-and-currency

[Woo POS payments onboarding] Handle case when we dont know country and currency
  • Loading branch information
samiuelson authored Nov 18, 2024
2 parents f191500 + 3e60a27 commit 6393c4f
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 149 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*** Use [*****] to indicate smoke tests of all critical flows should be run on the final APK before release (e.g. major library or targetSdk updates).
*** For entries which are touching the Android Wear app's, start entry with `[WEAR]` too.
21.2
- [Internal] Changed a way how authenticated web view opened in the IPP flows [https://github.com/woocommerce/woocommerce-android/pull/12908]
-----
- [**][Payments] Fixed a bug when IPP onboarding was not possible to finish from the app [https://github.com/woocommerce/woocommerce-android/pull/12917]
- [*] Fixed shipping lines being editable at all states [https://github.com/woocommerce/woocommerce-android/pull/12890]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import androidx.lifecycle.Lifecycle
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.woocommerce.android.NavGraphMainDirections
import com.woocommerce.android.NavGraphPaymentFlowDirections
import com.woocommerce.android.R
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.databinding.CardReaderConnectDialogBinding
Expand Down Expand Up @@ -268,7 +268,7 @@ class CardReaderConnectDialogFragment : PaymentsBaseDialogFragment(R.layout.card
ToastUtils.showToast(requireContext(), event.message)
is CardReaderConnectEvent.OpenWPComWebView ->
findNavController().navigateSafely(
NavGraphMainDirections.actionGlobalWPComWebViewFragment(urlToLoad = event.url)
NavGraphPaymentFlowDirections.actionGlobalWPComWebViewFragment(urlToLoad = event.url)
)
is CardReaderConnectEvent.OpenGenericWebView ->
ChromeCustomTabUtils.launchUrl(requireContext(), event.url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar
import com.woocommerce.android.NavGraphMainDirections
import com.woocommerce.android.NavGraphPaymentFlowDirections
import com.woocommerce.android.R
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.databinding.CardReaderPaymentDialogBinding
Expand Down Expand Up @@ -141,7 +141,7 @@ class CardReaderPaymentDialogFragment : PaymentsBaseDialogFragment(R.layout.card

private fun openPurchaseCardReaderScreen(url: String) {
findNavController().navigate(
NavGraphMainDirections.actionGlobalWPComWebViewFragment(urlToLoad = url)
NavGraphPaymentFlowDirections.actionGlobalWPComWebViewFragment(urlToLoad = url)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.transition.Slide
import androidx.transition.TransitionManager
import com.google.android.material.textview.MaterialTextView
import com.woocommerce.android.NavGraphMainDirections
import com.woocommerce.android.NavGraphPaymentFlowDirections
import com.woocommerce.android.R
import com.woocommerce.android.analytics.AnalyticsTracker
import com.woocommerce.android.databinding.FragmentPaymentsHubBinding
Expand Down Expand Up @@ -91,7 +92,7 @@ class PaymentsHubFragment : BaseFragment(R.layout.fragment_payments_hub) {
}
is PaymentsHubViewModel.PaymentsHubEvents.NavigateToPurchaseCardReaderFlow -> {
findNavController().navigate(
NavGraphMainDirections.actionGlobalWPComWebViewFragment(
NavGraphPaymentFlowDirections.actionGlobalWPComWebViewFragment(
urlToLoad = event.url,
title = resources.getString(event.titleRes)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,26 @@ import com.woocommerce.android.util.IsRemoteFeatureFlagEnabled
import com.woocommerce.android.util.RemoteFeatureFlag.WOO_POS
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import org.wordpress.android.fluxc.model.SiteModel
import org.wordpress.android.fluxc.model.payments.inperson.WCPaymentAccountResult
import org.wordpress.android.fluxc.store.WCInPersonPaymentsStore
import org.wordpress.android.fluxc.store.WCInPersonPaymentsStore.InPersonPaymentsPluginType.WOOCOMMERCE_PAYMENTS
import org.wordpress.android.fluxc.store.WooCommerceStore
import javax.inject.Inject
import javax.inject.Singleton

private typealias LocalSiteId = Int

@Singleton
class WooPosIsEnabled @Inject constructor(
private val selectedSite: SelectedSite,
private val ippStore: WCInPersonPaymentsStore,
private val isScreenSizeAllowed: WooPosIsScreenSizeAllowed,
private val getWooCoreVersion: GetWooCorePluginCachedVersion,
private val cardReaderOnboardingChecker: CardReaderOnboardingChecker,
private val wooCommerceStore: WooCommerceStore,
private val isRemoteFeatureFlagEnabled: IsRemoteFeatureFlagEnabled,
private val isWooPosPaymentsOnboardingSupportedInternally: WooPosIsPaymentsOnboardingSupportedInternally,
) {
private var paymentAccountCache: HashMap<LocalSiteId, WCPaymentAccountResult> = hashMapOf()

@Suppress("ReturnCount")
suspend operator fun invoke(): Boolean = coroutineScope {
val selectedSite = selectedSite.getOrNull() ?: return@coroutineScope false

val onboardingStatusDeferred = async { cardReaderOnboardingChecker.getOnboardingState() }
val paymentAccountDeferred = async { getOrFetchPaymentAccount(selectedSite, WOOCOMMERCE_PAYMENTS) }
val siteSettingsDeferred = async { wooCommerceStore.getSiteSettings(selectedSite) }

if (!isRemoteFeatureFlagEnabled(WOO_POS)) return@coroutineScope false
if (!isScreenSizeAllowed()) return@coroutineScope false
Expand All @@ -50,27 +43,13 @@ class WooPosIsEnabled @Inject constructor(
if (!isIPPOnboardingCompleted(onboardingStatus)) return@coroutineScope false
}

val paymentAccount = paymentAccountDeferred.await() ?: return@coroutineScope false
if (paymentAccount.country.lowercase() != "us") return@coroutineScope false
if (paymentAccount.storeCurrencies.default.lowercase() != "usd") return@coroutineScope false
val siteSettings = siteSettingsDeferred.await() ?: return@coroutineScope false
if (siteSettings.countryCode.lowercase() !in SUPPORTED_COUNTRIES) return@coroutineScope false
if (siteSettings.currencyCode.lowercase() !in SUPPORTED_CURRENCIES) return@coroutineScope false

return@coroutineScope true
}

private suspend fun getOrFetchPaymentAccount(
selectedSite: SiteModel,
ippPlugin: WCInPersonPaymentsStore.InPersonPaymentsPluginType
): WCPaymentAccountResult? {
paymentAccountCache[selectedSite.id]?.let { return it }

val paymentsAccount = ippStore.loadAccount(
ippPlugin,
selectedSite
)

return paymentsAccount.model?.also { paymentAccountCache[selectedSite.id] = it }
}

private fun isIPPOnboardingCompleted(onboardingStatus: CardReaderOnboardingState): Boolean =
when (onboardingStatus) {
CardReaderOnboardingState.ChoosePaymentGatewayProvider,
Expand Down Expand Up @@ -100,5 +79,8 @@ class WooPosIsEnabled @Inject constructor(

private companion object {
const val WC_VERSION_SUPPORTS_ORDER_AUTO_DRAFTS_AND_EXTRA_PAYMENTS_PROPS = "6.6.0"

val SUPPORTED_COUNTRIES = listOf("us")
val SUPPORTED_CURRENCIES = listOf("usd")
}
}
2 changes: 1 addition & 1 deletion WooCommerce/src/main/res/navigation/nav_graph_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
app:destination="@id/nav_graph_coupons" />
<action
android:id="@+id/action_moreMenu_to_paymentFlow"
app:destination="@id/paymentFlow"
app:destination="@id/nav_graph_payment_flow"
app:enterAnim="@null">
<argument
android:name="cardReaderFlowParam"
Expand Down
2 changes: 1 addition & 1 deletion WooCommerce/src/main/res/navigation/nav_graph_orders.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
app:destination="@id/billingAddressEditingFragment" />
<action
android:id="@+id/action_orderDetailFragment_to_cardReaderFlow"
app:destination="@id/paymentFlow">
app:destination="@id/nav_graph_payment_flow">
<argument
android:name="cardReaderFlowParam"
app:argType="com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam"
Expand Down
43 changes: 42 additions & 1 deletion WooCommerce/src/main/res/navigation/nav_graph_payment_flow.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/paymentFlow"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph_payment_flow"
app:startDestination="@id/selectPaymentMethodFragment">

<include app:graph="@navigation/nav_graph_order_creations" />
Expand Down Expand Up @@ -383,4 +384,44 @@
app:nullable="false" />
</dialog>

<action
android:id="@+id/action_global_WPComWebViewFragment"
app:destination="@id/WPComWebViewFragment" />

<fragment
android:id="@+id/WPComWebViewFragment"
android:name="com.woocommerce.android.ui.common.wpcomwebview.WPComWebViewFragment"
android:label="WPComWebViewFragment"
tools:layout="@layout/fragment_wpcom_webview">
<argument
android:name="urlToLoad"
app:argType="string" />
<argument
android:name="title"
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
<argument
android:name="urlsToTriggerExit"
android:defaultValue="@null"
app:argType="string[]"
app:nullable="true" />
<argument
android:name="captureBackButton"
android:defaultValue="true"
app:argType="boolean" />
<argument
android:name="displayMode"
android:defaultValue="REGULAR"
app:argType="com.woocommerce.android.ui.common.wpcomwebview.WPComWebViewViewModel$DisplayMode" />
<argument
android:name="urlComparisonMode"
android:defaultValue="PARTIAL"
app:argType="com.woocommerce.android.ui.common.wpcomwebview.WPComWebViewViewModel$UrlComparisonMode" />
<argument
android:name="clearCache"
android:defaultValue="false"
app:argType="boolean" />
</fragment>

</navigation>
2 changes: 1 addition & 1 deletion WooCommerce/src/main/res/navigation/nav_graph_refunds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
android:label="RefundConfirmationDialog" >
<action
android:id="@+id/action_refundConfirmationDialog_to_cardReaderFlow"
app:destination="@id/paymentFlow"
app:destination="@id/nav_graph_payment_flow"
app:popUpTo="@+id/refundConfirmationDialog"
app:popUpToInclusive="true">
<argument
Expand Down
Loading

0 comments on commit 6393c4f

Please sign in to comment.