From b8abd00b8f08cadb03d1d9279291fd613e9bf459 Mon Sep 17 00:00:00 2001 From: Kieran Osgood Date: Tue, 4 Aug 2026 12:20:21 +0100 Subject: [PATCH] fix(sample-android): let a guest cart take the shop market The Android sample gave a guest cart a Canadian buyer identity. A country on the buyer identity picks the market, and the market decides the currency, the address form and its labels, so the Kotlin checkout rendered a Canadian form and totalled in CAD. The Swift and React Native samples send no buyer identity for a guest, so this one now sends none either. This is flake B4: the shared E2E fixture is a United States address, and checkout-guest failed on Kotlin Android while React Native Android passed the same test. Co-Authored-By: Claude Opus 5 (1M context) Assisted-By: devx/5b4b8d5b-690a-4389-841e-039723ade1da --- .../androiddemo/cart/data/CartRepository.kt | 23 +++++++++++-------- .../cart/data/CartRepositoryTest.kt | 10 ++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/platforms/android/samples/CheckoutKitAndroidDemo/app/src/main/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepository.kt b/platforms/android/samples/CheckoutKitAndroidDemo/app/src/main/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepository.kt index c14dcb810..d6472a7d9 100644 --- a/platforms/android/samples/CheckoutKitAndroidDemo/app/src/main/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepository.kt +++ b/platforms/android/samples/CheckoutKitAndroidDemo/app/src/main/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepository.kt @@ -8,7 +8,6 @@ import com.shopify.checkoutkit.androiddemo.graphql.type.CartDeliveryInput import com.shopify.checkoutkit.androiddemo.graphql.type.CartInput import com.shopify.checkoutkit.androiddemo.graphql.type.CartLineInput import com.shopify.checkoutkit.androiddemo.graphql.type.CartLineUpdateInput -import com.shopify.checkoutkit.androiddemo.graphql.type.CountryCode import timber.log.Timber class CartRepository( @@ -82,25 +81,31 @@ class CartRepository( ) ) ), - buyerIdentity = Optional.present(buyerIdentity(demoBuyerIdentityEnabled, customerAccessToken)), + buyerIdentity = buyerIdentity(demoBuyerIdentityEnabled, customerAccessToken), delivery = delivery(demoBuyerIdentityEnabled, customerAccessToken), ) + // A guest carries nothing, so the cart takes the market of the shop. A country here + // would pick the market instead, and the market decides the currency, the address + // form and its labels. The Swift and React Native samples send nothing either. private fun buyerIdentity( demoBuyerIdentityEnabled: Boolean, customerAccessToken: String?, - ): CartBuyerIdentityInput { + ): Optional { if (customerAccessToken != null) { Timber.i("Setting a customer access token in buyer identity") - return CartBuyerIdentityInput(customerAccessToken = Optional.present(customerAccessToken)) + return Optional.present( + CartBuyerIdentityInput(customerAccessToken = Optional.present(customerAccessToken)) + ) } - return if (demoBuyerIdentityEnabled) { - Timber.i("Using demo buyer identity data to prefill checkout") - DemoBuyerIdentity.value - } else { - CartBuyerIdentityInput(countryCode = Optional.present(CountryCode.CA)) + if (!demoBuyerIdentityEnabled) { + return Optional.Absent } + + Timber.i("Using demo buyer identity data to prefill checkout") + + return Optional.present(DemoBuyerIdentity.value) } // A signed in customer picks from the addresses the account already holds, so only the diff --git a/platforms/android/samples/CheckoutKitAndroidDemo/app/src/test/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepositoryTest.kt b/platforms/android/samples/CheckoutKitAndroidDemo/app/src/test/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepositoryTest.kt index 4b0645047..ee0eeb82b 100644 --- a/platforms/android/samples/CheckoutKitAndroidDemo/app/src/test/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepositoryTest.kt +++ b/platforms/android/samples/CheckoutKitAndroidDemo/app/src/test/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepositoryTest.kt @@ -21,6 +21,16 @@ class CartRepositoryTest { assertThat(input.delivery.getOrNull()).isNull() } + // A country on the buyer identity picks the market, and the market decides the currency, + // the address form and the labels the E2E fixture types. The Swift and React Native + // samples send no buyer identity for a guest, so this one must not either. + @Test + fun `a guest supplies no buyer identity`() { + val input = cartInput(demoBuyerIdentityEnabled = false, customerAccessToken = null) + + assertThat(input.buyerIdentity.getOrNull()).isNull() + } + @Test fun `a signed in customer supplies no delivery address`() { val input = cartInput(demoBuyerIdentityEnabled = true, customerAccessToken = "token")