-
Notifications
You must be signed in to change notification settings - Fork 659
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
Compose credit element #4358
Merged
Merged
Compose credit element #4358
Changes from 70 commits
Commits
Show all changes
127 commits
Select commit
Hold shift + click to select a range
c5ef5ec
[WIP]
michelleb-stripe 0c95106
Display and receive input for Credit Card number and CVC.
michelleb-stripe 75e54d1
Add in the credit billing fields, need hidden visibility to work on a…
michelleb-stripe cd4ff51
Merge with master.
michelleb-stripe da41eb0
Billing code now shows the correct fields.
michelleb-stripe a9a04ac
Billing now added to the credit element.
michelleb-stripe 2ceac10
Credit card number length verification corrected.
michelleb-stripe e35e2c7
Refactor Elements so each element (including sections) provide the fo…
michelleb-stripe f897f12
Add in the expiration date functionality.
michelleb-stripe 53661e1
Merge branch 'master' into michelleb/credit-card-compose
michelleb-stripe 4f20fb2
Refactor so that each element returns a flow of FormFieldEntries, so …
michelleb-stripe 940f304
Fix unit test
michelleb-stripe e8fc0ff
Merge with master.
michelleb-stripe 7e5ee6a
Rename class
michelleb-stripe c3d7b28
More rework
michelleb-stripe a61ea99
Merge with michelleb/refactor-section-form-fields
michelleb-stripe b3be29c
Get ready for merge with master
michelleb-stripe 9a258ec
Merge with master.
michelleb-stripe 57b617c
Merge with master
michelleb-stripe 3e60136
Merge with master.
michelleb-stripe 4d8ec20
Change from liveData to flow.
michelleb-stripe 591a73e
Merge branch 'michelleb/convert-to-flow' into michelleb/credit-card-c…
michelleb-stripe 2aeb3ef
Row is working but not expiry date
michelleb-stripe 9161d4f
Make the keypad just numbers.
michelleb-stripe 0441d0a
Make the keypad just numbers.
michelleb-stripe c41ec5d
Set the expiration month and date correctly in the formFieldValues
michelleb-stripe fdad41f
Update the focus to visit the CVC
michelleb-stripe 43c9127
Handle a full text field state.
michelleb-stripe 317a841
Merge with master
michelleb-stripe 8e649c8
Unit tests
michelleb-stripe 9ead541
ktlintFormat
michelleb-stripe 939dba9
Format card number based on max pan for card number
michelleb-stripe 60da73f
Cleanup date util for expiration month
michelleb-stripe f51f90b
Make the label flowable
michelleb-stripe fef63b3
Fix internals
michelleb-stripe f19cbe2
Cleanup
michelleb-stripe 07cfa62
Cleanup
michelleb-stripe bd5d754
Merge with master
michelleb-stripe 2722977
Fix unit tests
michelleb-stripe 4bee0c1
ktlintFormat
michelleb-stripe 4b78747
Undos
michelleb-stripe 9242d80
ktlintFormat
michelleb-stripe b1cd5b0
Merge with master
michelleb-stripe 239273d
Merge remote-tracking branch 'origin/master' into michelleb/credit-ca…
michelleb-stripe 8eb4204
Merge with master
michelleb-stripe 40fe6c0
Merge with master
michelleb-stripe adaed05
Ignore tests that cause other failures
michelleb-stripe 667bd39
Merge branch 'master' into michelleb/credit-card-compose
michelleb-stripe 7c5e474
Working on the merge.
michelleb-stripe 1eee681
Almost building
michelleb-stripe 7ed49f3
Get closer to master
michelleb-stripe e68a86a
Update files.
michelleb-stripe f0fa03a
Iterating
michelleb-stripe 5ad3f10
Building
michelleb-stripe a3c9eae
Fix unit tests
michelleb-stripe e2f39c4
Cleanup
michelleb-stripe 57677d8
Remove extra comment
michelleb-stripe 6bee0a4
Fix failing tests
epan-stripe 2c6e45c
Fix linting
epan-stripe 8b5d2ae
Fix SaveForFutureUseController.label not showing
epan-stripe 313f52a
Merge with master
michelleb-stripe c1e78f7
Cleanup
michelleb-stripe 6c9cb94
apiDump
michelleb-stripe 508b5ad
Merge with master
michelleb-stripe 33b754a
apiDump
michelleb-stripe 7819db6
Fix some failing tests, apiDump, ktlintFormat
michelleb-stripe b3917f9
Fix remaining failing tests, apiDump, ktlintFormat
michelleb-stripe 95d8557
Fix todo
michelleb-stripe 7af4ff5
Merge remote-tracking branch 'origin/master' into michelleb/credit-ca…
michelleb-stripe afd06c9
Simplify and add DateConfig tests and cleanup commented out code in T…
michelleb-stripe 98043bd
Merge with master
michelleb-stripe 8ca28d2
Merge remote-tracking branch 'origin/master' into michelleb/credit-ca…
michelleb-stripe 9bf81f2
ktlintFormat apiDump
michelleb-stripe 783039a
Merge with master
michelleb-stripe bf51053
Add icons to the IBAN, credit card and CVC fields. (#4359)
michelleb-stripe 7979d18
Merge with master
michelleb-stripe bd3fb81
Merge with remote
michelleb-stripe a18c6c2
Add Card Metadata Service to CardNumberController (#4573)
epan-stripe b4cacba
Don't show cardbrand if there are multiple possibilities
epan-stripe 06c5d00
Don't show cardbrand if there are multiple possibilities
epan-stripe c179b73
Merge branch 'michelleb/credit-card-compose' of github.com:stripe/str…
epan-stripe 61200f9
Merge remote-tracking branch 'origin/master' into michelleb/credit-ca…
michelleb-stripe 110ecd3
Merge with master
michelleb-stripe 067ea3b
Material Theme information gathering.
michelleb-stripe 36913d3
Revert "Material Theme information gathering."
michelleb-stripe 167b00f
Immediately detect invalid card numbers (no brand)
epan-stripe 8701f44
Fix invalid vs incomplete dateconfig error text
epan-stripe b6fff48
Fix CVC icon and next field focus
epan-stripe 3ed0104
Fix expiry date accessibility reader
epan-stripe 7f3d2f2
Merge branch 'master' into michelleb/credit-card-compose
epan-stripe d92df95
Fix merge issues
epan-stripe e2880f4
Add ability to move focus on delete
jameswoo-stripe 81042c0
Merge remote-tracking branch 'origin/master' into michelleb/credit-ca…
michelleb-stripe 219e999
Fix dark mode error underline
epan-stripe 126de9a
Fix cursor and spacing position in card details
epan-stripe 10f4f47
update icons and colors for future wardrobe work
skyler-stripe da16b49
Merge branch 'master' into michelleb/credit-card-compose
michelleb-stripe 0d7f077
Merge branch 'michelleb/credit-card-compose' of github.com:stripe/str…
michelleb-stripe ba21e4a
Add card information title
epan-stripe 0c87580
Add tests for card number formatting
epan-stripe 7a60b61
Revert "Add tests for card number formatting"
epan-stripe d2ff7ba
Add country list to card and sepa billing spec. (#4669)
michelleb-stripe 55a143b
Credit Card Address and focus bug fixes (#4665)
michelleb-stripe f111ac0
Fix width of rows (#4676)
epan-stripe f3d960b
Fix spacing for AMEX and Discover cards (#4672)
epan-stripe f8c7ec7
Don't show CVC error when CardBrand is unknown (#4681)
epan-stripe 5fbad06
Stop accessibility talkback reading textfields twice (#4683)
epan-stripe c6363f2
Merge with master
michelleb-stripe c5c70e5
Merge branch 'michelleb/credit-card-compose' of github.com:stripe/str…
michelleb-stripe 2ba55b8
ktformat
michelleb-stripe 6fb7a3f
Fix detekt
michelleb-stripe b9095ff
checkbox colors read from theme object now
skyler-stripe 23a2a48
Fix the delete button move to previous. (#4706)
michelleb-stripe e23283b
Improve performance of dropdown in forms. (#4705)
michelleb-stripe eafd4c3
Merge with master. (Sepa debit address is broken - the row fields ar…
michelleb-stripe e89c5c1
Card now showing up correctly.
michelleb-stripe 3b818e7
Merge branch 'michelleb/credit-card-compose' of github.com:stripe/str…
michelleb-stripe 4119def
Fix compile error.
michelleb-stripe 33a004c
Don't show cardbrand if there are multiple possible (#4682)
epan-stripe cd76630
Merge branch 'master' into michelleb/credit-card-compose
michelleb-stripe bcc452e
Merge branch 'michelleb/credit-card-compose' of github.com:stripe/str…
michelleb-stripe e3c29bb
Merge remote-tracking branch 'origin/master' into michelleb/credit-ca…
michelleb-stripe e79cfdd
merge master
skyler-stripe 8f8c288
Merge remote-tracking branch 'origin/master' into michelleb/credit-ca…
michelleb-stripe c777dfc
Merge with master
michelleb-stripe f2e59b9
Fix merge errors.
michelleb-stripe 51dfa5d
Update the changedoc.
michelleb-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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
45 changes: 45 additions & 0 deletions
45
...ts-ui-core/src/main/java/com/stripe/android/ui/core/elements/CardBillingAddressElement.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,45 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import androidx.annotation.RestrictTo | ||
import com.stripe.android.ui.core.address.AddressFieldElementRepository | ||
import com.stripe.android.ui.core.address.FieldType | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
/** | ||
* This is a special type of AddressElement that | ||
* removes fields from the address based on the country. It | ||
* is only intended to be used with the card payment method. | ||
*/ | ||
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) | ||
class CardBillingAddressElement( | ||
identifier: IdentifierSpec, | ||
addressFieldRepository: AddressFieldElementRepository, | ||
countryCodes: Set<String> = emptySet(), | ||
countryDropdownFieldController: DropdownFieldController = DropdownFieldController( | ||
CountryConfig(countryCodes) | ||
), | ||
rawValuesMap: Map<IdentifierSpec, String?> = emptyMap(), | ||
) : AddressElement( | ||
identifier, | ||
addressFieldRepository, | ||
rawValuesMap, | ||
countryCodes, | ||
countryDropdownFieldController | ||
) { | ||
// Save for future use puts this in the controller rather than element | ||
val hiddenIdentifiers: Flow<List<IdentifierSpec>> = | ||
countryDropdownFieldController.rawFieldValue.map { countryCode -> | ||
when (countryCode) { | ||
"US", "GB", "CA" -> { | ||
FieldType.values() | ||
.filterNot { it == FieldType.PostalCode } | ||
.map { it.identifierSpec } | ||
} | ||
else -> { | ||
FieldType.values() | ||
.map { it.identifierSpec } | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/CardBillingSpec.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,14 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import com.stripe.android.ui.core.address.AddressFieldElementRepository | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
internal object CardBillingSpec : SectionFieldSpec(IdentifierSpec.Generic("card_billing")) { | ||
fun transform( | ||
addressRepository: AddressFieldElementRepository | ||
) = CardBillingAddressElement( | ||
IdentifierSpec.Generic("credit_billing"), | ||
addressRepository | ||
) | ||
} |
43 changes: 43 additions & 0 deletions
43
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/CardDetailsController.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,43 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.combine | ||
import java.util.UUID | ||
|
||
internal class CardDetailsController : SectionFieldErrorController { | ||
|
||
val label: Int? = null | ||
val numberElement = CardNumberElement( | ||
IdentifierSpec.Generic("number"), | ||
CardNumberController(CardNumberConfig()) | ||
) | ||
|
||
val cvcElement = CvcElement( | ||
IdentifierSpec.Generic("cvc"), | ||
CvcController(CvcConfig(), numberElement.controller.cardBrandFlow) | ||
) | ||
|
||
val expirationDateElement = SimpleTextElement( | ||
IdentifierSpec.Generic("date"), | ||
SimpleTextFieldController(DateConfig()) | ||
) | ||
|
||
private val rowFields = listOf(expirationDateElement, cvcElement) | ||
val fields = listOf( | ||
numberElement, | ||
RowElement( | ||
IdentifierSpec.Generic("row_" + UUID.randomUUID().leastSignificantBits), | ||
rowFields, | ||
RowController(rowFields) | ||
) | ||
) | ||
|
||
@ExperimentalCoroutinesApi | ||
override val error = combine( | ||
listOf(numberElement, expirationDateElement, cvcElement) | ||
.map { it.controller } | ||
.map { it.error } | ||
) { | ||
it.filterNotNull().firstOrNull() | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/CardDetailsElement.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,46 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import kotlinx.coroutines.flow.combine | ||
|
||
/** | ||
* This is the element that represent the collection of all the card details: | ||
* card number, expiration date, and CVC. | ||
*/ | ||
internal class CardDetailsElement( | ||
identifier: IdentifierSpec, | ||
val controller: CardDetailsController = CardDetailsController(), | ||
) : SectionMultiFieldElement(identifier) { | ||
override fun sectionFieldErrorController(): SectionFieldErrorController = | ||
controller | ||
|
||
override fun setRawValue(rawValuesMap: Map<IdentifierSpec, String?>) { | ||
// Nothing from formFragmentArguments to populate | ||
} | ||
|
||
override fun getFormFieldValueFlow() = combine( | ||
controller.numberElement.controller.formFieldValue, | ||
controller.cvcElement.controller.formFieldValue, | ||
controller.expirationDateElement.controller.formFieldValue | ||
) { number, cvc, expirationDate -> | ||
var month = -1 | ||
var year = -1 | ||
expirationDate.value?.let { date -> | ||
val newString = convertTo4DigitDate(date) | ||
if (newString.length == 4) { | ||
month = requireNotNull(newString.take(2).toIntOrNull()) | ||
year = requireNotNull(newString.takeLast(2).toIntOrNull()) | ||
} | ||
} | ||
|
||
listOf( | ||
controller.numberElement.identifier to number, | ||
controller.cvcElement.identifier to cvc, | ||
IdentifierSpec.Generic("exp_month") to expirationDate.copy( | ||
value = month.toString() | ||
), | ||
IdentifierSpec.Generic("exp_year") to expirationDate.copy( | ||
value = year.toString() | ||
) | ||
) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/CardDetailsElementUI.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,28 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Divider | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
|
||
@Composable | ||
internal fun CardDetailsElementUI( | ||
enabled: Boolean, | ||
controller: CardDetailsController, | ||
hiddenIdentifiers: List<IdentifierSpec>? | ||
) { | ||
controller.fields.forEachIndexed { index, field -> | ||
SectionFieldElementUI(enabled, field, hiddenIdentifiers = hiddenIdentifiers) | ||
if (index != controller.fields.size - 1) { | ||
val cardStyle = CardStyle(isSystemInDarkTheme()) | ||
Divider( | ||
color = cardStyle.cardBorderColor, | ||
thickness = cardStyle.cardBorderWidth, | ||
modifier = Modifier.padding( | ||
horizontal = cardStyle.cardBorderWidth | ||
) | ||
) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/CardDetailsSpec.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,10 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
internal object CardDetailsSpec : SectionFieldSpec(IdentifierSpec.Generic("card_details")) { | ||
fun transform(): SectionFieldElement = CardDetailsElement( | ||
IdentifierSpec.Generic("credit_detail") | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
...s-ui-core/src/main/java/com/stripe/android/ui/core/elements/CardDetailsTextFieldConfig.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,22 @@ | ||
package com.stripe.android.ui.core.elements | ||
|
||
import androidx.compose.ui.text.input.KeyboardCapitalization | ||
import androidx.compose.ui.text.input.KeyboardType | ||
import androidx.compose.ui.text.input.VisualTransformation | ||
import com.stripe.android.model.CardBrand | ||
|
||
/** | ||
* This is similar to the [TextFieldConfig], but in order to determine | ||
* the state the card brand is required. | ||
*/ | ||
internal interface CardDetailsTextFieldConfig { | ||
val capitalization: KeyboardCapitalization | ||
val debugLabel: String | ||
val label: Int | ||
val keyboard: KeyboardType | ||
val visualTransformation: VisualTransformation | ||
fun determineState(brand: CardBrand, number: String): TextFieldState | ||
fun filter(userTyped: String): String | ||
fun convertToRaw(displayName: String): String | ||
fun convertFromRaw(rawValue: String): String | ||
} |
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.
Expect this to be removed when other work is complete.