Skip to content
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

When losing focus show field as invalid #3482

Merged
merged 25 commits into from
Mar 22, 2021

Conversation

michelleb-stripe
Copy link
Contributor

@michelleb-stripe michelleb-stripe commented Mar 18, 2021

Summary

  • If the credit card number is at least one character check to see if it matches any of the possible values.
  • If the credit card is not complete and focus changes, show an error.
  • If the CVC is at least one character check to see if it matches any of the possible values when the brand updates.
  • If the CVC is not complete and focus changes, show an error.

Credit card = 3 -> no error (matches amex and diners)
Credit card = 3, move to new field -> show error
Credit card = 0 -> error
Credit card of 37, CVC of 1234, Credit card to 4 -> CVC should be in error. (brand updates checks cvc)
Credit card = any single possible 1 digit, CVC of 1, move to a new field -> Show CVC in error.

There is still a problem when the month loses focus, but that will be addressed in a separate PR. If desired I can split these into two reviews one for credit card and one for the CVC, just let me know on the early side.

There is also still a problem with postal code validation.

Motivation

MOBILESDK-170

Testing

  • Added tests
  • Modified tests
  • Manually verified

msternow and others added 6 commits March 17, 2021 21:28
… it matches any of the possible values.

* If the credit card is not complete and focus changes, show an error.
* If the CVC is at least one character check to see if it matches any of the possible values when the brand updates.
* If the CVC is not complete and focus changes, show an error.

Credit card = 3 -> no error (matches amex and diners)
Credit card = 3, move to new field -> show error
Credit card = 0 -> error
Credit card of 37, CVC of 1234, Credit card to 4 -> CVC should be in error. (brand updates checks cvc)
Credit card = any single possible 1 digit, CVC of 1, move to a new field -> Show CVC in error.
* If the credit card number is at least one character check to see if it matches any of the possible values.
* If the credit card is not complete and focus changes, show an error.
* If the CVC is at least one character check to see if it matches any of the possible values when the brand updates.
* If the CVC is not complete and focus changes, show an error.

Credit card = 3 -> no error (matches amex and diners)
Credit card = 3, move to new field -> show error
Credit card = 0 -> error
Credit card of 37, CVC of 1234, Credit card to 4 -> CVC should be in error. (brand updates checks cvc)
Credit card = any single possible 1 digit, CVC of 1, move to a new field -> Show CVC in error.
if (hasFocus) {
cardInputListener?.onFocusChange(CardInputListener.FocusField.CardNumber)
}
}

expiryDateEditText.onFocusChangeListener = OnFocusChangeListener { _, hasFocus ->
expiryDateEditText.internalFocusChangeListener.add { _, hasFocus ->
// TODO: Why is this only called when have focus?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intend to remove this comment, but I am curious if you know?

Copy link
Collaborator

Choose a reason for hiding this comment

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

onFocusChange() is called with the field that now has focus

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it make sense to name it onFocusGained? Not considering it for this PR, but might be worth thinking about if we are in this code again.

@michelleb-stripe
Copy link
Contributor Author

I have a few more unit tests to add in the morning. But it tests well. I also have postal code text color setting in another branch.

stripe/res/values/strings.xml Show resolved Hide resolved
stripe/src/main/java/com/stripe/android/cards/Cvc.kt Outdated Show resolved Hide resolved
// and the Cvc does not validate
if (unvalidatedCvc.normalized.isNotEmpty()) {
shouldShowError = unvalidatedCvc.validate(cardBrand.maxCvcLength) == null
// TODO(michelleb-stripe): Should truncate CVC on a brand name change.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we auto-truncate or just mark as error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Web Checkout truncates

Copy link
Collaborator

@mshafrir-stripe mshafrir-stripe left a comment

Choose a reason for hiding this comment

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

Are we missing any tests for new functionality?

@michelleb-stripe michelleb-stripe merged commit 5d9db04 into master Mar 22, 2021
@michelleb-stripe michelleb-stripe deleted the michelleb/every-field-invalid branch March 22, 2021 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants