From d1eeeaaa9c57d6d15adb81beaf58124095792e44 Mon Sep 17 00:00:00 2001 From: Till Hellmund <110940675+tillh-stripe@users.noreply.github.com> Date: Mon, 17 Oct 2022 13:57:52 -0400 Subject: [PATCH] Fix issue with limited postal code input (#5715) --- CHANGELOG.md | 1 + .../com/stripe/android/ui/core/elements/PostalCodeConfig.kt | 6 +++--- .../stripe/android/ui/core/elements/PostalCodeConfigTest.kt | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc351bb15d7..1e59951ed06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Payments * [FIXED][5701](https://github.com/stripe/stripe-android/pull/5701) Treat blank fields as invalid in `ShippingInfoWidget`. +* [FIXED][5715](https://github.com/stripe/stripe-android/pull/5715) Postal codes for countries other than US and Canada are no longer limited to a single character. ## 20.15.0 - 2022-10-11 diff --git a/payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/PostalCodeConfig.kt b/payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/PostalCodeConfig.kt index 1afeaefac13..db595936fff 100644 --- a/payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/PostalCodeConfig.kt +++ b/payments-ui-core/src/main/java/com/stripe/android/ui/core/elements/PostalCodeConfig.kt @@ -37,17 +37,17 @@ internal class PostalCodeConfig( override fun getError(): FieldError? { return when { - input.isNotBlank() && !isFull() && country == "US" -> { + input.isNotBlank() && !isValid() && country == "US" -> { FieldError(R.string.address_zip_invalid) } - input.isNotBlank() && !isFull() -> { + input.isNotBlank() && !isValid() -> { FieldError(R.string.address_zip_postal_invalid) } else -> null } } - override fun isFull(): Boolean = input.length >= format.minimumLength + override fun isFull(): Boolean = input.length >= format.maximumLength override fun isBlank(): Boolean = input.isBlank() } diff --git a/payments-ui-core/src/test/java/com/stripe/android/ui/core/elements/PostalCodeConfigTest.kt b/payments-ui-core/src/test/java/com/stripe/android/ui/core/elements/PostalCodeConfigTest.kt index ab2f8074706..04ffe48d1d8 100644 --- a/payments-ui-core/src/test/java/com/stripe/android/ui/core/elements/PostalCodeConfigTest.kt +++ b/payments-ui-core/src/test/java/com/stripe/android/ui/core/elements/PostalCodeConfigTest.kt @@ -40,9 +40,9 @@ class PostalCodeConfigTest { Truth.assertThat(determineStateForInput(" ").isValid()).isFalse() Truth.assertThat(determineStateForInput(" ").isFull()).isFalse() Truth.assertThat(determineStateForInput("a").isValid()).isTrue() - Truth.assertThat(determineStateForInput("a").isFull()).isTrue() + Truth.assertThat(determineStateForInput("a").isFull()).isFalse() Truth.assertThat(determineStateForInput("1").isValid()).isTrue() - Truth.assertThat(determineStateForInput("1").isFull()).isTrue() + Truth.assertThat(determineStateForInput("1").isFull()).isFalse() Truth.assertThat(determineStateForInput("aaaaaa").isValid()).isTrue() Truth.assertThat(determineStateForInput("111111").isValid()).isTrue() }