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 2 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 @@ -59,7 +59,7 @@ internal class SavedPaymentMethodMutator(
isNotPaymentFlow: Boolean,
) {
val defaultPaymentMethodId: StateFlow<String?> = customerStateHolder.customer.mapAsStateFlow { customerState ->
customerState?.defaultPaymentMethodId
customerState?.getDefaultPaymentMethodId()
}

private val paymentOptionsItemsMapper: PaymentOptionsItemsMapper by lazy {
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 All @@ -14,7 +15,7 @@ internal data class CustomerState(
val customerSessionClientSecret: String?,
val paymentMethods: List<PaymentMethod>,
val permissions: Permissions,
val defaultPaymentMethodId: String?
private val defaultPaymentMethodId: String?
) : Parcelable {
@Parcelize
data class Permissions(
Expand All @@ -23,6 +24,14 @@ internal data class CustomerState(
val canRemoveDuplicates: Boolean,
) : Parcelable

fun getDefaultPaymentMethodId(): String? {
tianzhao-stripe marked this conversation as resolved.
Show resolved Hide resolved
return if (FeatureFlags.enableDefaultPaymentMethods.isEnabled) {
this.defaultPaymentMethodId
} else {
null
}
}

internal companion object {
/**
* Creates a [CustomerState] instance using an [ElementsSession.Customer] response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class PaymentOptionsItemsMapper(
paymentMethods = customerState?.paymentMethods ?: listOf(),
isLinkEnabled = isLinkEnabled,
isGooglePayReady = isGooglePayReady,
defaultPaymentMethodId = customerState?.defaultPaymentMethodId
defaultPaymentMethodId = customerState?.getDefaultPaymentMethodId()
) ?: emptyList()
}
}
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 @@ -163,7 +173,13 @@ class CustomerStateTest {
canRemoveDuplicates = true,
)
)
assertThat(customerState.defaultPaymentMethodId).isEqualTo(defaultPaymentMethodId)
assertThat(customerState.getDefaultPaymentMethodId()).isEqualTo(defaultPaymentMethodId)

enableDefaultPaymentMethods.setEnabled(false)
assertThat(customerState.getDefaultPaymentMethodId()).isNull()

enableDefaultPaymentMethods.setEnabled(true)
assertThat(customerState.getDefaultPaymentMethodId()).isEqualTo(defaultPaymentMethodId)
tianzhao-stripe marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
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("Default Payment Method")
}

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