Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

For #19065: Add extension functions to be used with credit cards. #19187

Merged
merged 1 commit into from
Apr 22, 2021

Conversation

mcarare
Copy link
Contributor

@mcarare mcarare commented Apr 22, 2021

Fixes #19065

Pull Request checklist

  • Tests: This PR includes thorough tests or an explanation of why it does not
  • Screenshots: This PR includes screenshots or GIFs of the changes made or an explanation of why it does not
  • Accessibility: The code in this PR follows accessibility best practices or does not include any user facing features. In addition, it includes a screenshot of a successful accessibility scan to ensure no new defects are added to the product.

To download an APK when reviewing a PR:

  1. click on Show All Checks,
  2. click Details next to "Taskcluster (pull_request)" after it appears and then finishes with a green checkmark,
  3. click on the "Fenix - assemble" task, then click "Run Artifacts".
  4. the APK links should be on the left side of the screen, named for each CPU architecture

@mcarare mcarare requested review from a team as code owners April 22, 2021 12:31
@mcarare mcarare removed request for a team April 22, 2021 12:31
@mcarare mcarare added the needs:review PRs that need to be reviewed label Apr 22, 2021
Copy link
Member

@gabrielluong gabrielluong left a 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 {
Copy link
Member

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.

* Strips characters other than digits from a string.
* Used to strip a credit card number user input of spaces and separators.
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

return luhnAlgorithmValidation(creditCardNumber)
}

private fun luhnAlgorithmValidation(creditCardNumber: String): Boolean {
Copy link
Member

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

@gabrielluong gabrielluong added pr:approved PR that has been approved and removed needs:review PRs that need to be reviewed labels Apr 22, 2021
@gabrielluong gabrielluong merged commit e952513 into mozilla-mobile:master Apr 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr:approved PR that has been approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strip spaces and separators from credit card number input
2 participants