Skip to content

Add new payment option label for Link PMs #10887

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
@@ -1,6 +1,7 @@
package com.stripe.android.link.ui.wallet

import com.stripe.android.core.strings.ResolvableString
import com.stripe.android.core.strings.plus
import com.stripe.android.core.strings.resolvableString
import com.stripe.android.model.CardBrand
import com.stripe.android.model.ConsumerPaymentDetails
Expand All @@ -22,6 +23,12 @@ internal val LinkPaymentDetails.sublabel: ResolvableString?
is BankAccount -> if (bankName != null) "••••$last4".resolvableString else null
}

internal val LinkPaymentDetails.paymentOptionLabel: ResolvableString
get() {
val components = listOfNotNull(label, sublabel)
return components.joinToString(separator = " ")
}

internal val ConsumerPaymentDetails.PaymentDetails.displayName: ResolvableString
get() = when (this) {
is ConsumerPaymentDetails.Card -> makeCardDisplayName(nickname, funding, brand)
Expand Down Expand Up @@ -50,3 +57,9 @@ private fun makeFallbackCardName(funding: String, brand: String): ResolvableStri
else -> resolvableString(R.string.stripe_link_card_type_unknown, brand)
}
}

private fun List<ResolvableString>.joinToString(separator: String): ResolvableString {
return reduce { acc, text ->
acc + separator.resolvableString + text
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.stripe.android.paymentsheet.ui.createCardLabel
import com.stripe.android.paymentsheet.ui.getCardBrandIcon
import com.stripe.android.paymentsheet.ui.getLabel
import com.stripe.android.paymentsheet.ui.getLinkIcon
import com.stripe.android.paymentsheet.ui.getPaymentOptionLabel
import com.stripe.android.paymentsheet.ui.getSavedPaymentMethodIcon
import com.stripe.android.uicore.image.StripeImageLoader
import kotlinx.parcelize.IgnoredOnParcel
Expand Down Expand Up @@ -407,7 +408,7 @@ internal val PaymentSelection.label: ResolvableString
}

private fun getSavedLabel(selection: PaymentSelection.Saved): ResolvableString? {
return selection.paymentMethod.getLabel(canShowSublabel = true) ?: run {
return selection.paymentMethod.getPaymentOptionLabel() ?: run {
when (selection.walletType) {
PaymentSelection.Saved.WalletType.Link -> StripeR.string.stripe_link.resolvableString
PaymentSelection.Saved.WalletType.GooglePay -> StripeR.string.stripe_google_pay.resolvableString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.annotation.DrawableRes
import com.stripe.android.core.strings.ResolvableString
import com.stripe.android.core.strings.resolvableString
import com.stripe.android.link.ui.wallet.label
import com.stripe.android.link.ui.wallet.paymentOptionLabel
import com.stripe.android.link.ui.wallet.sublabel
import com.stripe.android.model.CardBrand
import com.stripe.android.model.CardBrand.Unknown
Expand Down Expand Up @@ -232,6 +233,28 @@ internal fun PaymentMethod.getLabel(canShowSublabel: Boolean = false): Resolvabl
else -> null
}

internal fun PaymentMethod.getPaymentOptionLabel(): ResolvableString? = when (type) {
PaymentMethod.Type.Card -> {
if (isLinkPaymentMethod) {
linkPaymentDetails?.paymentOptionLabel
} else {
createCardLabel(card?.last4)
}
}
PaymentMethod.Type.SepaDebit -> resolvableString(
R.string.stripe_paymentsheet_payment_method_item_card_number,
sepaDebit?.last4
)
PaymentMethod.Type.USBankAccount -> resolvableString(
R.string.stripe_paymentsheet_payment_method_item_card_number,
usBankAccount?.last4
)
PaymentMethod.Type.Link -> {
linkPaymentDetails?.paymentOptionLabel
}
else -> null
}

internal fun PaymentMethod.getLabelIcon(): Int? = when (type) {
PaymentMethod.Type.Card -> {
when (linkPaymentDetails) {
Expand Down
Loading