Skip to content
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

Support Cvc Recollection and add fake to LinkConfirmationHandler #9884

Merged
merged 2 commits into from
Jan 13, 2025
Merged
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
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)) },
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little unsure of whether this is the best way to include CVC in the confirm call. Conceptually, it seems like maybe this should be part of the PaymentDetails type (though that type is public so we probably can't change it). Also how does the CVC value here relate to the CvcCheck in the ConsumerPaymentDetails.Card type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cvc field is obtained after cvc recollection and he payment details represents the payment methods obtained from the backend. We could wrap both values in a new data class.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotchaaa

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll wrap both values in my integration PR

): Result

fun interface Factory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ internal class DefaultLinkConfirmationHandlerTest {

val result = handler.confirm(
paymentDetails = TestFactory.CONSUMER_PAYMENT_DETAILS_CARD,
linkAccount = TestFactory.LINK_ACCOUNT
linkAccount = TestFactory.LINK_ACCOUNT,
cvc = CVC
)

assertThat(result).isEqualTo(Result.Succeeded)
confirmationHandler.startTurbine.awaitItem().assertConfirmationArgs(
configuration = configuration,
linkAccount = TestFactory.LINK_ACCOUNT,
paymentDetails = TestFactory.CONSUMER_PAYMENT_DETAILS_CARD,
cvc = CVC,
amk-stripe marked this conversation as resolved.
Show resolved Hide resolved
initMode = PaymentElementLoader.InitializationMode.PaymentIntent(
clientSecret = configuration.stripeIntent.clientSecret.orEmpty()
)
Expand Down Expand Up @@ -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()
)
Expand Down Expand Up @@ -192,6 +195,7 @@ internal class DefaultLinkConfirmationHandlerTest {
configuration: LinkConfiguration,
paymentDetails: ConsumerPaymentDetails.PaymentDetails,
linkAccount: LinkAccount,
cvc: String?,
initMode: PaymentElementLoader.InitializationMode
) {
assertThat(intent).isEqualTo(configuration.stripeIntent)
Expand All @@ -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)
Expand All @@ -220,4 +224,8 @@ internal class DefaultLinkConfirmationHandlerTest {
confirmationHandler.validate()
return handler
}

companion object {
private const val CVC = "333"
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Loading