Modern Apps git

← Modern-Apps.git

shop: drop browser fallback buttons from checkout; Pay in app is the only handoff

Commit
4765958855cd794d68550753964407c733d2a112
Author
Vayun Mathur <[email protected]>
When
2026-11-01 20:58 UTC (1 month ago)
Parents
877c010

Diff

shop/src/main/java/com/vayunmathur/shop/domain/MerchantUrls.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/domain/MerchantUrls.kt b/shop/src/main/java/com/vayunmathur/shop/domain/MerchantUrls.ktindex 8299978c36..3bb50cc011 100644--- a/shop/src/main/java/com/vayunmathur/shop/domain/MerchantUrls.kt+++ b/shop/src/main/java/com/vayunmathur/shop/domain/MerchantUrls.kt@@ -5,19 +5,6 @@ import java.util.Locale  /** Public HTTPS URLs only; merchant input must not name local devices or app intents. */ object MerchantUrls {-    private val shopifyVariant = Regex("^gid://shopify/ProductVariant/([0-9]+)$")--    /** Shopify cart permalink that opens the store's cart with these lines already added. */-    fun shopifyCartUrl(domain: String, lines: List<Pair<String, Int>>): String? {-        val host = domain(domain) ?: return null-        if (lines.isEmpty()) return null-        val items = lines.map { (variantId, quantity) ->-            val id = shopifyVariant.find(variantId)?.groupValues?.get(1) ?: return null-            "$id:$quantity"-        }-        return httpsUrl("https://$host/cart/${items.joinToString(",")}")-    }-     fun httpsUrl(value: String): String? {         val uri = runCatching { URI(value) }.getOrNull() ?: return null         if (!uri.scheme.equals("https", ignoreCase = true) || uri.userInfo != null) return null
shop/src/main/java/com/vayunmathur/shop/ui/CheckoutScreen.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/ui/CheckoutScreen.kt b/shop/src/main/java/com/vayunmathur/shop/ui/CheckoutScreen.ktindex 67342badd6..bd0e51d8dc 100644--- a/shop/src/main/java/com/vayunmathur/shop/ui/CheckoutScreen.kt+++ b/shop/src/main/java/com/vayunmathur/shop/ui/CheckoutScreen.kt@@ -18,9 +18,7 @@ import com.vayunmathur.library.ui.Button import com.vayunmathur.library.ui.CircularProgressIndicator import com.vayunmathur.library.ui.DetailSection import com.vayunmathur.library.ui.MaterialTheme-import com.vayunmathur.library.ui.OutlinedButton import com.vayunmathur.library.ui.Text-import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.appBarScrollBehavior import com.vayunmathur.shop.R import com.vayunmathur.shop.data.CheckoutPhase@@ -81,9 +79,7 @@ fun CheckoutScreen(viewModel: ShopViewModel, onBack: () -> Unit, onPayInApp: ()                             if (state.busy) CircularProgressIndicator()                             else Text(if (checkout == null) "Create review session" else "Update review session")                         }-                        val merchantSiteUrl = MerchantUrls.domain(key.second)?.let { "https://$it" }                         val checkoutUrl = (checkout?.continueUrl ?: state.handoffUrl)?.let(MerchantUrls::httpsUrl)-                        val cartUrl = MerchantUrls.shopifyCartUrl(key.second, lines.map { it.variantId to it.quantity })                         if (checkoutUrl != null) {                             Button(                                 modifier = Modifier.fillMaxWidth(),@@ -91,13 +87,6 @@ fun CheckoutScreen(viewModel: ShopViewModel, onBack: () -> Unit, onPayInApp: ()                                     if (viewModel.openEmbeddedCheckout(key.first, key.second, checkoutUrl, dark)) onPayInApp()                                 },                             ) { Text("Pay in app") }-                            TextButton(onClick = { openContinueUrl(context, checkoutUrl) }) { Text("Open in browser") }-                        } else {-                            (cartUrl ?: merchantSiteUrl)?.let { url ->-                                OutlinedButton(modifier = Modifier.fillMaxWidth(), onClick = { openContinueUrl(context, url) }) {-                                    Text(if (url == cartUrl) "Open cart on merchant website" else "Open merchant website")-                                }-                            }                         }                     }                 }
shop/src/test/java/com/vayunmathur/shop/domain/MerchantUrlsTest.kt
diff --git a/shop/src/test/java/com/vayunmathur/shop/domain/MerchantUrlsTest.kt b/shop/src/test/java/com/vayunmathur/shop/domain/MerchantUrlsTest.ktindex f0083fc274..8a7ed7eef8 100644--- a/shop/src/test/java/com/vayunmathur/shop/domain/MerchantUrlsTest.kt+++ b/shop/src/test/java/com/vayunmathur/shop/domain/MerchantUrlsTest.kt@@ -17,13 +17,4 @@ class MerchantUrlsTest {             "https://127.0.0.1", "https://[::1]", "https://router.local", "https://store.example:8443",             "https://store.example/cart").forEach { assertNull(MerchantUrls.domain(it), it) }     }--    @Test-    fun shopifyCartPermalinkNeedsShopifyVariantIds() {-        assertEquals("https://store.example/cart/11:2,12:1",-            MerchantUrls.shopifyCartUrl("store.example", listOf("gid://shopify/ProductVariant/11" to 2, "gid://shopify/ProductVariant/12" to 1)))-        assertNull(MerchantUrls.shopifyCartUrl("store.example", listOf("gid://shopify/ProductVariant/11" to 1, "sku-12" to 1)))-        assertNull(MerchantUrls.shopifyCartUrl("localhost", listOf("gid://shopify/ProductVariant/11" to 1)))-        assertNull(MerchantUrls.shopifyCartUrl("store.example", emptyList()))-    } }