stripe / stripe-terminal-android

Stripe Terminal Android SDK
https://stripe.dev/stripe-terminal-android/
Other
94 stars 46 forks source link

Payment Processing Issue: Stuck on Waiting for Payment Screen and requires double payment to succeed #395

Closed VictorJanampa closed 1 year ago

VictorJanampa commented 1 year ago

Summary

I encounter an issue when processing payments on the localMobile library. Specifically, the problem is related to the "tap to pay" functionality. When attempting to complete a payment action, the application gets stuck on the "waiting for payment" screen, and it requires to tap twice to successfully process a payment(Second 9 to 13). This behavior also occurs on a production build.

https://github.com/stripe/stripe-terminal-android/assets/52934166/244e68e4-23cd-4e19-81e3-325674fd44a7

Code to reproduce

private fun retrievePaymentIntent(clientSecret: String) {
        Terminal.getInstance().retrievePaymentIntent(clientSecret, object : PaymentIntentCallback {
            override fun onFailure(e: TerminalException) {
                e.printStackTrace()
                displayTapToPayNotConfiguredDialog()
            }

            override fun onSuccess(paymentIntent: PaymentIntent) {
                paymentCollect(paymentIntent)
            }
        })
    }

    private var cancelablePaymentReader: Cancelable? = null

    private fun paymentCollect(paymentIntent: PaymentIntent) {
        cancelablePaymentReader = Terminal.getInstance()
            .collectPaymentMethod(paymentIntent, createPaymentIntentCallback)
    }

    private val createPaymentIntentCallback by lazy {
        object : PaymentIntentCallback {
            override fun onSuccess(paymentIntent: PaymentIntent) {
                val skipTipping = true

                val collectConfig = CollectConfiguration.Builder()
                    .skipTipping(skipTipping)
                    .build()

                Terminal.getInstance().collectPaymentMethod(
                    paymentIntent, collectPaymentMethodCallback, collectConfig
                )
            }

            override fun onFailure(e: TerminalException) {
                cancelPaymentIntent()
                e.printStackTrace()
            }
        }
    }

    private val collectPaymentMethodCallback by lazy {
        object : PaymentIntentCallback {
            override fun onSuccess(paymentIntent: PaymentIntent) {
                Terminal.getInstance().processPayment(paymentIntent, processPaymentCallback)
            }

            override fun onFailure(e: TerminalException) {
                cancelPaymentIntent()
                e.printStackTrace()
            }
        }
    }

    private val processPaymentCallback by lazy {
        object : PaymentIntentCallback {
            override fun onSuccess(paymentIntent: PaymentIntent) {
                deleteCurrentOrder()
                navigateToSuccessPayment()
            }

            override fun onFailure(e: TerminalException) {
                cancelPaymentIntent()
                e.printStackTrace()
            }
        }
    }

Android version

The issue is observed on Android 13 and 14

Impacted devices (Android devices or readers)

Pixel 6 Pro

SDK version

stripeterminal-localmobile version 2.23.2 stripeterminal-core version 2.23.2

Other information

billfinn-stripe commented 1 year ago

It looks like you are calling collectPaymentMethod twice, once at line 18 and once at line 30.

If you encounter a similar issue in the future, please first try to reproduce with the Terminal sample application, and, if it doesn't happen within the sample application, compare your implementation with the sample application to spot any differences.