-
Notifications
You must be signed in to change notification settings - Fork 709
Add Tap to Add button in card form #12299
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
Merged
Merged
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions
10
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/CardDetailsAction.kt
This file contains hidden or 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,10 @@ | ||
| package com.stripe.android.ui.core.elements | ||
|
|
||
| import androidx.annotation.RestrictTo | ||
| import androidx.compose.runtime.Composable | ||
|
|
||
| @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
| interface CardDetailsAction { | ||
| @Composable | ||
| fun Content(enabled: Boolean) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -74,10 +74,12 @@ fun CardDetailsSectionElementUI( | |
| heading() | ||
| } | ||
| ) | ||
| ScanCardButtonUI( | ||
| enabled = enabled, | ||
| cardScanGoogleLauncher = cardScanLauncher | ||
| ) | ||
| controller.cardDetailsAction?.Content(enabled) ?: run { | ||
| ScanCardButtonUI( | ||
| enabled = enabled, | ||
| cardScanGoogleLauncher = cardScanLauncher | ||
| ) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a large refactor here we can do for |
||
| } | ||
| } | ||
| SectionElementUI( | ||
| modifier = Modifier.padding(top = 8.dp), | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,28 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="18dp" | ||
| android:height="18dp" | ||
| android:viewportWidth="18" | ||
| android:viewportHeight="18"> | ||
| <path | ||
| android:pathData="M8.559,8.559m-8.045,0a8.045,8.045 0,1 1,16.09 0a8.045,8.045 0,1 1,-16.09 0" | ||
| android:strokeWidth="1.02857" | ||
| android:strokeColor="#007AFF"/> | ||
| <path | ||
| android:pathData="M5.76,7.195L5.795,7.246C6.472,8.221 6.457,9.516 5.76,10.473" | ||
| android:strokeWidth="1.17669" | ||
| android:fillColor="#00000000" | ||
| android:strokeColor="#007AFF" | ||
| android:strokeLineCap="square"/> | ||
| <path | ||
| android:pathData="M8.184,6.181L8.544,6.872C8.645,7.065 8.724,7.268 8.78,7.479L8.832,7.675C8.871,7.821 8.898,7.969 8.914,8.119L8.957,8.517C8.983,8.766 8.978,9.017 8.941,9.264L8.867,9.757C8.824,10.043 8.739,10.321 8.615,10.582L8.202,11.453" | ||
| android:strokeWidth="1.17669" | ||
| android:fillColor="#00000000" | ||
| android:strokeColor="#007AFF" | ||
| android:strokeLineCap="square"/> | ||
| <path | ||
| android:pathData="M10.572,5.07L11.128,6.185C11.216,6.361 11.286,6.545 11.337,6.735L11.47,7.227C11.513,7.388 11.542,7.552 11.558,7.717L11.636,8.553C11.656,8.769 11.653,8.986 11.625,9.201L11.535,9.909L11.438,10.419C11.402,10.611 11.347,10.798 11.274,10.979L11.013,11.622L10.572,12.453" | ||
| android:strokeWidth="1.17669" | ||
| android:fillColor="#00000000" | ||
| android:strokeColor="#007AFF" | ||
| android:strokeLineCap="square"/> | ||
| </vector> |
This file contains hidden or 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
49 changes: 49 additions & 0 deletions
49
paymentsheet/src/main/java/com/stripe/android/common/taptoadd/TapToAddButtonUI.kt
This file contains hidden or 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,49 @@ | ||
| package com.stripe.android.common.taptoadd | ||
|
|
||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.interaction.MutableInteractionSource | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.width | ||
| import androidx.compose.material.MaterialTheme | ||
| import androidx.compose.material.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.ColorFilter | ||
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.unit.dp | ||
| import com.stripe.android.paymentsheet.R | ||
|
|
||
| @Composable | ||
| internal fun TapToButtonUI( | ||
| enabled: Boolean, | ||
| onClick: () -> Unit, | ||
| ) { | ||
| Row( | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| modifier = Modifier.clickable( | ||
| interactionSource = remember { MutableInteractionSource() }, | ||
| indication = null, | ||
| enabled = enabled, | ||
| onClick = onClick, | ||
| ), | ||
| ) { | ||
| Image( | ||
| painter = painterResource(R.drawable.stripe_ic_nfc_tap), | ||
| contentDescription = stringResource(R.string.stripe_tap_to_add_card_button_label), | ||
| colorFilter = ColorFilter.tint(MaterialTheme.colors.primary), | ||
| modifier = Modifier.width(18.dp).height(18.dp), | ||
| ) | ||
| Text( | ||
| text = stringResource(R.string.stripe_tap_to_add_card_button_label), | ||
| modifier = Modifier.padding(start = 4.dp), | ||
| color = MaterialTheme.colors.primary, | ||
| style = MaterialTheme.typography.h6, | ||
| ) | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
paymentsheet/src/main/java/com/stripe/android/common/taptoadd/TapToAddCardDetailsAction.kt
This file contains hidden or 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,15 @@ | ||
| package com.stripe.android.common.taptoadd | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import com.stripe.android.ui.core.elements.CardDetailsAction | ||
|
|
||
| internal class TapToAddCardDetailsAction( | ||
| private val tapToAddHelper: TapToAddHelper, | ||
| ) : CardDetailsAction { | ||
| @Composable | ||
| override fun Content(enabled: Boolean) { | ||
| TapToButtonUI(enabled) { | ||
| tapToAddHelper.startPaymentMethodCollection() | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
...tsheet/src/test/java/com/stripe/android/common/taptoadd/TapToAddButtonUIScreenshotTest.kt
This file contains hidden or 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,22 @@ | ||
| package com.stripe.android.common.taptoadd | ||
|
|
||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.dp | ||
| import com.stripe.android.screenshottesting.PaparazziRule | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
|
|
||
| internal class TapToAddButtonUIScreenshotTest { | ||
| @get:Rule | ||
| val paparazziRule = PaparazziRule( | ||
| boxModifier = Modifier.padding(10.dp), | ||
| ) | ||
|
|
||
| @Test | ||
| fun default() { | ||
| paparazziRule.snapshot { | ||
| TapToButtonUI(enabled = true) {} | ||
| } | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...ntsheet/src/test/java/com/stripe/android/common/taptoadd/TapToAddCardDetailsActionTest.kt
This file contains hidden or 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,48 @@ | ||
| package com.stripe.android.common.taptoadd | ||
|
|
||
| import androidx.compose.ui.test.junit4.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import com.google.common.truth.Truth.assertThat | ||
| import kotlinx.coroutines.test.runTest | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| internal class TapToAddCardDetailsActionTest { | ||
| @get:Rule | ||
| val composeTestRule = createComposeRule() | ||
|
|
||
| @Test | ||
| fun `clicking button calls startPaymentMethodCollection`() = runTest { | ||
| FakeTapToAddHelper.test { | ||
| val action = TapToAddCardDetailsAction(tapToAddHelper = helper) | ||
|
|
||
| composeTestRule.setContent { | ||
| action.Content(enabled = true) | ||
| } | ||
|
|
||
| composeTestRule.onNodeWithText("Tap to add card").performClick() | ||
|
|
||
| assertThat(collectCalls.awaitItem()).isEqualTo(Unit) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun `clicking disabled button does not call startPaymentMethodCollection`() = runTest { | ||
| FakeTapToAddHelper.test { | ||
| val action = TapToAddCardDetailsAction(tapToAddHelper = helper) | ||
|
|
||
| composeTestRule.setContent { | ||
| action.Content(enabled = false) | ||
| } | ||
|
|
||
| composeTestRule.onNodeWithText("Tap to add card").performClick() | ||
|
|
||
| // No collect calls should have been made | ||
| collectCalls.expectNoEvents() | ||
| } | ||
| } | ||
| } |
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.
why would we want to prevent launching card scan in this case? My expectation would be for TTA and automatically launching card scan to be very separate features
It would probably be confusing if someone wanted to launch card scan automatically and then enabling TTA prevented that from happening
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.
It's because TTA will be launching automatically instead of card scan. This is implemented in #12300.