Skip to content

Commit

Permalink
Filter saved cards originating from a wallet when showing saved payme…
Browse files Browse the repository at this point in the history
…nt methods. (#7529)
  • Loading branch information
jaynewstrom-stripe authored Oct 27, 2023
1 parent 9e263c9 commit eea13db
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### PaymentSheet
* [FIXED][7499](https://github.com/stripe/stripe-android/pull/7499) Fixed an issue with incorrect error messages when encountering a failure after 3D Secure authentication.
* [FIXED][7529](https://github.com/stripe/stripe-android/pull/7529) PaymentSheet no longer displays saved cards that originated from Apple Pay or Google Pay.

## 20.34.1 - 2023-10-24

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.stripe.android.model.wallets

import android.os.Parcelable
import androidx.annotation.RestrictTo
import com.stripe.android.core.model.StripeModel
import com.stripe.android.model.Address
import kotlinx.parcelize.Parcelize
Expand All @@ -11,11 +12,14 @@ import kotlinx.parcelize.Parcelize
* [card.wallet](https://stripe.com/docs/api/payment_methods/object#payment_method_object-card-wallet)
*/
sealed class Wallet(
internal val walletType: Type
@get:RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
val walletType: Type
) : StripeModel {

@Parcelize
data class AmexExpressCheckoutWallet internal constructor(
data class AmexExpressCheckoutWallet
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
constructor(
val dynamicLast4: String?
) : Wallet(Type.AmexExpressCheckout)

Expand All @@ -25,7 +29,9 @@ sealed class Wallet(
) : Wallet(Type.ApplePay)

@Parcelize
data class GooglePayWallet internal constructor(
data class GooglePayWallet
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
constructor(
val dynamicLast4: String?
) : Wallet(Type.GooglePay), Parcelable

Expand All @@ -51,7 +57,8 @@ sealed class Wallet(
val dynamicLast4: String?
) : Wallet(Type.VisaCheckout)

internal enum class Type(val code: String) {
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
enum class Type(val code: String) {
AmexExpressCheckout("amex_express_checkout"),
ApplePay("apple_pay"),
GooglePay("google_pay"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.stripe.android.model.ElementsSession
import com.stripe.android.model.PaymentMethod
import com.stripe.android.model.PaymentMethod.Type.Link
import com.stripe.android.model.StripeIntent
import com.stripe.android.model.wallets.Wallet
import com.stripe.android.payments.core.injection.APP_NAME
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
Expand Down Expand Up @@ -212,6 +213,8 @@ internal class DefaultPaymentSheetLoader @Inject constructor(
PaymentMethod.Type.fromCode(it.code)
}

val walletTypesToRemove = setOf(Wallet.Type.ApplePay, Wallet.Type.GooglePay, Wallet.Type.SamsungPay)

val paymentMethods = customerRepository.getPaymentMethods(
customerConfig = customerConfig,
types = paymentMethodTypes.filter { paymentMethodType ->
Expand All @@ -222,7 +225,11 @@ internal class DefaultPaymentSheetLoader @Inject constructor(
)
},
silentlyFail = true,
).getOrDefault(emptyList())
).getOrDefault(emptyList()).filter { paymentMethod ->
val isCardWithWallet = paymentMethod.type == PaymentMethod.Type.Card &&
walletTypesToRemove.contains(paymentMethod.card?.wallet?.walletType)
!isCardWithWallet
}

return paymentMethods.filter { paymentMethod ->
paymentMethod.hasExpectedDetails()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.stripe.android.model.PaymentMethodFixtures
import com.stripe.android.model.StripeIntent
import com.stripe.android.model.StripeIntent.Status.Canceled
import com.stripe.android.model.StripeIntent.Status.Succeeded
import com.stripe.android.model.wallets.Wallet
import com.stripe.android.paymentsheet.FakePrefsRepository
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.PaymentSheetFixtures
Expand Down Expand Up @@ -289,6 +290,57 @@ internal class DefaultPaymentSheetLoaderTest {
.containsExactly(PaymentMethodFixtures.CARD_PAYMENT_METHOD)
}

@Test
fun `load() with customer should filter out cards attached to a filtered wallet`() =
runTest {
val result = createPaymentSheetLoader(
customerRepo = FakeCustomerRepository(
listOf(
PaymentMethodFixtures.CARD_PAYMENT_METHOD,
PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy(
card = PaymentMethodFixtures.CARD_PAYMENT_METHOD.card?.copy(
wallet = Wallet.GooglePayWallet("3000")
)
)
)
)
).load(
initializationMode = PaymentSheet.InitializationMode.PaymentIntent(
clientSecret = PaymentSheetFixtures.PAYMENT_INTENT_CLIENT_SECRET.value,
),
PaymentSheetFixtures.CONFIG_CUSTOMER_WITH_GOOGLEPAY
).getOrThrow()

assertThat(result.customerPaymentMethods)
.containsExactly(PaymentMethodFixtures.CARD_PAYMENT_METHOD)
}

@Test
fun `load() with customer should not filter out cards attached to a wallet`() =
runTest {
val cardWithAmexWallet = PaymentMethodFixtures.CARD_PAYMENT_METHOD.copy(
card = PaymentMethodFixtures.CARD_PAYMENT_METHOD.card?.copy(
wallet = Wallet.AmexExpressCheckoutWallet("3000")
)
)
val result = createPaymentSheetLoader(
customerRepo = FakeCustomerRepository(
listOf(
PaymentMethodFixtures.CARD_PAYMENT_METHOD,
cardWithAmexWallet
)
)
).load(
initializationMode = PaymentSheet.InitializationMode.PaymentIntent(
clientSecret = PaymentSheetFixtures.PAYMENT_INTENT_CLIENT_SECRET.value,
),
PaymentSheetFixtures.CONFIG_CUSTOMER_WITH_GOOGLEPAY
).getOrThrow()

assertThat(result.customerPaymentMethods)
.containsExactly(PaymentMethodFixtures.CARD_PAYMENT_METHOD, cardWithAmexWallet)
}

// PayPal isn't supported as a saved payment method due to issues with on-session.
// See: https://docs.google.com/document/d/1_bCPJXxhV4Kdgy7LX7HPwpZfElN3a2DcYUooiWC9SgM
@Test
Expand Down

0 comments on commit eea13db

Please sign in to comment.