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

[BUG] IllegalStateException: CreateIntentCallback must be implemented when using IntentConfiguration with PaymentSheet #9760

Open
hjdealba96 opened this issue Dec 6, 2024 · 2 comments
Labels
bug triaged Issue has been reviewed by Stripe and is being tracked internally

Comments

@hjdealba96
Copy link

hjdealba96 commented Dec 6, 2024

Summary

Hello there! Recently, we've integrated PaymentSheet + IntentConfiguration in our project to collect user's payment methods. While the integration seems to be working fine, we've been getting occasional reports of this crash associated with a missing CreateIntentCallback callback:

Fatal Exception: java.lang.IllegalStateException: CreateIntentCallback must be implemented when using IntentConfiguration with PaymentSheet
       at com.stripe.android.paymentsheet.DefaultIntentConfirmationInterceptor.handleDeferredIntent(IntentConfirmationInterceptor.kt:248)
       at com.stripe.android.paymentsheet.DefaultIntentConfirmationInterceptor.handleDeferredIntent(IntentConfirmationInterceptor.kt:210)
       at com.stripe.android.paymentsheet.DefaultIntentConfirmationInterceptor.intercept(IntentConfirmationInterceptor.kt:122)
       at com.stripe.android.paymentsheet.IntentConfirmationInterceptorKtxKt.intercept(IntentConfirmationInterceptorKtx.kt:10)
       at com.stripe.android.paymentsheet.IntentConfirmationDefinition.action(IntentConfirmationDefinition.kt:29)
       at com.stripe.android.paymentsheet.IntentConfirmationHandler.confirmIntent(IntentConfirmationHandler.kt:267)
       at com.stripe.android.paymentsheet.IntentConfirmationHandler.confirm(IntentConfirmationHandler.kt:238)
       at com.stripe.android.paymentsheet.IntentConfirmationHandler.preconfirm(IntentConfirmationHandler.kt:222)
       at com.stripe.android.paymentsheet.IntentConfirmationHandler.access$get_state$p(IntentConfirmationHandler.kt:51)
       at com.stripe.android.paymentsheet.IntentConfirmationHandler.access$preconfirm(IntentConfirmationHandler.kt:51)
       at com.stripe.android.paymentsheet.IntentConfirmationHandler$start$1.invokeSuspend(IntentConfirmationHandler.kt:186)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
       at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.java:113)
       at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:589)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:823)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707)

We have tried several times to replicate this crash on our end with no success. As you can see in the stack trace, there are no lines associated with our project's codebase. Seems like this exception is thrown from the internals of the SDK?

Hope someone can give me a hand solving this issue. I'd really appreciated it!

Code to reproduce

Following the official documentation, here's how the PaymentSheet is instantiated and receives the callbacks:

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
       super.onViewCreated(view, savedInstanceState)
       paymentSheet = PaymentSheet(this, ::onCreateSetupIntent, ::onPaymentSheetResult)
}

NOTE: ::onCreateSetupIntent implements CreateIntentCallback, which is supposed to be the missing callback mentioned in the stack trace, isn't it?

These are the implementations of the callbacks using function references:

private suspend fun onCreateSetupIntent(
        paymentMethod: PaymentMethod,
        shouldSavePaymentMethod: Boolean,
    ): CreateIntentResult {

        val setupIntentSecret = stripeViewModel.getStripePaymentCredentials()?.setupIntent

        return if (setupIntentSecret != null) {
            addedPaymentMethod = paymentMethod.asCardUiModel()
            CreateIntentResult.Success(setupIntentSecret)
        } else {
            CreateIntentResult.Failure(Exception())
        }

    }
    
 private fun onPaymentSheetResult(paymentSheetResult: PaymentSheetResult) {
        when (paymentSheetResult) {
            PaymentSheetResult.Completed -> {
                addedPaymentMethod?.let { addedPayment ->
                    stripeViewModel.savePrimaryPaymentMethod(addedPayment)
                }
                addedPaymentMethod = null
            }
            is PaymentSheetResult.Failed -> {
                appLogger.error(
                    exception = paymentSheetResult.error,
                    message = "Something went wrong while attaching payment method"
                )
                dismiss()
            }
            else -> dismiss()
        }
    }    

