diff --git a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/settings/PlaygroundSettings.kt b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/settings/PlaygroundSettings.kt index 5ca342b100e..49772f8f43c 100644 --- a/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/settings/PlaygroundSettings.kt +++ b/paymentsheet-example/src/main/java/com/stripe/android/paymentsheet/example/playground/settings/PlaygroundSettings.kt @@ -449,6 +449,7 @@ internal class PlaygroundSettings private constructor( LayoutSettingsDefinition, CardBrandAcceptanceSettingsDefinition, FeatureFlagSettingsDefinition(FeatureFlags.instantDebitsIncentives), + FeatureFlagSettingsDefinition(FeatureFlags.enableDefaultPaymentMethods), ) private val nonUiSettingDefinitions: List> = listOf( diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/CustomerState.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/CustomerState.kt index 6b378ebea18..8b73b3585c9 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/CustomerState.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/state/CustomerState.kt @@ -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 @@ -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 + } ) } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/CustomerStateTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/CustomerStateTest.kt index be4772577ef..a88e2de9d60 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/CustomerStateTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/state/CustomerStateTest.kt @@ -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) @@ -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, @@ -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) diff --git a/stripe-core/src/main/java/com/stripe/android/core/utils/FeatureFlags.kt b/stripe-core/src/main/java/com/stripe/android/core/utils/FeatureFlags.kt index 627d969ff2b..54de3694fea 100644 --- a/stripe-core/src/main/java/com/stripe/android/core/utils/FeatureFlags.kt +++ b/stripe-core/src/main/java/com/stripe/android/core/utils/FeatureFlags.kt @@ -8,6 +8,7 @@ object FeatureFlags { // Add any feature flags here val nativeLinkEnabled = FeatureFlag("Native Link") val instantDebitsIncentives = FeatureFlag("Instant Bank Payments Incentives") + val enableDefaultPaymentMethods = FeatureFlag("Enable Default Payment Methods") } @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)