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..3f8a87af96f 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,15 @@ 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 = paymentMethod.card?.displayBrand?.let { CardBrand.fromCode(it) } + ?: paymentMethod.card?.brand + resolvableString( + com.stripe.android.R.string.stripe_card_ending_in, + brand?.displayName, + 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..eb198d1113a --- /dev/null +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/DisplayableSavedPaymentMethodTest.kt @@ -0,0 +1,47 @@ +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 { + + private 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") + } + + @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") + } +}