Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update saved card description to use displayed brand #9351

Merged
merged 4 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
}
}
Loading