diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d9f936ac08..dc7cc885485 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## XX.XX.XX - 2023-XX-XX +### PaymentSheet +* [FIXED][](https://github.com/stripe/stripe-android/pull/) Fixed an issue where SEPA mandate texts were being displayed to payment method forms when they shouldn't be. + ## 20.30.0 - 2023-09-11 ### PaymentSheet diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/forms/PlaceholderHelper.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/forms/PlaceholderHelper.kt index 5065cc9b439..ed6986d587c 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/forms/PlaceholderHelper.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/forms/PlaceholderHelper.kt @@ -39,7 +39,6 @@ internal object PlaceholderHelper { PlaceholderField.Email, PlaceholderField.Phone, PlaceholderField.BillingAddress, - PlaceholderField.SepaMandate, ) val modifiedSpecs = specs.mapNotNull { @@ -61,10 +60,6 @@ internal object PlaceholderHelper { configuration.address == AddressCollectionMode.Never } - is SepaMandateTextSpec -> it.takeIf { - requiresMandate - } - is PlaceholderSpec -> specForPlaceholderField( it.field, placeholderOverrideList, diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/forms/PlaceholderHelperTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/forms/PlaceholderHelperTest.kt index 96612b8e089..9a3e358665a 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/forms/PlaceholderHelperTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/forms/PlaceholderHelperTest.kt @@ -40,7 +40,6 @@ class PlaceholderHelperTest { EmailSpec(), PhoneSpec(), AddressSpec(), - SepaMandateTextSpec(), ), ) assertThat(specs).isEmpty() @@ -109,6 +108,54 @@ class PlaceholderHelperTest { ) } + @Test + fun `Test when requiresMandate is true, SepaMandateSpec is only added when specified`() { + val specs = specsForConfiguration( + configuration = PaymentSheet.BillingDetailsCollectionConfiguration(), + placeholderOverrideList = emptyList(), + requiresMandate = true, + specs = listOf( + NameSpec(), + ), + ) + + assertThat(specs).containsExactly( + NameSpec(), + ) + + val specsWithSepa = specsForConfiguration( + configuration = PaymentSheet.BillingDetailsCollectionConfiguration(), + placeholderOverrideList = emptyList(), + requiresMandate = true, + specs = listOf( + NameSpec(), + SepaMandateTextSpec() + ), + ) + + assertThat(specsWithSepa).containsExactly( + NameSpec(), + SepaMandateTextSpec() + ) + + val specsWithSepaPlaceholder = specsForConfiguration( + configuration = PaymentSheet.BillingDetailsCollectionConfiguration(), + placeholderOverrideList = emptyList(), + requiresMandate = true, + specs = listOf( + NameSpec(), + PlaceholderSpec( + field = PlaceholderSpec.PlaceholderField.SepaMandate, + ) + ), + ) + + assertThat(specsWithSepaPlaceholder).containsExactly( + NameSpec(), + SepaMandateTextSpec() + ) + } + @Suppress("LongMethod") @Test fun `Test correct spec is returned for placeholder fields`() { @@ -160,6 +207,14 @@ class PlaceholderHelperTest { configuration = billingDetailsCollectionConfiguration, ) ).isEqualTo(AddressSpec(hideCountry = true)) + assertThat( + specForPlaceholderField( + field = PlaceholderField.SepaMandate, + placeholderOverrideList = emptyList(), + requiresMandate = true, + configuration = billingDetailsCollectionConfiguration, + ) + ).isEqualTo(SepaMandateTextSpec()) } @Test @@ -222,6 +277,7 @@ class PlaceholderHelperTest { PlaceholderField.Email, PlaceholderField.Phone, PlaceholderField.BillingAddress, + PlaceholderField.SepaMandate, ) placeholders = basePlaceholders() @@ -230,6 +286,7 @@ class PlaceholderHelperTest { PlaceholderField.Name, PlaceholderField.Phone, PlaceholderField.BillingAddress, + PlaceholderField.SepaMandate, ) placeholders = basePlaceholders() @@ -238,6 +295,7 @@ class PlaceholderHelperTest { PlaceholderField.Name, PlaceholderField.Email, PlaceholderField.BillingAddress, + PlaceholderField.SepaMandate, ) placeholders = basePlaceholders() @@ -246,6 +304,16 @@ class PlaceholderHelperTest { PlaceholderField.Name, PlaceholderField.Email, PlaceholderField.Phone, + PlaceholderField.SepaMandate, + ) + + placeholders = basePlaceholders() + removeCorrespondingPlaceholder(placeholders, SepaMandateTextSpec()) + assertThat(placeholders).containsExactly( + PlaceholderField.Name, + PlaceholderField.Email, + PlaceholderField.Phone, + PlaceholderField.BillingAddress, ) } @@ -257,6 +325,7 @@ class PlaceholderHelperTest { PlaceholderField.Email, PlaceholderField.Phone, PlaceholderField.BillingAddress, + PlaceholderField.SepaMandate, ) placeholders = basePlaceholders() @@ -268,6 +337,7 @@ class PlaceholderHelperTest { PlaceholderField.Name, PlaceholderField.Phone, PlaceholderField.BillingAddress, + PlaceholderField.SepaMandate, ) placeholders = basePlaceholders() @@ -279,6 +349,7 @@ class PlaceholderHelperTest { PlaceholderField.Name, PlaceholderField.Email, PlaceholderField.BillingAddress, + PlaceholderField.SepaMandate, ) placeholders = basePlaceholders() @@ -290,6 +361,7 @@ class PlaceholderHelperTest { PlaceholderField.Name, PlaceholderField.Email, PlaceholderField.Phone, + PlaceholderField.SepaMandate, ) placeholders = basePlaceholders() @@ -301,6 +373,19 @@ class PlaceholderHelperTest { PlaceholderField.Name, PlaceholderField.Email, PlaceholderField.Phone, + PlaceholderField.SepaMandate, + ) + + placeholders = basePlaceholders() + removeCorrespondingPlaceholder( + placeholders, + PlaceholderSpec(field = PlaceholderField.SepaMandate) + ) + assertThat(placeholders).containsExactly( + PlaceholderField.Name, + PlaceholderField.Email, + PlaceholderField.Phone, + PlaceholderField.BillingAddress, ) } @@ -383,5 +468,6 @@ class PlaceholderHelperTest { PlaceholderField.Email, PlaceholderField.Phone, PlaceholderField.BillingAddress, + PlaceholderField.SepaMandate, ) }