From 8c69d084c77fa43d15d9bd8c1ebc4acdbab5ec8b Mon Sep 17 00:00:00 2001 From: toluo-stripe Date: Tue, 7 Jan 2025 17:03:13 -0500 Subject: [PATCH] Refactor Link `shippingValues` to use `AddressDetails` (#9869) --- .../java/com/stripe/android/link/LinkConfiguration.kt | 4 ++-- .../android/paymentsheet/state/PaymentElementLoader.kt | 9 +-------- .../com/stripe/android/link/LinkActivityContractTest.kt | 4 ++-- .../android/link/LinkConfigurationCoordinatorTest.kt | 2 +- .../src/test/java/com/stripe/android/link/TestFactory.kt | 2 +- .../link/account/DefaultLinkAccountManagerTest.kt | 2 +- .../android/link/serialization/PopupPayloadTest.kt | 2 +- .../android/link/ui/inline/InlineSignupViewModelTest.kt | 4 ++-- .../android/link/ui/inline/InlineSignupViewStateTest.kt | 2 +- .../stripe/android/link/ui/signup/SignUpScreenTest.kt | 2 +- .../paymentmethod/PaymentMethodMetadataTest.kt | 2 +- .../paymentmethod/definitions/CardDefinitionTest.kt | 2 +- .../confirmation/ConfirmationHandlerOptionKtxTest.kt | 2 +- .../confirmation/link/LinkConfirmationActivityTest.kt | 2 +- .../confirmation/link/LinkConfirmationDefinitionTest.kt | 2 +- .../confirmation/link/LinkConfirmationFlowTest.kt | 2 +- .../com/stripe/android/paymentsheet/LinkHandlerTest.kt | 2 +- .../android/paymentsheet/PaymentSheetViewModelTest.kt | 4 ++-- .../state/DefaultPaymentElementLoaderTest.kt | 4 ++-- .../stripe/android/paymentsheet/utils/LinkTestUtils.kt | 2 +- 20 files changed, 25 insertions(+), 32 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/link/LinkConfiguration.kt b/paymentsheet/src/main/java/com/stripe/android/link/LinkConfiguration.kt index ae530276d3c..b28a67c81b8 100644 --- a/paymentsheet/src/main/java/com/stripe/android/link/LinkConfiguration.kt +++ b/paymentsheet/src/main/java/com/stripe/android/link/LinkConfiguration.kt @@ -2,7 +2,7 @@ package com.stripe.android.link import android.os.Parcelable import com.stripe.android.model.StripeIntent -import com.stripe.android.uicore.elements.IdentifierSpec +import com.stripe.android.paymentsheet.addresselement.AddressDetails import kotlinx.parcelize.Parcelize @Parcelize @@ -11,7 +11,7 @@ internal data class LinkConfiguration( val merchantName: String, val merchantCountryCode: String?, val customerInfo: CustomerInfo, - val shippingValues: Map?, + val shippingDetails: AddressDetails?, val passthroughModeEnabled: Boolean, val flags: Map, val cardBrandChoice: CardBrandChoice?, diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentElementLoader.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentElementLoader.kt index e35e23e351e..b15f2361857 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentElementLoader.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/PaymentElementLoader.kt @@ -27,7 +27,6 @@ import com.stripe.android.paymentsheet.PaymentSheet import com.stripe.android.paymentsheet.PaymentSheet.IntentConfiguration import com.stripe.android.paymentsheet.PrefsRepository import com.stripe.android.paymentsheet.addresselement.AddressDetails -import com.stripe.android.paymentsheet.addresselement.toIdentifierMap import com.stripe.android.paymentsheet.analytics.EventReporter import com.stripe.android.paymentsheet.cvcrecollection.CvcRecollectionHandler import com.stripe.android.paymentsheet.model.PaymentIntentClientSecret @@ -471,12 +470,6 @@ internal class DefaultPaymentElementLoader @Inject constructor( configuration.defaultBillingDetails?.phone } - val shippingAddress = if (shippingDetails?.isCheckboxSelected == true) { - shippingDetails.toIdentifierMap(configuration.defaultBillingDetails) - } else { - null - } - val customerEmail = configuration.defaultBillingDetails?.email ?: customer?.let { customerRepository.retrieveCustomer( CustomerRepository.CustomerInfo( @@ -508,7 +501,7 @@ internal class DefaultPaymentElementLoader @Inject constructor( merchantName = merchantName, merchantCountryCode = merchantCountry, customerInfo = customerInfo, - shippingValues = shippingAddress, + shippingDetails = shippingDetails?.takeIf { it.isCheckboxSelected == true }, passthroughModeEnabled = passthroughModeEnabled, cardBrandChoice = cardBrandChoice, flags = flags, diff --git a/paymentsheet/src/test/java/com/stripe/android/link/LinkActivityContractTest.kt b/paymentsheet/src/test/java/com/stripe/android/link/LinkActivityContractTest.kt index 123295e8352..c26b8a80869 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/LinkActivityContractTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/LinkActivityContractTest.kt @@ -53,7 +53,7 @@ class LinkActivityContractTest { phone = "1234567890", billingCountryCode = "US", ), - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = false, flags = emptyMap(), cardBrandChoice = null, @@ -85,7 +85,7 @@ class LinkActivityContractTest { phone = "1234567890", billingCountryCode = "US", ), - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = false, flags = emptyMap(), cardBrandChoice = null, diff --git a/paymentsheet/src/test/java/com/stripe/android/link/LinkConfigurationCoordinatorTest.kt b/paymentsheet/src/test/java/com/stripe/android/link/LinkConfigurationCoordinatorTest.kt index d3ac191614b..69fe4f8cfcf 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/LinkConfigurationCoordinatorTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/LinkConfigurationCoordinatorTest.kt @@ -27,7 +27,7 @@ class LinkConfigurationCoordinatorTest { phone = CUSTOMER_PHONE, billingCountryCode = CUSTOMER_BILLING_COUNTRY_CODE, ), - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = false, flags = emptyMap(), cardBrandChoice = null, diff --git a/paymentsheet/src/test/java/com/stripe/android/link/TestFactory.kt b/paymentsheet/src/test/java/com/stripe/android/link/TestFactory.kt index 4f017404f5d..0e018b60e78 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/TestFactory.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/TestFactory.kt @@ -122,7 +122,7 @@ internal object TestFactory { phone = CUSTOMER_PHONE, billingCountryCode = CUSTOMER_BILLING_COUNTRY_CODE ), - shippingValues = null, + shippingDetails = null, flags = emptyMap(), cardBrandChoice = null, passthroughModeEnabled = false diff --git a/paymentsheet/src/test/java/com/stripe/android/link/account/DefaultLinkAccountManagerTest.kt b/paymentsheet/src/test/java/com/stripe/android/link/account/DefaultLinkAccountManagerTest.kt index a3e45820127..eba546aabb9 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/account/DefaultLinkAccountManagerTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/account/DefaultLinkAccountManagerTest.kt @@ -828,7 +828,7 @@ class DefaultLinkAccountManagerTest { ), merchantName = "Merchant", merchantCountryCode = "US", - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = passthroughModeEnabled, flags = emptyMap(), cardBrandChoice = null, diff --git a/paymentsheet/src/test/java/com/stripe/android/link/serialization/PopupPayloadTest.kt b/paymentsheet/src/test/java/com/stripe/android/link/serialization/PopupPayloadTest.kt index 3517ecc2cbf..9cebfe3e197 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/serialization/PopupPayloadTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/serialization/PopupPayloadTest.kt @@ -221,7 +221,7 @@ internal class PopupPayloadTest { ), flags = emptyMap(), passthroughModeEnabled = true, - shippingValues = emptyMap(), + shippingDetails = null, cardBrandChoice = cardBrandChoice, stripeIntent = intent ) diff --git a/paymentsheet/src/test/java/com/stripe/android/link/ui/inline/InlineSignupViewModelTest.kt b/paymentsheet/src/test/java/com/stripe/android/link/ui/inline/InlineSignupViewModelTest.kt index daa1bff53ca..1a827654b98 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/ui/inline/InlineSignupViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/ui/inline/InlineSignupViewModelTest.kt @@ -66,7 +66,7 @@ class InlineSignupViewModelTest { name = CUSTOMER_NAME, billingCountryCode = CUSTOMER_BILLING_COUNTRY_CODE, ), - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = false, flags = emptyMap(), cardBrandChoice = null, @@ -429,7 +429,7 @@ class InlineSignupViewModelTest { name = prefilledName, billingCountryCode = null, ), - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = false, flags = emptyMap(), cardBrandChoice = null, diff --git a/paymentsheet/src/test/java/com/stripe/android/link/ui/inline/InlineSignupViewStateTest.kt b/paymentsheet/src/test/java/com/stripe/android/link/ui/inline/InlineSignupViewStateTest.kt index 38bfa103869..d2041b88cf5 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/ui/inline/InlineSignupViewStateTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/ui/inline/InlineSignupViewStateTest.kt @@ -91,7 +91,7 @@ class InlineSignupViewStateTest { phone = "+15555555555", billingCountryCode = "usd", ), - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = false, flags = emptyMap(), cardBrandChoice = null, diff --git a/paymentsheet/src/test/java/com/stripe/android/link/ui/signup/SignUpScreenTest.kt b/paymentsheet/src/test/java/com/stripe/android/link/ui/signup/SignUpScreenTest.kt index 8d106596f88..2b1d25e7e01 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/ui/signup/SignUpScreenTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/ui/signup/SignUpScreenTest.kt @@ -43,7 +43,7 @@ internal class SignUpScreenTest { merchantCountryCode = "US", passthroughModeEnabled = false, cardBrandChoice = null, - shippingValues = mapOf(), + shippingDetails = null, ) private val linkAccountManager = FakeLinkAccountManager() private val linkEventsReporter = object : FakeLinkEventsReporter() { diff --git a/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataTest.kt b/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataTest.kt index ad813b2c75a..49b6578e057 100644 --- a/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/PaymentMethodMetadataTest.kt @@ -1303,7 +1303,7 @@ internal class PaymentMethodMetadataTest { ), merchantName = "Merchant Inc.", merchantCountryCode = "CA", - shippingValues = mapOf(), + shippingDetails = null, flags = mapOf(), cardBrandChoice = LinkConfiguration.CardBrandChoice( eligible = true, diff --git a/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/definitions/CardDefinitionTest.kt b/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/definitions/CardDefinitionTest.kt index 66dfe7a8d07..7eedf7e7591 100644 --- a/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/definitions/CardDefinitionTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/lpmfoundations/paymentmethod/definitions/CardDefinitionTest.kt @@ -171,7 +171,7 @@ class CardDefinitionTest { flags = mapOf(), passthroughModeEnabled = false, cardBrandChoice = null, - shippingValues = mapOf() + shippingDetails = null ) } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/ConfirmationHandlerOptionKtxTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/ConfirmationHandlerOptionKtxTest.kt index a22b28f04b9..8315bedee53 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/ConfirmationHandlerOptionKtxTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/ConfirmationHandlerOptionKtxTest.kt @@ -360,7 +360,7 @@ class ConfirmationHandlerOptionKtxTest { phone = null, billingCountryCode = "CA", ), - shippingValues = mapOf(), + shippingDetails = null, passthroughModeEnabled = false, cardBrandChoice = null, flags = mapOf() diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationActivityTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationActivityTest.kt index ff26070eeb1..f0fcf506935 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationActivityTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationActivityTest.kt @@ -222,7 +222,7 @@ internal class LinkConfirmationActivityTest(private val nativeLinkEnabled: Boole phone = "+1234567890", billingCountryCode = "CA", ), - shippingValues = mapOf(), + shippingDetails = null, passthroughModeEnabled = false, flags = mapOf(), cardBrandChoice = null, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationDefinitionTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationDefinitionTest.kt index c11bc2f2a8b..cdf789e2367 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationDefinitionTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationDefinitionTest.kt @@ -278,7 +278,7 @@ internal class LinkConfirmationDefinitionTest { phone = "+1123456789", billingCountryCode = "CA" ), - shippingValues = mapOf(), + shippingDetails = null, passthroughModeEnabled = false, flags = mapOf(), cardBrandChoice = null, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationFlowTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationFlowTest.kt index 8261b49be8d..3688b4cadd8 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationFlowTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentelement/confirmation/link/LinkConfirmationFlowTest.kt @@ -156,7 +156,7 @@ class LinkConfirmationFlowTest { phone = "+1123456789", billingCountryCode = "CA" ), - shippingValues = mapOf(), + shippingDetails = null, passthroughModeEnabled = false, flags = mapOf(), cardBrandChoice = null, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/LinkHandlerTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/LinkHandlerTest.kt index f4998571575..8b4b60c1cf6 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/LinkHandlerTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/LinkHandlerTest.kt @@ -562,7 +562,7 @@ private fun defaultLinkConfiguration( phone = "1234567890", billingCountryCode = "US", ), - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = false, cardBrandChoice = null, flags = emptyMap(), diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt index b28d34f3b5d..f7923335c84 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/PaymentSheetViewModelTest.kt @@ -948,7 +948,7 @@ internal class PaymentSheetViewModelTest { merchantCountryCode = "US", passthroughModeEnabled = false, cardBrandChoice = null, - shippingValues = mapOf(), + shippingDetails = null, ) val viewModel = createViewModel( @@ -3335,7 +3335,7 @@ internal class PaymentSheetViewModelTest { phone = null, billingCountryCode = "US", ), - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = false, cardBrandChoice = null, flags = emptyMap() diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentElementLoaderTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentElementLoaderTest.kt index 7372a3625e5..ce4895ea34e 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentElementLoaderTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/DefaultPaymentElementLoaderTest.kt @@ -579,7 +579,7 @@ internal class DefaultPaymentElementLoaderTest { phone = null, billingCountryCode = "CA", ), - shippingValues = null, + shippingDetails = null, passthroughModeEnabled = false, cardBrandChoice = null, flags = emptyMap(), @@ -606,7 +606,7 @@ internal class DefaultPaymentElementLoaderTest { initializedViaCompose = false, ).getOrThrow() - assertThat(result.linkState?.configuration?.shippingValues).isNotNull() + assertThat(result.linkState?.configuration?.shippingDetails).isNotNull() } @Test diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/utils/LinkTestUtils.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/utils/LinkTestUtils.kt index 62aa69e92a3..856a6f908b0 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/utils/LinkTestUtils.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/utils/LinkTestUtils.kt @@ -59,7 +59,7 @@ internal object LinkTestUtils { merchantCountryCode = "US", passthroughModeEnabled = false, cardBrandChoice = null, - shippingValues = mapOf(), + shippingDetails = null, ) } }