stripe / stripe-terminal-android

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

[BUG] Collect Payment Method failed with "NFC is disabled" after turned off then turned on device's screen on Sunmi Device #331

Open dwiyasko opened 1 year ago

dwiyasko commented 1 year ago

Summary

Using Tap to Pay Android feature deps:

When the device's screen is turned off without leaving the app and then turned on, sometimes get failed when collectPaymentMethod with the message "NFC is disabled", even I check NFC adapter right after the device is turned on its returns true or enabled.

Code to reproduce

When the device screen is turned off by pressing the power button without leaving the app, network Listener is triggered with Unknown state. Then, when turned on the screen again, will trigger network listener with Online state.

So, I check NFC adapter right after, and it says NFC is enabled.

if (viewModel.networkStatus == Unknown && status == Online) {
            val enabled = isNFCEnabled() // this will resulting true (enabled)
}

But when starts payment and reaches collectPaymentMethod(), will fail with NFC is disabled error message and errorCode: error_code_reader_error_local_mobile_nfc_disabled

paymentCancelable = Terminal.getInstance()
            .collectPaymentMethod(originIntent, object : PaymentIntentCallback {
                override fun onFailure(e: TerminalException) {
                    // Sometime will goes here with NFC is disabled
                }

                override fun onSuccess(paymentIntent: PaymentIntent) {
                    // expected to go here, because NFC is enabled
                }
            }, collectConfig)

This issue is intermittent but happens quite often, 6 occurrences out of 20 are quite big. Happen on Sunmi v2s Pro device Android 11, not sure about other devices.

maggiewhite-stripe commented 1 year ago

@dwiyasko Do you see this issue this frequently on all Sunmi v2s devices, or is it particularly bad on this one device?

dwiyasko commented 1 year ago

@maggiewhite-stripe it's frequently happened on all Sunmi v2s devices.

maggiewhite-stripe commented 1 year ago

@dwiyasko Sorry for the delay in my update. I'm having trouble reproducing this issue on my Sunmi V2s.

  1. What are you using to determine if NFC is enabled in your isNFCEnabled() function?
  2. How long does the screen have to be turned off to reproduce this issue?
  3. Does this issue reproduce if the device is plugged in or charging?
  4. Did you see this issue on older versions of the SDK, or is it new with 2.20.0?
dwiyasko commented 1 year ago

Hi @maggiewhite-stripe Sorry for the delay, we are facing another issue related to Wisepad BT reader.

Regarding your question:

  1. It's just a simple check using Android SDK to check whether NFC is enabled or not.
    private fun isNFCAvailable(): Boolean {
        val adapter = (getSystemService(NFC_SERVICE) as NfcManager).defaultAdapter
        return adapter != null
    }
  2. There is no exact time, sometimes within a minute or longer.
  3. No, this issue will not be reproducible when the device is charging or USB is plugged in, so we will not facing such issue by debugging with a cable. To verify this issue, we put a log to our server to see the errorMessage. Then we see error_code_reader_error_local_mobile_nfc_disabled
  4. Never try the older version before, should we check?

For now, we solve the issue with a 1-second retry mechanism, the pattern is, the first try of collection will say NFC disabled, then the next try will work as expected.

Any insight would be very helpful.

billfinn-stripe commented 7 months ago

Hi @dwiyasko -- I realize that we haven't responded to this issue for quite some time (sorry!), but can you upgrade to the latest version and check if it's still an issue? We've been actively developing TTP, so it would be helpful if we could get clear reproducible steps on the latest version of the SDK (3.5.0).