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

Crash in test mode when using deferred SSC with set as default feature #10273

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -408,6 +408,7 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor(
): NextStep {
return retrieveStripeIntent(clientSecret).mapCatching { intent ->
if (intent.isConfirmed) {
failIfSetAsDefaultFeatureIsEnabled(paymentMethodExtraParams)
NextStep.Complete(isForceSuccess = false)
} else if (intent.requiresAction()) {
val attachedPaymentMethodId = intent.paymentMethodId
Expand Down Expand Up @@ -521,6 +522,27 @@ internal class DefaultIntentConfirmationInterceptor @Inject constructor(
)
}

private fun failIfSetAsDefaultFeatureIsEnabled(paymentMethodExtraParams: PaymentMethodExtraParams?) {
// Ideally, we would crash anytime the set as default checkbox is shown, rather than just when it is checked.
// We could check if it is shown by asserting that setAsDefault != null instead of asserting that it is true.
// However, we don't have good end-to-end test coverage of this for now, so if we made a change to start
// sending the set as default flag as false more frequently, we could accidentally start failing here more
// often as well.
val setAsDefaultChecked = when (paymentMethodExtraParams) {
is PaymentMethodExtraParams.Card -> paymentMethodExtraParams.setAsDefault == true
is PaymentMethodExtraParams.USBankAccount -> paymentMethodExtraParams.setAsDefault == true
is PaymentMethodExtraParams.BacsDebit, null -> false
}

if (setAsDefaultChecked && !requestOptions.apiKeyIsLiveMode) {
throw IllegalStateException(
"(Test-mode only error) The default payment methods feature is not yet supported with deferred " +
"server-side confirmation. Please contact us if you'd like to use this feature via a Github " +
"issue on stripe-android."
)
}
}

private companion object {
private const val INTENT_CALLBACK_FETCH_TIMEOUT = 2
private const val INTENT_CALLBACK_FETCH_INTERVAL = 5L
Expand Down
Loading