-
Notifications
You must be signed in to change notification settings - Fork 662
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
Conversation
… 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.
stripe/src/test/java/com/stripe/android/view/CardNumberEditTextTest.kt
Outdated
Show resolved
Hide resolved
if (hasFocus) { | ||
cardInputListener?.onFocusChange(CardInputListener.FocusField.CardNumber) | ||
} | ||
} | ||
|
||
expiryDateEditText.onFocusChangeListener = OnFocusChangeListener { _, hasFocus -> | ||
expiryDateEditText.internalFocusChangeListener.add { _, hasFocus -> | ||
// TODO: Why is this only called when have focus? |
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 intend to remove this comment, but I am curious if you know?
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.
onFocusChange()
is called with the field that now has focus
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.
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.
… simplify the logic on focus loss in the CardNumberEditText.kt
stripe/src/main/java/com/stripe/android/view/CardNumberEditText.kt
Outdated
Show resolved
Hide resolved
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/src/main/java/com/stripe/android/model/ExpirationDate.kt
Outdated
Show resolved
Hide resolved
stripe/src/main/java/com/stripe/android/model/ExpirationDate.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. |
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.
Should we auto-truncate or just mark as error?
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.
Web Checkout truncates
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.
Are we missing any tests for new functionality?
Summary
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