From b388616febe2642b328fc8da4a34e9711b925220 Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 26 Sep 2024 15:51:23 -0700 Subject: [PATCH 1/4] Update saved card description to use displayed brand --- .../DisplayableSavedPaymentMethod.kt | 14 +++++--- .../DisplayableSavedPaymentMethodTest.kt | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethod.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethod.kt index 5b347d40a0e..6a2da11eb40 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethod.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethod.kt @@ -2,6 +2,7 @@ package com.stripe.android.paymentsheet import com.stripe.android.core.strings.ResolvableString import com.stripe.android.core.strings.resolvableString +import com.stripe.android.model.CardBrand import com.stripe.android.model.PaymentMethod internal data class DisplayableSavedPaymentMethod( @@ -18,11 +19,14 @@ internal data class DisplayableSavedPaymentMethod( } fun getDescription() = when (paymentMethod.type) { - PaymentMethod.Type.Card -> resolvableString( - com.stripe.android.R.string.stripe_card_ending_in, - paymentMethod.card?.brand, - paymentMethod.card?.last4 - ) + PaymentMethod.Type.Card -> { + val brand = CardBrand.fromCode(paymentMethod.card?.displayBrand).displayName + resolvableString( + com.stripe.android.R.string.stripe_card_ending_in, + brand, + paymentMethod.card?.last4 + ) + } PaymentMethod.Type.SepaDebit -> resolvableString( R.string.stripe_bank_account_ending_in, paymentMethod.sepaDebit?.last4 diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt new file mode 100644 index 00000000000..790e0ef90f6 --- /dev/null +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt @@ -0,0 +1,33 @@ +package com.stripe.android.paymentsheet + +import android.content.Context +import android.os.Build +import androidx.test.core.app.ApplicationProvider.getApplicationContext +import com.google.common.truth.Truth.assertThat +import com.stripe.android.core.strings.resolvableString +import com.stripe.android.model.PaymentMethodFixtures +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import kotlin.test.Test + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [Build.VERSION_CODES.Q]) +class DisplayableSavedPaymentMethodTest { + + val context: Context = getApplicationContext() + + @Test + fun getDescription_usesDisplayedCardBrand() { + val visaCardUsingCartesBancaires = PaymentMethodFixtures.CARD_WITH_NETWORKS_PAYMENT_METHOD + val displayableSavedPaymentMethod = DisplayableSavedPaymentMethod( + displayName = "unused".resolvableString, + paymentMethod = visaCardUsingCartesBancaires + ) + + val description = displayableSavedPaymentMethod.getDescription().resolve(context) + + assertThat(description).isEqualTo("Cartes Bancaires ending in 4242") + } + +} \ No newline at end of file From 6e0fb870542e3a89ec99022974e7224b6361939d Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 26 Sep 2024 16:01:14 -0700 Subject: [PATCH 2/4] Fix lint issues --- .../android/paymentsheet/DisplayableSavedPaymentMethodTest.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt index 790e0ef90f6..f8e7c8b32ca 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt @@ -29,5 +29,4 @@ class DisplayableSavedPaymentMethodTest { assertThat(description).isEqualTo("Cartes Bancaires ending in 4242") } - -} \ No newline at end of file +} From bf883ae52fbc849553526b3202be6ac511d53dbd Mon Sep 17 00:00:00 2001 From: Annabella Koch Date: Thu, 26 Sep 2024 16:19:08 -0700 Subject: [PATCH 3/4] Use brand if display brand is missing --- .../paymentsheet/DisplayableSavedPaymentMethod.kt | 5 +++-- .../DisplayableSavedPaymentMethodTest.kt | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethod.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethod.kt index 6a2da11eb40..3f8a87af96f 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethod.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethod.kt @@ -20,10 +20,11 @@ internal data class DisplayableSavedPaymentMethod( fun getDescription() = when (paymentMethod.type) { PaymentMethod.Type.Card -> { - val brand = CardBrand.fromCode(paymentMethod.card?.displayBrand).displayName + val brand = paymentMethod.card?.displayBrand?.let { CardBrand.fromCode(it) } + ?: paymentMethod.card?.brand resolvableString( com.stripe.android.R.string.stripe_card_ending_in, - brand, + brand?.displayName, paymentMethod.card?.last4 ) } diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt index f8e7c8b32ca..137c972d498 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt @@ -29,4 +29,19 @@ class DisplayableSavedPaymentMethodTest { assertThat(description).isEqualTo("Cartes Bancaires ending in 4242") } + + @Test + fun getDescription_usesBrandIfDisplayBrandIsUnknown() { + val cardWithoutDisplayBrand = PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy( + card = PaymentMethodFixtures.CARD_PAYMENT_METHOD.card?.copy(displayBrand = null) + ) + val displayableSavedPaymentMethod = DisplayableSavedPaymentMethod( + displayName = "unused".resolvableString, + paymentMethod = cardWithoutDisplayBrand + ) + + val description = displayableSavedPaymentMethod.getDescription().resolve(context) + + assertThat(description).isEqualTo("Visa ending in 4242") + } } From d3809f5d4a03589aa8ed0d595426357bc29e1d44 Mon Sep 17 00:00:00 2001 From: Bella Koch <160939932+amk-stripe@users.noreply.github.com> Date: Fri, 27 Sep 2024 09:42:45 -0700 Subject: [PATCH 4/4] Update paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt Co-authored-by: Jay Newstrom --- .../android/paymentsheet/DisplayableSavedPaymentMethodTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt index 137c972d498..eb198d1113a 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt @@ -15,7 +15,7 @@ import kotlin.test.Test @Config(sdk = [Build.VERSION_CODES.Q]) class DisplayableSavedPaymentMethodTest { - val context: Context = getApplicationContext() + private val context: Context = getApplicationContext() @Test fun getDescription_usesDisplayedCardBrand() {