-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link Gate to determine link launch/attest behaviour (#9956)
- Loading branch information
1 parent
6e58b87
commit 2c1ab02
Showing
13 changed files
with
285 additions
and
18 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...com/stripe/android/paymentsheet/example/playground/settings/LinkTypeSettingsDefinition.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.stripe.android.paymentsheet.example.playground.settings | ||
|
||
import com.stripe.android.core.utils.FeatureFlags | ||
|
||
internal object LinkTypeSettingsDefinition : | ||
PlaygroundSettingDefinition<LinkType>, | ||
PlaygroundSettingDefinition.Saveable<LinkType> by EnumSaveable( | ||
key = "LinkType", | ||
values = LinkType.entries.toTypedArray(), | ||
defaultValue = LinkType.Native | ||
), | ||
PlaygroundSettingDefinition.Displayable<LinkType> { | ||
override val displayName: String = "Link Type" | ||
|
||
override fun createOptions( | ||
configurationData: PlaygroundConfigurationData | ||
): List<PlaygroundSettingDefinition.Displayable.Option<LinkType>> { | ||
return listOf( | ||
option("Native", LinkType.Native), | ||
option("Native + Attest", LinkType.NativeAttest), | ||
option("Web", LinkType.Web), | ||
) | ||
} | ||
|
||
override fun setValue(value: LinkType) { | ||
when (value) { | ||
LinkType.Native -> { | ||
FeatureFlags.nativeLinkEnabled.setEnabled(true) | ||
FeatureFlags.nativeLinkAttestationEnabled.setEnabled(false) | ||
} | ||
LinkType.NativeAttest -> { | ||
FeatureFlags.nativeLinkEnabled.setEnabled(true) | ||
FeatureFlags.nativeLinkAttestationEnabled.setEnabled(true) | ||
} | ||
LinkType.Web -> { | ||
FeatureFlags.nativeLinkEnabled.setEnabled(false) | ||
FeatureFlags.nativeLinkAttestationEnabled.setEnabled(false) | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum class LinkType(override val value: String) : ValueEnum { | ||
Native("Native"), | ||
NativeAttest("Native + Attest"), | ||
Web("Web"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
paymentsheet/src/main/java/com/stripe/android/link/gate/DefaultLinkGate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.stripe.android.link.gate | ||
|
||
import com.stripe.android.core.utils.FeatureFlags | ||
import com.stripe.android.link.LinkConfiguration | ||
import javax.inject.Inject | ||
|
||
internal class DefaultLinkGate @Inject constructor( | ||
private val configuration: LinkConfiguration | ||
) : LinkGate { | ||
override val useNativeLink: Boolean | ||
get() { | ||
if (configuration.stripeIntent.isLiveMode) { | ||
return useAttestationEndpoints | ||
} | ||
return FeatureFlags.nativeLinkEnabled.isEnabled | ||
} | ||
|
||
override val useAttestationEndpoints: Boolean | ||
get() { | ||
if (configuration.stripeIntent.isLiveMode) { | ||
return configuration.useAttestationEndpointsForLink | ||
} | ||
return FeatureFlags.nativeLinkAttestationEnabled.isEnabled | ||
} | ||
|
||
class Factory @Inject constructor() : LinkGate.Factory { | ||
override fun create(configuration: LinkConfiguration): LinkGate { | ||
return DefaultLinkGate(configuration) | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
paymentsheet/src/main/java/com/stripe/android/link/gate/LinkGate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.stripe.android.link.gate | ||
|
||
import com.stripe.android.link.LinkConfiguration | ||
|
||
internal interface LinkGate { | ||
val useNativeLink: Boolean | ||
val useAttestationEndpoints: Boolean | ||
|
||
fun interface Factory { | ||
fun create(configuration: LinkConfiguration): LinkGate | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
paymentsheet/src/test/java/com/stripe/android/link/gate/DefaultLinkGateTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.stripe.android.link.gate | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import com.stripe.android.core.utils.FeatureFlags | ||
import com.stripe.android.link.TestFactory | ||
import com.stripe.android.model.PaymentIntent | ||
import com.stripe.android.model.SetupIntent | ||
import com.stripe.android.testing.FeatureFlagTestRule | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
internal class DefaultLinkGateTest { | ||
|
||
@get:Rule | ||
val nativeLinkFeatureFlagTestRule = FeatureFlagTestRule( | ||
featureFlag = FeatureFlags.nativeLinkEnabled, | ||
isEnabled = false | ||
) | ||
|
||
@get:Rule | ||
val attestationFeatureFlagTestRule = FeatureFlagTestRule( | ||
featureFlag = FeatureFlags.nativeLinkAttestationEnabled, | ||
isEnabled = false | ||
) | ||
|
||
// useNativeLink tests for test mode | ||
@Test | ||
fun `useNativeLink - test mode - returns true when feature flag enabled`() { | ||
nativeLinkFeatureFlagTestRule.setEnabled(true) | ||
val gate = gate(isLiveMode = false) | ||
|
||
assertThat(gate.useNativeLink).isTrue() | ||
} | ||
|
||
@Test | ||
fun `useNativeLink - test mode - returns false when feature flag disabled`() { | ||
nativeLinkFeatureFlagTestRule.setEnabled(false) | ||
val gate = gate(isLiveMode = false) | ||
|
||
assertThat(gate.useNativeLink).isFalse() | ||
} | ||
|
||
// useNativeLink tests for live mode | ||
@Test | ||
fun `useNativeLink - live mode - returns true when attestation enabled`() { | ||
val gate = gate(isLiveMode = true, useAttestationEndpoints = true) | ||
|
||
assertThat(gate.useNativeLink).isTrue() | ||
} | ||
|
||
@Test | ||
fun `useNativeLink - live mode - returns false when attestation disabled`() { | ||
val gate = gate(isLiveMode = true, useAttestationEndpoints = false) | ||
|
||
assertThat(gate.useNativeLink).isFalse() | ||
} | ||
|
||
// useAttestationEndpoints tests for test mode | ||
@Test | ||
fun `useAttestationEndpoints - test mode - returns true when feature flag enabled`() { | ||
attestationFeatureFlagTestRule.setEnabled(true) | ||
val gate = gate(isLiveMode = false) | ||
|
||
assertThat(gate.useAttestationEndpoints).isTrue() | ||
} | ||
|
||
@Test | ||
fun `useAttestationEndpoints - test mode - returns false when feature flag disabled`() { | ||
attestationFeatureFlagTestRule.setEnabled(false) | ||
val gate = gate(isLiveMode = false) | ||
|
||
assertThat(gate.useAttestationEndpoints).isFalse() | ||
} | ||
|
||
// useAttestationEndpoints tests for live mode | ||
@Test | ||
fun `useAttestationEndpoints - live mode - returns true when configuration enabled`() { | ||
val gate = gate(isLiveMode = true, useAttestationEndpoints = true) | ||
|
||
assertThat(gate.useAttestationEndpoints).isTrue() | ||
} | ||
|
||
@Test | ||
fun `useAttestationEndpoints - live mode - returns false when configuration disabled`() { | ||
val gate = gate(isLiveMode = true, useAttestationEndpoints = false) | ||
|
||
assertThat(gate.useAttestationEndpoints).isFalse() | ||
} | ||
|
||
// Feature flag independence tests | ||
@Test | ||
fun `useNativeLink - test mode - not affected by attestation feature flag`() { | ||
nativeLinkFeatureFlagTestRule.setEnabled(true) | ||
attestationFeatureFlagTestRule.setEnabled(false) | ||
val gate = gate(isLiveMode = false) | ||
|
||
assertThat(gate.useNativeLink).isTrue() | ||
} | ||
|
||
@Test | ||
fun `useAttestationEndpoints - test mode - not affected by native link feature flag`() { | ||
attestationFeatureFlagTestRule.setEnabled(true) | ||
nativeLinkFeatureFlagTestRule.setEnabled(false) | ||
val gate = gate(isLiveMode = false) | ||
|
||
assertThat(gate.useAttestationEndpoints).isTrue() | ||
} | ||
|
||
private fun gate( | ||
isLiveMode: Boolean = true, | ||
useAttestationEndpoints: Boolean = true | ||
): DefaultLinkGate { | ||
val newIntent = when (val intent = TestFactory.LINK_CONFIGURATION.stripeIntent) { | ||
is PaymentIntent -> { | ||
intent.copy(isLiveMode = isLiveMode) | ||
} | ||
is SetupIntent -> { | ||
intent.copy(isLiveMode = isLiveMode) | ||
} | ||
else -> intent | ||
} | ||
return DefaultLinkGate( | ||
configuration = TestFactory.LINK_CONFIGURATION.copy( | ||
useAttestationEndpointsForLink = useAttestationEndpoints, | ||
stripeIntent = newIntent | ||
) | ||
) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
paymentsheet/src/test/java/com/stripe/android/link/gate/FakeLinkGate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.stripe.android.link.gate | ||
|
||
internal class FakeLinkGate : LinkGate { | ||
private var _useNativeLink = true | ||
override val useNativeLink: Boolean | ||
get() = _useNativeLink | ||
|
||
private var _useAttestationEndpoints = true | ||
override val useAttestationEndpoints: Boolean | ||
get() = _useAttestationEndpoints | ||
|
||
fun setUseNativeLink(value: Boolean) { | ||
_useNativeLink = value | ||
} | ||
|
||
fun setUseAttestationEndpoints(value: Boolean) { | ||
_useAttestationEndpoints = value | ||
} | ||
} |
Oops, something went wrong.