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

Enable optionally requiring postal code in CardInputWidget and CardMultilineWidget #2113

Merged
merged 1 commit into from
Jan 29, 2020

Conversation

mshafrir-stripe
Copy link
Collaborator

Summary

By default, postal code is an optional field in CardInputWidget
and CardMultilineWidget because some countries do not have
postal codes.

For apps that are certain their customers are from a country
that has a postal code (e.g. US), postal code can be set to a
required field. If required, the postal code value must be
non-blank. No other validation is applied.

If the postal code field is not enabled (i.e. it is not visible),
then the postal code will never be required.

Note that because some countries do not have postal codes, requiring
a postal code will prevent users with cards from those countries
from submitting the form successfully.

Postal code can either be required via XML:

<com.stripe.android.view.CardInputWidget
    app:shouldRequirePostalCode="true" />

<com.stripe.android.view.CardMultilineWidget
    app:shouldRequirePostalCode="true" />

or code:

val cardWidget: CardInlineWidget = ...
cardWidget.postalCodeRequired = true

val cardWidget: CardMultilineWidget = ...
cardWidget.postalCodeRequired = true

Motivation

Fixes #2111

Testing

  • Added unit tests
  • Tested in example app
  • Tested with TalkBack

Summary
By default, postal code is an optional field in `CardInputWidget`
and `CardMultilineWidget` because some countries do not have
postal codes.

For apps that are certain their customers are from a country
that has a postal code (e.g. US), postal code can be set to a
required field. If required, the postal code value must be
non-blank. No other validation is applied.

If the postal code field is not enabled (i.e. it is not visible),
then the postal code will never be required.

Note that because some countries do not have postal codes, requiring
a postal code will prevent users with cards from those countries
from submitting the form successfully.

Postal code can either be required via XML:
```
<com.stripe.android.view.CardInputWidget
    app:shouldRequirePostalCode="true" />

<com.stripe.android.view.CardMultilineWidget
    app:shouldRequirePostalCode="true" />
```

or code:
```
val cardWidget: CardInlineWidget = ...
cardWidget.postalCodeRequired = true

val cardWidget: CardMultilineWidget = ...
cardWidget.postalCodeRequired = true
```

Motivation
Fixes #2111

Testing
- Added unit tests
- Tested in example app
- Tested with TalkBack
@mshafrir-stripe mshafrir-stripe merged commit 962b4f0 into master Jan 29, 2020
@mshafrir-stripe mshafrir-stripe deleted the require-postal-code branch January 29, 2020 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zip code field is no longer showing an error
4 participants