And this is how the PaymentSheet is launched:

paymentSheet.presentWithIntentConfiguration(
        intentConfiguration = PaymentSheet.IntentConfiguration(
            mode = PaymentSheet.IntentConfiguration.Mode.Setup(
                setupFutureUse = SetupFutureUse.OnSession
            )
        ),
        configuration = PaymentSheet.Configuration.Builder(merchantDisplayName = context.getString(R.string.merchant_name))
            .apply {
                appearance(PaymentSheetStyle.defaultAppearance(context))
                primaryButtonLabel(context.getString(R.string.action_add))
            }.build()
    )

Android version and Impacted devices

So far the vast majority of the reports on Firebase Crashlytics come from Samsung phones with Android 14, but also from some Motorola models with Android 12 and 14.

Installation method

Gradle

Dependency Versions

We're using the SDK version 20.53.0

@hjdealba96 hjdealba96 added the bug label Dec 6, 2024
@saugs
Copy link

saugs commented Dec 13, 2024

Hello, same here we have this crash for Android 12 and Android 14 devices and unable to reproduce on other devices :

          Fatal Exception: java.lang.IllegalStateException: a must be implemented when using IntentConfiguration with PaymentSheet
       at com.stripe.android.paymentelement.confirmation.intent.DefaultIntentConfirmationInterceptor.handleDeferredIntent(IntentConfirmationInterceptor.kt:255)
       at com.stripe.android.paymentelement.confirmation.intent.DefaultIntentConfirmationInterceptor.handleDeferredIntent(IntentConfirmationInterceptor.kt:217)
       at com.stripe.android.paymentelement.confirmation.intent.DefaultIntentConfirmationInterceptor.intercept(IntentConfirmationInterceptor.kt:128)
       at com.stripe.android.paymentelement.confirmation.intent.IntentConfirmationInterceptorKtxKt.intercept(IntentConfirmationInterceptorKtx.kt:11)
       at com.stripe.android.paymentelement.confirmation.intent.IntentConfirmationDefinition.action(IntentConfirmationDefinition.kt:38)
       at com.stripe.android.paymentelement.confirmation.intent.IntentConfirmationDefinition.action(IntentConfirmationDefinition.kt:19)
       at com.stripe.android.paymentelement.confirmation.ConfirmationMediator.action(ConfirmationMediator.kt:85)
       at com.stripe.android.paymentelement.confirmation.DefaultConfirmationHandler.confirm(DefaultConfirmationHandler.kt:289)
       at com.stripe.android.paymentelement.confirmation.DefaultConfirmationHandler.confirm(DefaultConfirmationHandler.kt:254)
       at com.stripe.android.paymentelement.confirmation.DefaultConfirmationHandler.preconfirm(DefaultConfirmationHandler.kt:238)
       at com.stripe.android.paymentelement.confirmation.DefaultConfirmationHandler.access$preconfirm(DefaultConfirmationHandler.java:60)
       at com.stripe.android.paymentelement.confirmation.DefaultConfirmationHandler$start$1.invokeSuspend(DefaultConfirmationHandler.kt:202)
       at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
       at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
       at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113)
       at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
       at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:589)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:823)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
       at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707)

@joyceqin-stripe
Copy link

Hi @hjdealba96, thanks for reporting! We'll look into this.

@joyceqin-stripe joyceqin-stripe added the triaged Issue has been reviewed by Stripe and is being tracked internally label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug triaged Issue has been reviewed by Stripe and is being tracked internally
Projects
None yet
Development

No branches or pull requests

3 participants