diff --git a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/cvcrecollection/CvcRecollectionHandlerImpl.kt b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/cvcrecollection/CvcRecollectionHandlerImpl.kt index 6b75719303b..81a194c633c 100644 --- a/paymentsheet/src/main/java/com/stripe/android/paymentsheet/cvcrecollection/CvcRecollectionHandlerImpl.kt +++ b/paymentsheet/src/main/java/com/stripe/android/paymentsheet/cvcrecollection/CvcRecollectionHandlerImpl.kt @@ -42,6 +42,7 @@ internal class CvcRecollectionHandlerImpl : CvcRecollectionHandler { val hasNotRecollectedCvcAlready = optionsParams == null || !optionsParams.hasAlreadyRecollectedCvc() return paymentMethod.isCard() && + paymentMethod.hasNoWallet() && cvcRecollectionEnabled(stripeIntent, initializationMode) && hasNotRecollectedCvcAlready } @@ -50,6 +51,10 @@ internal class CvcRecollectionHandlerImpl : CvcRecollectionHandler { return type == PaymentMethod.Type.Card } + private fun PaymentMethod.hasNoWallet(): Boolean { + return card?.wallet == null + } + private fun StripeIntent.supportsCvcRecollection(): Boolean { return when (this) { is PaymentIntent -> requireCvcRecollection diff --git a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/cvcrecollection/CvcRecollectionHandlerTest.kt b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/cvcrecollection/CvcRecollectionHandlerTest.kt index 3198c2294c0..8c1a9889f0b 100644 --- a/paymentsheet/src/test/java/com/stripe/android/paymentsheet/cvcrecollection/CvcRecollectionHandlerTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/paymentsheet/cvcrecollection/CvcRecollectionHandlerTest.kt @@ -4,6 +4,7 @@ import com.google.common.truth.Truth.assertThat import com.stripe.android.model.PaymentIntentFixtures import com.stripe.android.model.PaymentMethodFixtures import com.stripe.android.model.PaymentMethodOptionsParams +import com.stripe.android.model.wallets.Wallet import com.stripe.android.paymentsheet.PaymentSheet import com.stripe.android.paymentsheet.paymentdatacollection.cvcrecollection.CvcRecollectionData import com.stripe.android.paymentsheet.state.PaymentElementLoader @@ -61,7 +62,7 @@ class CvcRecollectionHandlerTest { } @Test - fun `card & intent requiring cvc recollection should return false is CVC is in options params`() { + fun `card & intent requiring cvc recollection should return false if CVC is in options params`() { val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD_CVC_RECOLLECTION val paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD val response = handler.requiresCVCRecollection( @@ -73,6 +74,21 @@ class CvcRecollectionHandlerTest { assertThat(response).isFalse() } + @Test + fun `card & intent requiring cvc recollection should return false if card is from a wallet`() { + val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD_CVC_RECOLLECTION + val paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD.run { + copy(card = card?.copy(wallet = Wallet.GooglePayWallet(dynamicLast4 = null))) + } + val response = handler.requiresCVCRecollection( + stripeIntent = paymentIntent, + paymentMethod = paymentMethod, + optionsParams = null, + initializationMode = PaymentElementLoader.InitializationMode.PaymentIntent("") + ) + assertThat(response).isFalse() + } + @Test fun `card payment method with deferred init and enabled deferred cvc recollection should return true`() { val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD @@ -126,7 +142,7 @@ class CvcRecollectionHandlerTest { } @Test - fun `card & valid deferred intent should return false is CVC is in options params`() { + fun `card & valid deferred intent should return false if CVC is in options params`() { val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD val response = handler.requiresCVCRecollection( stripeIntent = paymentIntent, @@ -145,6 +161,29 @@ class CvcRecollectionHandlerTest { assertThat(response).isFalse() } + @Test + fun `card & valid deferred intent should return false if card is from a wallet`() { + val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD + val paymentMethod = PaymentMethodFixtures.CARD_PAYMENT_METHOD.run { + copy(card = card?.copy(wallet = Wallet.GooglePayWallet(dynamicLast4 = null))) + } + val response = handler.requiresCVCRecollection( + stripeIntent = paymentIntent, + paymentMethod = paymentMethod, + optionsParams = null, + initializationMode = PaymentElementLoader.InitializationMode.DeferredIntent( + intentConfiguration = PaymentSheet.IntentConfiguration( + mode = PaymentSheet.IntentConfiguration.Mode.Payment( + amount = 1234, + currency = "cad", + ), + requireCvcRecollection = true + ) + ) + ) + assertThat(response).isFalse() + } + @Test fun `cvcRecEnabled - cvc rec payment intent, cvc rec config enabled, and deferred intent returned true`() { val paymentIntent = PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD_CVC_RECOLLECTION