Skip to content
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 @@ -12,6 +12,7 @@ import com.stripe.android.model.ConfirmationTokenClientContextParams
import com.stripe.android.model.ConfirmationTokenParams
import com.stripe.android.model.DeferredIntentParams
import com.stripe.android.model.MandateDataParams
import com.stripe.android.model.PaymentMethod
import com.stripe.android.model.PaymentMethodOptionsParams
import com.stripe.android.model.RadarOptions
import com.stripe.android.model.StripeIntent
Expand Down Expand Up @@ -48,6 +49,8 @@ internal class ConfirmationTokenConfirmationInterceptor @AssistedInject construc
confirmationOption: PaymentMethodConfirmationOption.New,
shippingValues: ConfirmPaymentIntentParams.Shipping?
): ConfirmationDefinition.Action<Args> {
failIfUnsupportedPaymentMethod(confirmationOption.createParams.typeCode)

return stripeRepository.createConfirmationToken(
confirmationTokenParams = prepareConfirmationTokenParams(
confirmationOption,
Expand Down Expand Up @@ -81,6 +84,8 @@ internal class ConfirmationTokenConfirmationInterceptor @AssistedInject construc
shippingValues: ConfirmPaymentIntentParams.Shipping?
): ConfirmationDefinition.Action<Args> {
val paymentMethod = confirmationOption.paymentMethod
failIfUnsupportedPaymentMethod(paymentMethod.type?.code)

return stripeRepository.createConfirmationToken(
confirmationTokenParams = prepareConfirmationTokenParams(
confirmationOption,
Expand Down Expand Up @@ -253,6 +258,21 @@ internal class ConfirmationTokenConfirmationInterceptor @AssistedInject construc
}
}

private fun failIfUnsupportedPaymentMethod(paymentMethodCode: String?) {
val unsupportedPaymentMethods = setOf(
PaymentMethod.Type.Konbini.code,
PaymentMethod.Type.Blik.code,
)

if (paymentMethodCode in unsupportedPaymentMethods && !requestOptions.apiKeyIsLiveMode) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the behavior in live mode? ie what is the user experience if they are trying to check out with Konbini + CTs in live mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the best way to test that? If I simply remove the assertion and try in playground, it would look like this:

Screen_recording_20251016_221319.mp4

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll follow up on this on slack

throw IllegalStateException(
"(Test-mode only error) The payment method '$paymentMethodCode' is not yet supported with " +
"confirmation tokens. Please contact us if you'd like to use this feature via a GitHub " +
"issue on stripe-android."
)
}
}

@AssistedFactory
interface Factory {
fun create(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,138 @@ class ConfirmationTokenConfirmationInterceptorTest {
}
}

@Test
fun `Fails with Konbini payment method in test mode`() {
val konbiniCreateParams = PaymentMethodCreateParams(
code = "konbini",
requiresMandate = false,
billingDetails = PaymentMethodCreateParamsFixtures.BILLING_DETAILS,
)

runConfirmationTokenInterceptorScenario { interceptor ->
val confirmationOption = PaymentMethodConfirmationOption.New(
createParams = konbiniCreateParams,
optionsParams = null,
extraParams = null,
shouldSave = false,
passiveCaptchaParams = null,
)

val exception = runCatching {
interceptor.intercept(
intent = PaymentIntentFactory.create(),
confirmationOption = confirmationOption,
shippingValues = null,
)
}.exceptionOrNull()

assertThat(exception).isInstanceOf<IllegalStateException>()
assertThat(exception?.message).isEqualTo(
"(Test-mode only error) The payment method 'konbini' " +
"is not yet supported with confirmation tokens. " +
"Please contact us if you'd like to use this feature via a GitHub " +
"issue on stripe-android."
)
}
}

@Test
fun `Fails with Blik payment method in test mode`() {
val blikCreateParams = PaymentMethodCreateParams.createBlik(
billingDetails = PaymentMethodCreateParamsFixtures.BILLING_DETAILS,
)

runConfirmationTokenInterceptorScenario { interceptor ->
val confirmationOption = PaymentMethodConfirmationOption.New(
createParams = blikCreateParams,
optionsParams = null,
extraParams = null,
shouldSave = false,
passiveCaptchaParams = null,
)

val exception = runCatching {
interceptor.intercept(
intent = PaymentIntentFactory.create(),
confirmationOption = confirmationOption,
shippingValues = null,
)
}.exceptionOrNull()

assertThat(exception).isInstanceOf<IllegalStateException>()
assertThat(exception?.message).isEqualTo(
"(Test-mode only error) The payment method 'blik' " +
"is not yet supported with confirmation tokens. " +
"Please contact us if you'd like to use this feature via a GitHub " +
"issue on stripe-android."
)
}
}

@Test
fun `Succeeds with Konbini payment method in live mode`() {
val konbiniCreateParams = PaymentMethodCreateParams(
code = "konbini",
requiresMandate = false,
billingDetails = PaymentMethodCreateParamsFixtures.BILLING_DETAILS,
)

runConfirmationTokenInterceptorScenario(isLiveMode = true) { interceptor ->
val confirmationOption = PaymentMethodConfirmationOption.New(
createParams = konbiniCreateParams,
optionsParams = null,
extraParams = null,
shouldSave = false,
passiveCaptchaParams = null,
)

val nextStep = interceptor.intercept(
intent = PaymentIntentFactory.create(),
confirmationOption = confirmationOption,
shippingValues = null,
)

assertThat(nextStep).isEqualTo(
ConfirmationDefinition.Action.Complete<IntentConfirmationDefinition.Args>(
intent = PaymentIntentFixtures.PI_SUCCEEDED,
deferredIntentConfirmationType = DeferredIntentConfirmationType.Server,
completedFullPaymentFlow = true,
)
)
}
}

@Test
fun `Succeeds with Blik payment method in live mode`() {
val blikCreateParams = PaymentMethodCreateParams.createBlik(
billingDetails = PaymentMethodCreateParamsFixtures.BILLING_DETAILS,
)

runConfirmationTokenInterceptorScenario(isLiveMode = true) { interceptor ->
val confirmationOption = PaymentMethodConfirmationOption.New(
createParams = blikCreateParams,
optionsParams = null,
extraParams = null,
shouldSave = false,
passiveCaptchaParams = null,
)

val nextStep = interceptor.intercept(
intent = PaymentIntentFactory.create(),
confirmationOption = confirmationOption,
shippingValues = null,
)

assertThat(nextStep).isEqualTo(
ConfirmationDefinition.Action.Complete<IntentConfirmationDefinition.Args>(
intent = PaymentIntentFixtures.PI_SUCCEEDED,
deferredIntentConfirmationType = DeferredIntentConfirmationType.Server,
completedFullPaymentFlow = true,
)
)
}
}

@Test
fun `Saved PM - includes radarOptions when hCaptchaToken is provided for CSC flow`() {
runConfirmationTokenInterceptorScenario(
Expand Down Expand Up @@ -1161,12 +1293,14 @@ class ConfirmationTokenConfirmationInterceptorTest {
observedParams: Turbine<ConfirmationTokenParams> = Turbine(),
retrievedIntentStatus: StripeIntent.Status = StripeIntent.Status.Succeeded,
initializationMode: PaymentElementLoader.InitializationMode = DEFAULT_DEFERRED_INTENT,
isLiveMode: Boolean = false,
block: suspend (IntentConfirmationInterceptor) -> Unit
) {
runInterceptorScenario(
initializationMode = initializationMode,
scenario = InterceptorTestScenario(
ephemeralKeySecret = "ek_test_123",
publishableKeyProvider = { if (isLiveMode) "pk_live_123" else "pk_test_123" },
stripeRepository = createFakeStripeRepositoryForConfirmationToken(
observedParams,
retrievedIntentStatus,
Expand Down
Loading