|
1 | 1 | package com.woocommerce.android.ui.payments.receipt
|
2 | 2 |
|
3 | 3 | import com.woocommerce.android.AppPrefsWrapper
|
| 4 | +import com.woocommerce.android.BuildConfig |
4 | 5 | import com.woocommerce.android.extensions.semverCompareTo
|
5 | 6 | import com.woocommerce.android.tools.SelectedSite
|
6 | 7 | import com.woocommerce.android.ui.payments.cardreader.onboarding.PluginType
|
7 |
| -import kotlinx.coroutines.Dispatchers |
8 |
| -import kotlinx.coroutines.withContext |
9 | 8 | import org.wordpress.android.fluxc.model.SiteModel
|
10 | 9 | import org.wordpress.android.fluxc.store.WCOrderStore
|
11 | 10 | import org.wordpress.android.fluxc.store.WooCommerceStore
|
@@ -72,16 +71,29 @@ class PaymentReceiptHelper @Inject constructor(
|
72 | 71 | }
|
73 | 72 | }
|
74 | 73 |
|
75 |
| - private suspend fun isWCCanGenerateReceipts() = |
76 |
| - withContext(Dispatchers.IO) { |
77 |
| - val currentWooCoreVersion = |
78 |
| - wooCommerceStore.getSitePlugin( |
79 |
| - selectedSite.get(), |
80 |
| - WooCommerceStore.WooPlugin.WOO_CORE |
81 |
| - )?.version ?: return@withContext false |
| 74 | + private suspend fun isWCCanGenerateReceipts(): Boolean { |
| 75 | + val currentWooCoreVersion = getWoocommerceCorePluginVersion() |
82 | 76 |
|
83 |
| - currentWooCoreVersion.semverCompareTo(WC_CAN_GENERATE_RECEIPTS_VERSION) >= 0 |
84 |
| - } |
| 77 | + return currentWooCoreVersion.semverCompareTo(WC_CAN_GENERATE_RECEIPTS_VERSION) >= 0 |
| 78 | + } |
| 79 | + |
| 80 | + private suspend fun getWoocommerceCorePluginVersion(): String { |
| 81 | + val sitePlugin = wooCommerceStore.getSitePlugin( |
| 82 | + selectedSite.get(), |
| 83 | + WooCommerceStore.WooPlugin.WOO_CORE |
| 84 | + ) |
| 85 | + return if (sitePlugin == null) { |
| 86 | + if (BuildConfig.DEBUG) { |
| 87 | + wooCommerceStore.getSitePlugins(selectedSite.get()) |
| 88 | + .firstOrNull { it.name == "woocommerce-dev/woocommerce" } |
| 89 | + ?.let { it.version } |
| 90 | + } else { |
| 91 | + "" |
| 92 | + } |
| 93 | + } else { |
| 94 | + sitePlugin.version |
| 95 | + } ?: "" |
| 96 | + } |
85 | 97 |
|
86 | 98 | private companion object {
|
87 | 99 | const val WCPAY_RECEIPTS_SENDING_SUPPORT_VERSION = "4.0.0"
|
|
0 commit comments