Skip to content

Commit

Permalink
Fix issue where sepa mandate text is incorrectly being displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
jameswoo-stripe committed Sep 13, 2023
1 parent 0680a67 commit 83d77a9
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ internal object PlaceholderHelper {
PlaceholderField.Email,
PlaceholderField.Phone,
PlaceholderField.BillingAddress,
PlaceholderField.SepaMandate,
)

val modifiedSpecs = specs.mapNotNull {
Expand All @@ -61,10 +60,6 @@ internal object PlaceholderHelper {
configuration.address == AddressCollectionMode.Never
}

is SepaMandateTextSpec -> it.takeIf {
requiresMandate
}

is PlaceholderSpec -> specForPlaceholderField(
it.field,
placeholderOverrideList,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class PlaceholderHelperTest {
EmailSpec(),
PhoneSpec(),
AddressSpec(),
SepaMandateTextSpec(),
),
)
assertThat(specs).isEmpty()
Expand Down Expand Up @@ -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`() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -222,6 +277,7 @@ class PlaceholderHelperTest {
PlaceholderField.Email,
PlaceholderField.Phone,
PlaceholderField.BillingAddress,
PlaceholderField.SepaMandate,
)

placeholders = basePlaceholders()
Expand All @@ -230,6 +286,7 @@ class PlaceholderHelperTest {
PlaceholderField.Name,
PlaceholderField.Phone,
PlaceholderField.BillingAddress,
PlaceholderField.SepaMandate,
)

placeholders = basePlaceholders()
Expand All @@ -238,6 +295,7 @@ class PlaceholderHelperTest {
PlaceholderField.Name,
PlaceholderField.Email,
PlaceholderField.BillingAddress,
PlaceholderField.SepaMandate,
)

placeholders = basePlaceholders()
Expand All @@ -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,
)
}

Expand All @@ -257,6 +325,7 @@ class PlaceholderHelperTest {
PlaceholderField.Email,
PlaceholderField.Phone,
PlaceholderField.BillingAddress,
PlaceholderField.SepaMandate,
)

placeholders = basePlaceholders()
Expand All @@ -268,6 +337,7 @@ class PlaceholderHelperTest {
PlaceholderField.Name,
PlaceholderField.Phone,
PlaceholderField.BillingAddress,
PlaceholderField.SepaMandate,
)

placeholders = basePlaceholders()
Expand All @@ -279,6 +349,7 @@ class PlaceholderHelperTest {
PlaceholderField.Name,
PlaceholderField.Email,
PlaceholderField.BillingAddress,
PlaceholderField.SepaMandate,
)

placeholders = basePlaceholders()
Expand All @@ -290,6 +361,7 @@ class PlaceholderHelperTest {
PlaceholderField.Name,
PlaceholderField.Email,
PlaceholderField.Phone,
PlaceholderField.SepaMandate,
)

placeholders = basePlaceholders()
Expand All @@ -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,
)
}

Expand Down Expand Up @@ -383,5 +468,6 @@ class PlaceholderHelperTest {
PlaceholderField.Email,
PlaceholderField.Phone,
PlaceholderField.BillingAddress,
PlaceholderField.SepaMandate,
)
}

0 comments on commit 83d77a9

Please sign in to comment.