Skip to content

Commit

Permalink
Ensure CVC recollection is not done for payment methods from wallet c…
Browse files Browse the repository at this point in the history
…ards. (#9887)
  • Loading branch information
samer-stripe authored Jan 10, 2025
1 parent 3147184 commit 923851d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ internal class CvcRecollectionHandlerImpl : CvcRecollectionHandler {
val hasNotRecollectedCvcAlready = optionsParams == null || !optionsParams.hasAlreadyRecollectedCvc()

return paymentMethod.isCard() &&
paymentMethod.hasNoWallet() &&
cvcRecollectionEnabled(stripeIntent, initializationMode) &&
hasNotRecollectedCvcAlready
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 923851d

Please sign in to comment.