From fe48bf8cd4501e3a8b4671fdc612ae0779546807 Mon Sep 17 00:00:00 2001 From: toluo-stripe Date: Thu, 9 Jan 2025 13:29:58 -0500 Subject: [PATCH 1/2] Support Cvc Recollection and add fake to LinkConfirmationHandler --- .../confirmation/DefaultLinkConfirmationHandler.kt | 14 +++++++++----- .../link/confirmation/LinkConfirmationHandler.kt | 3 ++- .../DefaultLinkConfirmationHandlerTest.kt | 12 ++++++++++-- .../confirmation/FakeLinkConfirmationHandler.kt | 14 ++++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 paymentsheet/src/test/java/com/stripe/android/link/confirmation/FakeLinkConfirmationHandler.kt diff --git a/paymentsheet/src/main/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandler.kt b/paymentsheet/src/main/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandler.kt index d1dbca7a6bf..fd324e77c50 100644 --- a/paymentsheet/src/main/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandler.kt +++ b/paymentsheet/src/main/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandler.kt @@ -22,10 +22,11 @@ internal class DefaultLinkConfirmationHandler @Inject constructor( ) : LinkConfirmationHandler { override suspend fun confirm( paymentDetails: ConsumerPaymentDetails.PaymentDetails, - linkAccount: LinkAccount + linkAccount: LinkAccount, + cvc: String? ): Result { return runCatching { - val args = confirmationArgs(paymentDetails, linkAccount) + val args = confirmationArgs(paymentDetails, linkAccount, cvc) confirmationHandler.start(args) val result = confirmationHandler.awaitResult() transformResult(result) @@ -58,14 +59,16 @@ internal class DefaultLinkConfirmationHandler @Inject constructor( private fun confirmationArgs( paymentDetails: ConsumerPaymentDetails.PaymentDetails, - linkAccount: LinkAccount + linkAccount: LinkAccount, + cvc: String? ): ConfirmationHandler.Args { return ConfirmationHandler.Args( intent = configuration.stripeIntent, confirmationOption = PaymentMethodConfirmationOption.New( createParams = createPaymentMethodCreateParams( selectedPaymentDetails = paymentDetails, - linkAccount = linkAccount + linkAccount = linkAccount, + cvc = cvc ), optionsParams = null, shouldSave = false @@ -91,11 +94,12 @@ internal class DefaultLinkConfirmationHandler @Inject constructor( private fun createPaymentMethodCreateParams( selectedPaymentDetails: ConsumerPaymentDetails.PaymentDetails, linkAccount: LinkAccount, + cvc: String? ): PaymentMethodCreateParams { return PaymentMethodCreateParams.createLink( paymentDetailsId = selectedPaymentDetails.id, consumerSessionClientSecret = linkAccount.clientSecret, - extraParams = emptyMap(), + extraParams = cvc?.let { mapOf("card" to mapOf("cvc" to cvc)) }, ) } diff --git a/paymentsheet/src/main/java/com/stripe/android/link/confirmation/LinkConfirmationHandler.kt b/paymentsheet/src/main/java/com/stripe/android/link/confirmation/LinkConfirmationHandler.kt index 85e9f70e1f2..d0848829edb 100644 --- a/paymentsheet/src/main/java/com/stripe/android/link/confirmation/LinkConfirmationHandler.kt +++ b/paymentsheet/src/main/java/com/stripe/android/link/confirmation/LinkConfirmationHandler.kt @@ -8,7 +8,8 @@ import com.stripe.android.paymentelement.confirmation.ConfirmationHandler internal interface LinkConfirmationHandler { suspend fun confirm( paymentDetails: ConsumerPaymentDetails.PaymentDetails, - linkAccount: LinkAccount + linkAccount: LinkAccount, + cvc: String? = null ): Result fun interface Factory { diff --git a/paymentsheet/src/test/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandlerTest.kt b/paymentsheet/src/test/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandlerTest.kt index cb4c79ea3bd..6d1f6ac2436 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandlerTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandlerTest.kt @@ -41,7 +41,8 @@ internal class DefaultLinkConfirmationHandlerTest { val result = handler.confirm( paymentDetails = TestFactory.CONSUMER_PAYMENT_DETAILS_CARD, - linkAccount = TestFactory.LINK_ACCOUNT + linkAccount = TestFactory.LINK_ACCOUNT, + cvc = "333" ) assertThat(result).isEqualTo(Result.Succeeded) @@ -49,6 +50,7 @@ internal class DefaultLinkConfirmationHandlerTest { configuration = configuration, linkAccount = TestFactory.LINK_ACCOUNT, paymentDetails = TestFactory.CONSUMER_PAYMENT_DETAILS_CARD, + cvc = CVC, initMode = PaymentElementLoader.InitializationMode.PaymentIntent( clientSecret = configuration.stripeIntent.clientSecret.orEmpty() ) @@ -83,6 +85,7 @@ internal class DefaultLinkConfirmationHandlerTest { configuration = configuration, linkAccount = TestFactory.LINK_ACCOUNT, paymentDetails = TestFactory.CONSUMER_PAYMENT_DETAILS_CARD, + cvc = null, initMode = PaymentElementLoader.InitializationMode.SetupIntent( clientSecret = configuration.stripeIntent.clientSecret.orEmpty() ) @@ -192,6 +195,7 @@ internal class DefaultLinkConfirmationHandlerTest { configuration: LinkConfiguration, paymentDetails: ConsumerPaymentDetails.PaymentDetails, linkAccount: LinkAccount, + cvc: String?, initMode: PaymentElementLoader.InitializationMode ) { assertThat(intent).isEqualTo(configuration.stripeIntent) @@ -200,7 +204,7 @@ internal class DefaultLinkConfirmationHandlerTest { PaymentMethodCreateParams.createLink( paymentDetailsId = paymentDetails.id, consumerSessionClientSecret = linkAccount.clientSecret, - extraParams = emptyMap(), + extraParams = cvc?.let { mapOf("card" to mapOf("cvc" to cvc)) }, ) ) assertThat(shippingDetails).isEqualTo(configuration.shippingDetails) @@ -220,4 +224,8 @@ internal class DefaultLinkConfirmationHandlerTest { confirmationHandler.validate() return handler } + + companion object { + private const val CVC = "333" + } } diff --git a/paymentsheet/src/test/java/com/stripe/android/link/confirmation/FakeLinkConfirmationHandler.kt b/paymentsheet/src/test/java/com/stripe/android/link/confirmation/FakeLinkConfirmationHandler.kt new file mode 100644 index 00000000000..ea50e090bee --- /dev/null +++ b/paymentsheet/src/test/java/com/stripe/android/link/confirmation/FakeLinkConfirmationHandler.kt @@ -0,0 +1,14 @@ +package com.stripe.android.link.confirmation + +import com.stripe.android.link.model.LinkAccount +import com.stripe.android.model.ConsumerPaymentDetails + +internal class FakeLinkConfirmationHandler : LinkConfirmationHandler { + var confirmResult: Result = Result.Succeeded + + override suspend fun confirm( + paymentDetails: ConsumerPaymentDetails.PaymentDetails, + linkAccount: LinkAccount, + cvc: String? + ) = confirmResult +} From 78cc897b14505199766b63f11d08e9f569a81ff6 Mon Sep 17 00:00:00 2001 From: toluo-stripe Date: Fri, 10 Jan 2025 16:53:39 -0500 Subject: [PATCH 2/2] Use CVC variable --- .../link/confirmation/DefaultLinkConfirmationHandlerTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/paymentsheet/src/test/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandlerTest.kt b/paymentsheet/src/test/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandlerTest.kt index 6d1f6ac2436..db7cdaa49ea 100644 --- a/paymentsheet/src/test/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandlerTest.kt +++ b/paymentsheet/src/test/java/com/stripe/android/link/confirmation/DefaultLinkConfirmationHandlerTest.kt @@ -42,7 +42,7 @@ internal class DefaultLinkConfirmationHandlerTest { val result = handler.confirm( paymentDetails = TestFactory.CONSUMER_PAYMENT_DETAILS_CARD, linkAccount = TestFactory.LINK_ACCOUNT, - cvc = "333" + cvc = CVC ) assertThat(result).isEqualTo(Result.Succeeded)