Skip to content

Commit

Permalink
Remove local feature flag for Instant Debits
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed May 6, 2024
1 parent 45eed69 commit 468565f
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@ import androidx.compose.ui.test.isEnabled
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.core.utils.FeatureFlags
import com.stripe.android.paymentsheet.example.playground.settings.AutomaticPaymentMethodsSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.Country
import com.stripe.android.paymentsheet.example.playground.settings.CountrySettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.Currency
import com.stripe.android.paymentsheet.example.playground.settings.CurrencySettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.DefaultBillingAddress
import com.stripe.android.paymentsheet.example.playground.settings.DefaultBillingAddressSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.EnableInstantDebitsSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.LinkSettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.SupportedPaymentMethodsSettingsDefinition
import com.stripe.android.paymentsheet.ui.PAYMENT_SHEET_PRIMARY_BUTTON_TEST_TAG
import com.stripe.android.test.core.AuthorizeAction
import com.stripe.android.test.core.TestParameters
import com.stripe.android.test.core.ui.ComposeButton
import com.stripe.android.testing.FeatureFlagTestRule
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

Expand All @@ -39,15 +35,8 @@ internal class TestInstantDebits : BasePlaygroundTest() {
settings[DefaultBillingAddressSettingsDefinition] = DefaultBillingAddress.On
settings[LinkSettingsDefinition] = true
settings[SupportedPaymentMethodsSettingsDefinition] = listOf("card", "link")
settings[EnableInstantDebitsSettingsDefinition] = true
}

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

@Test
@Ignore
fun testInstantDebitsSuccess() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.stripe.android.paymentsheet.example.playground.settings

import com.stripe.android.core.utils.FeatureFlags
import com.stripe.android.paymentsheet.example.playground.model.CheckoutRequest

internal object EnableInstantDebitsSettingsDefinition : BooleanSettingsDefinition(
Expand All @@ -10,11 +9,8 @@ internal object EnableInstantDebitsSettingsDefinition : BooleanSettingsDefinitio
) {

override fun configure(value: Boolean, checkoutRequestBuilder: CheckoutRequest.Builder) {
// Hijacking this method to synchronize the setting with the feature flag
FeatureFlags.instantDebits.setEnabled(value)
}

override fun valueUpdated(value: Boolean, playgroundSettings: PlaygroundSettings) {
FeatureFlags.instantDebits.setEnabled(value)
if (value) {
checkoutRequestBuilder.supportedPaymentMethods(listOf("card", "link"))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.stripe.android.lpmfoundations.paymentmethod

import com.stripe.android.core.utils.FeatureFlags
import com.stripe.android.model.PaymentIntent
import com.stripe.android.model.PaymentMethod.Type.USBankAccount

Expand Down Expand Up @@ -64,8 +63,7 @@ internal enum class AddPaymentMethodRequirement {
val noUsBankAccount = USBankAccount.code !in paymentMethodTypes
val supportsBankAccounts = "bank_account" in metadata.stripeIntent.linkFundingSources
val isDeferred = metadata.stripeIntent.clientSecret == null
val isEnabled = FeatureFlags.instantDebits.isEnabled
return noUsBankAccount && supportsBankAccounts && !isDeferred && isEnabled
return noUsBankAccount && supportsBankAccounts && !isDeferred
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
package com.stripe.android.lpmfoundations.paymentmethod

import com.google.common.truth.Truth.assertThat
import com.stripe.android.core.utils.FeatureFlags
import com.stripe.android.lpmfoundations.paymentmethod.AddPaymentMethodRequirement.InstantDebits
import com.stripe.android.model.Address
import com.stripe.android.model.PaymentIntent
import com.stripe.android.model.PaymentIntentFixtures
import com.stripe.android.model.SetupIntentFixtures
import com.stripe.android.model.StripeIntent
import com.stripe.android.testing.FeatureFlagTestRule
import com.stripe.android.testing.PaymentIntentFactory
import org.junit.Rule
import org.junit.Test

internal class AddPaymentMethodRequirementTest {

@get:Rule
val instantDebitsFeatureRule = FeatureFlagTestRule(
featureFlag = FeatureFlags.instantDebits,
isEnabled = false,
)

@Test
fun testUnsupportedReturnsFalse() {
val metadata = PaymentMethodMetadataFactory.create()
Expand Down Expand Up @@ -171,30 +162,15 @@ internal class AddPaymentMethodRequirementTest {

@Test
fun testInstantDebitsReturnsTrue() {
instantDebitsFeatureRule.setEnabled(true)

val metadata = PaymentMethodMetadataFactory.create(
stripeIntent = createValidInstantDebitsPaymentIntent(),
)

assertThat(InstantDebits.isMetBy(metadata)).isTrue()
}

@Test
fun testInstantDebitsReturnsFalseIfFeatureNotEnabled() {
instantDebitsFeatureRule.setEnabled(false)

val metadata = PaymentMethodMetadataFactory.create(
stripeIntent = createValidInstantDebitsPaymentIntent(),
)

assertThat(InstantDebits.isMetBy(metadata)).isFalse()
}

@Test
fun testInstantDebitsReturnsFalseIfDeferredIntent() {
instantDebitsFeatureRule.setEnabled(true)

val metadata = PaymentMethodMetadataFactory.create(
stripeIntent = createValidInstantDebitsPaymentIntent().copy(
clientSecret = null,
Expand All @@ -206,8 +182,6 @@ internal class AddPaymentMethodRequirementTest {

@Test
fun testInstantDebitsReturnsFalseIfShowingUsBankAccount() {
instantDebitsFeatureRule.setEnabled(true)

val metadata = PaymentMethodMetadataFactory.create(
stripeIntent = createValidInstantDebitsPaymentIntent().copy(
paymentMethodTypes = listOf("card", "link", "us_bank_account"),
Expand All @@ -219,8 +193,6 @@ internal class AddPaymentMethodRequirementTest {

@Test
fun testInstantDebitsReturnsFalseIfOnlyCardFundingSource() {
instantDebitsFeatureRule.setEnabled(true)

val metadata = PaymentMethodMetadataFactory.create(
stripeIntent = createValidInstantDebitsPaymentIntent().copy(
linkFundingSources = listOf("card"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import androidx.annotation.RestrictTo
import com.stripe.android.core.BuildConfig

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
@Suppress("unused")
object FeatureFlags {
val instantDebits = FeatureFlag()
// Add any feature flags here
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
Expand Down

0 comments on commit 468565f

Please sign in to comment.