Skip to content

Commit

Permalink
Refactor Link shippingValues to use AddressDetails (#9869)
Browse files Browse the repository at this point in the history
  • Loading branch information
toluo-stripe authored Jan 7, 2025
1 parent a23d0a6 commit 8c69d08
Show file tree
Hide file tree
Showing 20 changed files with 25 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -11,7 +11,7 @@ internal data class LinkConfiguration(
val merchantName: String,
val merchantCountryCode: String?,
val customerInfo: CustomerInfo,
val shippingValues: Map<IdentifierSpec, String?>?,
val shippingDetails: AddressDetails?,
val passthroughModeEnabled: Boolean,
val flags: Map<String, Boolean>,
val cardBrandChoice: CardBrandChoice?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LinkActivityContractTest {
phone = "1234567890",
billingCountryCode = "US",
),
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = false,
flags = emptyMap(),
cardBrandChoice = null,
Expand Down Expand Up @@ -85,7 +85,7 @@ class LinkActivityContractTest {
phone = "1234567890",
billingCountryCode = "US",
),
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = false,
flags = emptyMap(),
cardBrandChoice = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LinkConfigurationCoordinatorTest {
phone = CUSTOMER_PHONE,
billingCountryCode = CUSTOMER_BILLING_COUNTRY_CODE,
),
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = false,
flags = emptyMap(),
cardBrandChoice = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ class DefaultLinkAccountManagerTest {
),
merchantName = "Merchant",
merchantCountryCode = "US",
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = passthroughModeEnabled,
flags = emptyMap(),
cardBrandChoice = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ internal class PopupPayloadTest {
),
flags = emptyMap(),
passthroughModeEnabled = true,
shippingValues = emptyMap(),
shippingDetails = null,
cardBrandChoice = cardBrandChoice,
stripeIntent = intent
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class InlineSignupViewModelTest {
name = CUSTOMER_NAME,
billingCountryCode = CUSTOMER_BILLING_COUNTRY_CODE,
),
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = false,
flags = emptyMap(),
cardBrandChoice = null,
Expand Down Expand Up @@ -429,7 +429,7 @@ class InlineSignupViewModelTest {
name = prefilledName,
billingCountryCode = null,
),
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = false,
flags = emptyMap(),
cardBrandChoice = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class InlineSignupViewStateTest {
phone = "+15555555555",
billingCountryCode = "usd",
),
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = false,
flags = emptyMap(),
cardBrandChoice = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,7 @@ internal class PaymentMethodMetadataTest {
),
merchantName = "Merchant Inc.",
merchantCountryCode = "CA",
shippingValues = mapOf(),
shippingDetails = null,
flags = mapOf(),
cardBrandChoice = LinkConfiguration.CardBrandChoice(
eligible = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class CardDefinitionTest {
flags = mapOf(),
passthroughModeEnabled = false,
cardBrandChoice = null,
shippingValues = mapOf()
shippingDetails = null
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class ConfirmationHandlerOptionKtxTest {
phone = null,
billingCountryCode = "CA",
),
shippingValues = mapOf(),
shippingDetails = null,
passthroughModeEnabled = false,
cardBrandChoice = null,
flags = mapOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ internal class LinkConfirmationDefinitionTest {
phone = "+1123456789",
billingCountryCode = "CA"
),
shippingValues = mapOf(),
shippingDetails = null,
passthroughModeEnabled = false,
flags = mapOf(),
cardBrandChoice = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class LinkConfirmationFlowTest {
phone = "+1123456789",
billingCountryCode = "CA"
),
shippingValues = mapOf(),
shippingDetails = null,
passthroughModeEnabled = false,
flags = mapOf(),
cardBrandChoice = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ private fun defaultLinkConfiguration(
phone = "1234567890",
billingCountryCode = "US",
),
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = false,
cardBrandChoice = null,
flags = emptyMap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ internal class PaymentSheetViewModelTest {
merchantCountryCode = "US",
passthroughModeEnabled = false,
cardBrandChoice = null,
shippingValues = mapOf(),
shippingDetails = null,
)

val viewModel = createViewModel(
Expand Down Expand Up @@ -3335,7 +3335,7 @@ internal class PaymentSheetViewModelTest {
phone = null,
billingCountryCode = "US",
),
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = false,
cardBrandChoice = null,
flags = emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ internal class DefaultPaymentElementLoaderTest {
phone = null,
billingCountryCode = "CA",
),
shippingValues = null,
shippingDetails = null,
passthroughModeEnabled = false,
cardBrandChoice = null,
flags = emptyMap(),
Expand All @@ -606,7 +606,7 @@ internal class DefaultPaymentElementLoaderTest {
initializedViaCompose = false,
).getOrThrow()

assertThat(result.linkState?.configuration?.shippingValues).isNotNull()
assertThat(result.linkState?.configuration?.shippingDetails).isNotNull()
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal object LinkTestUtils {
merchantCountryCode = "US",
passthroughModeEnabled = false,
cardBrandChoice = null,
shippingValues = mapOf(),
shippingDetails = null,
)
}
}

0 comments on commit 8c69d08

Please sign in to comment.