-
Notifications
You must be signed in to change notification settings - Fork 1.3k
For #19065: Add extension functions to be used with credit cards. #19187
Conversation
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.
Looking good here. Let's hold back on using this immediately until we land the breaking changes that are coming from AC/AS in #19154
* to validate a credit card number | ||
*/ | ||
@Suppress("MagicNumber") | ||
fun String.validateCreditCardNumber(): Boolean { |
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.
Nice, this saves me the trouble of implementing the Luhn Algorithm. Just an FYI this will probably be refactored in some capacity when I finish up the credit card validation that will return the credit card issuer based on the card number in mozilla-mobile/android-components#9813.
One immediate benefit of having this for now is that we can probably use this for the form validation in the meantime in #18266.
app/src/test/java/org/mozilla/fenix/settings/creditcards/StringTest.kt
Outdated
Show resolved
Hide resolved
app/src/test/java/org/mozilla/fenix/settings/creditcards/StringTest.kt
Outdated
Show resolved
Hide resolved
* Strips characters other than digits from a string. | ||
* Used to strip a credit card number user input of spaces and separators. | ||
*/ | ||
|
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.
app/src/main/java/org/mozilla/fenix/settings/creditcards/String.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/org/mozilla/fenix/settings/creditcards/String.kt
Outdated
Show resolved
Hide resolved
return luhnAlgorithmValidation(creditCardNumber) | ||
} | ||
|
||
private fun luhnAlgorithmValidation(creditCardNumber: String): Boolean { |
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.
I am wondering if we can write tests that just validates the luhn algorithm
Fixes #19065
Pull Request checklist
To download an APK when reviewing a PR: