-
Notifications
You must be signed in to change notification settings - Fork 663
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
Link Gate to determine link launch/attest behaviour #9956
Open
toluo-stripe
wants to merge
5
commits into
master
Choose a base branch
from
tolu/link/gate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
33e0652
Link Gate to determine link behaviour
toluo-stripe 7ef4623
Use link gate in LinkActivityContract
toluo-stripe 9cf5f37
Change playground display name
toluo-stripe e5b35fb
Fix lint
toluo-stripe e0a2654
Add live mode logic
toluo-stripe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the advantage of keeping track of
useNativeLink
separately fromuseAttestationEndpoints
if useNativeLink's value is equal to useAttestationEndpoints value?ie is "native" link as opposed to "native + attest" going to exist in production? And if not, do we need to test it now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Native link without attestation will be the default in test-mode (there's no need to attest in this scenario). Since
useAttestationEndpoints
could be false in test mode, we'll useuseNativeLink
for theLinkActivityContract
. This PR doesn't reflect the test mode logic. I'll push an update.