Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOBILESDK-2681] [MOBILESDK-2682] Default Payment Method Label Feature Flag #9844

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ internal class PlaygroundSettings private constructor(
CardBrandAcceptanceSettingsDefinition,
FeatureFlagSettingsDefinition(FeatureFlags.useNewUpdateCardScreen),
FeatureFlagSettingsDefinition(FeatureFlags.instantDebitsIncentives),
FeatureFlagSettingsDefinition(FeatureFlags.enableDefaultPaymentMethods),
)

private val nonUiSettingDefinitions: List<PlaygroundSettingDefinition<*>> = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.stripe.android.paymentsheet.state

import android.os.Parcelable
import com.stripe.android.common.model.CommonConfiguration
import com.stripe.android.core.utils.FeatureFlags
import com.stripe.android.model.ElementsSession
import com.stripe.android.model.PaymentMethod
import com.stripe.android.paymentsheet.PaymentSheet
Expand Down Expand Up @@ -66,7 +67,11 @@ internal data class CustomerState(
// Should always remove duplicates when using `customer_session`
canRemoveDuplicates = true,
),
defaultPaymentMethodId = customer.defaultPaymentMethod
defaultPaymentMethodId = if (FeatureFlags.enableDefaultPaymentMethods.isEnabled) {
customer.defaultPaymentMethod
} else {
null
}
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,26 @@ package com.stripe.android.paymentsheet.state
import com.google.common.truth.Truth.assertThat
import com.stripe.android.common.model.CommonConfiguration
import com.stripe.android.common.model.asCommonConfiguration
import com.stripe.android.core.utils.FeatureFlags
import com.stripe.android.model.ElementsSession
import com.stripe.android.model.PaymentMethod
import com.stripe.android.model.PaymentMethodFixtures
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.PaymentSheetFixtures
import com.stripe.android.testing.FeatureFlagTestRule
import com.stripe.android.testing.PaymentMethodFactory
import kotlinx.coroutines.test.runTest
import org.junit.Rule
import org.junit.Test

class CustomerStateTest {

@get:Rule
val enableDefaultPaymentMethods = FeatureFlagTestRule(
featureFlag = FeatureFlags.enableDefaultPaymentMethods,
isEnabled = true,
)

@Test
fun `Should create 'CustomerState' for customer session properly with permissions disabled`() {
val paymentMethods = PaymentMethodFactory.cards(4)
Expand Down Expand Up @@ -125,18 +135,17 @@ class CustomerStateTest {
)
}

@Test
fun `Should create 'CustomerState' for customer session properly with nonnull defaultPaymentMethodId`() {
private fun createCustomerSessionForTestingDefaultPaymentMethod(defaultPaymentMethodId: String?): CustomerState {
val customerId = "cus_3"
val ephemeralKeySecret = "ek_3"
val paymentMethods = PaymentMethodFactory.cards(3)

val mobilePaymentElementComponent = ElementsSession.Customer.Components.MobilePaymentElement.Enabled(
isPaymentMethodSaveEnabled = false,
isPaymentMethodRemoveEnabled = false,
canRemoveLastPaymentMethod = false,
allowRedisplayOverride = null,
)
val defaultPaymentMethodId = "aaa111"
val customer = createElementsSessionCustomer(
customerId = customerId,
ephemeralKeySecret = ephemeralKeySecret,
Expand All @@ -152,20 +161,57 @@ class CustomerStateTest {
customerSessionClientSecret = "cuss_123",
)

assertThat(customerState.id).isEqualTo(customerId)
assertThat(customerState.ephemeralKeySecret).isEqualTo(ephemeralKeySecret)
assertThat(customerState.paymentMethods).isEqualTo(paymentMethods)
assertThat(customerState.permissions).isEqualTo(
CustomerState.Permissions(
canRemovePaymentMethods = false,
canRemoveLastPaymentMethod = false,
// Always true for `customer_session`
canRemoveDuplicates = true,
)
return customerState
}

@Test
fun `Create 'CustomerState' for customer session with nonnull defaultPaymentMethodId & flag on`() {
val defaultPaymentMethodId = "aaa111"

enableDefaultPaymentMethods.setEnabled(true)
val customerState = createCustomerSessionForTestingDefaultPaymentMethod(
defaultPaymentMethodId = defaultPaymentMethodId
)

assertThat(customerState.defaultPaymentMethodId).isEqualTo(defaultPaymentMethodId)
}

@Test
fun `Create 'CustomerState' for customer session with nonnull defaultPaymentMethodId & flag off`() {
val defaultPaymentMethodId = "aaa111"

enableDefaultPaymentMethods.setEnabled(false)
val customerState = createCustomerSessionForTestingDefaultPaymentMethod(
defaultPaymentMethodId = defaultPaymentMethodId
)

assertThat(customerState.defaultPaymentMethodId).isNull()
}

@Test
fun `Create 'CustomerState' for customer session with null defaultPaymentMethodId & flag on`() {
val defaultPaymentMethodId = null

enableDefaultPaymentMethods.setEnabled(true)
val customerState = createCustomerSessionForTestingDefaultPaymentMethod(
defaultPaymentMethodId = defaultPaymentMethodId
)

assertThat(customerState.defaultPaymentMethodId).isNull()
}

@Test
fun `Create 'CustomerState' for customer session with null defaultPaymentMethodId & flag off`() {
val defaultPaymentMethodId = null

enableDefaultPaymentMethods.setEnabled(false)
val customerState = createCustomerSessionForTestingDefaultPaymentMethod(
defaultPaymentMethodId = defaultPaymentMethodId
)

assertThat(customerState.defaultPaymentMethodId).isNull()
}

@Test
fun `Should create 'CustomerState' for legacy ephemeral keys properly`() {
val paymentMethods = PaymentMethodFactory.cards(7)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ object FeatureFlags {
val nativeLinkEnabled = FeatureFlag("Native Link")
val useNewUpdateCardScreen = FeatureFlag("Enable new update card screen")
val instantDebitsIncentives = FeatureFlag("Instant Bank Payments Incentives")
val enableDefaultPaymentMethods = FeatureFlag("Enable Default Payment Methods")
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
Expand Down
Loading