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

Reader Disconnect issue #532

Open
VijayRathodM opened this issue Nov 22, 2024 · 14 comments
Open

Reader Disconnect issue #532

VijayRathodM opened this issue Nov 22, 2024 · 14 comments

Comments

@VijayRathodM
Copy link

VijayRathodM commented Nov 22, 2024

Summary

When reader is connect after we have one button to disconnect reader but there is not return callback, this issue major in Fragment , we need to call onSuccess after to back the screen but it is not possible

Code to reproduce

Step 1
Connect Reader Successfull
Step 2
Disconnect Button and click following callback

 Terminal.getInstance().disconnectReader(object : Callback {
    override fun onFailure(e: TerminalException) {
    
    }

    override fun onSuccess() {
            
        }
})

but not any callback method onSuccess or onFailure nothing to call

Android version

14

Impacted devices (Android devices or readers)

SDK version

4.0.0

Other information

@sjl-stripe
Copy link
Collaborator

@VijayRathodM Thanks for bringing this to our attention, and I'm sorry to hear you're experiencing issues with the disconnectReader callbacks.

To help us investigate this issue, could you please provide the following information?

  1. Reader's serial number: This will help us check the logs for any errors related to your device.
  2. Approximate time of the issue: Knowing when the issue occurred will assist us in narrowing down the logs.
  3. Reproducibility: Is this issue happening every time you try to disconnect the reader, or is it intermittent?

In the meantime, as a workaround, you can implement the ReaderDisconnectListener in your application. This listener's onDisconnect() method will be called when the reader is disconnected, which can help you navigate back to the desired screen.

@VijayRathodM
Copy link
Author

VijayRathodM commented Nov 25, 2024

Thanks for your support

  1. Reader's serial number: STRM26138005130
  2. Approximate time of the issue: Not Fixed, we get every time disconnecting issue
  3. Reproducibility : Following all step possible my side here

Step 1
Terminal.initTerminal( requireContext(),LogLevel.ERROR,TokenProvider(requireContext()),TerminalEventListener() )

Step 2
discoveryTask = Terminal.getInstance().discoverReaders(config, this, discoveryCallback)

Step 3

override fun onUpdateDiscoveredReaders(readers: List<Reader>) {
	//Connect Devoce 
	connectREader(readers[0])
	stopDiscovery()			
}

//Connect Device 
fun connectReader(reader) {
	Terminal.getInstance().connectReader(reader,config,object :ReaderCallback {

		override fun onFailure(e: TerminalException) {
	                       
		}

		override fun onSuccess(reader: Reader) {
	           Log.e("onSuccess","Connect Successfully...")
	           //Show the reader data on screen            
	    }
	})
}

//Stop Discovery
fun stopDiscovery(onSuccess: () -> Unit = { }) {
	try {
    		if (discoveryTask != null) {
        		discoveryTask?.cancel(object : Callback {
				override fun onSuccess() {
                    discoveryTask = null
                }

				override fun onFailure(e: TerminalException) {
                        
                }

			}) ?: run {
                onSuccess()
		   }
	   }
	} catch (ex: TerminalException) {
            ex.printStackTrace()
}

Step 4
//Disconnect Reader call when button click

Terminal
    .getInstance()
    .disconnectReader(
        object : Callback {
            override fun onFailure(ex: TerminalException) {
                Log.e("onFailure","${ex.errorMessage}")
            }

            override fun onSuccess() {
             	Log.e("onSuccess","Reader Disconnect Successfully...")
             	//Back Fragment here			
            }
        }
)

// This method is not callback with any reason and we have implemented ReaderDisconnectListener method but not working

  override fun onDisconnect(reason: DisconnectReason) {
        Log.e("MobileReaderListener","onDisconnect: $reason")
    }

Note : When try to disconnect device there is no log are getting

Logs
BluetoothAdapter com.reader.example D isLeEnabled(): ON
Applicatio...ageManager com.reader.example D hasSystemFeature:name=android.hardware.bluetooth_le version=0 getOpPackageName=com.reader.example hasSystemFeature=true
Applicatio...ageManager com.reader.example D hasSystemFeature:name=android.hardware.bluetooth_le version=0 getOpPackageName=com.reader.example hasSystemFeature=true
Applicatio...ageManager com.reader.example D hasSystemFeature:name=android.hardware.bluetooth_le version=0 getOpPackageName=com.reader.example hasSystemFeature=true
BluetoothGatt com.reader.example D connect() - device: CC:D3:1E:69:XX:XX, auto: false
BluetoothGatt com.reader.example D registerApp()
BluetoothGatt com.reader.example D registerApp() - UUID=1fa93c9d-6e88-4611-af28-XXXXXXXX
BluetoothGatt com.reader.example D onClientRegistered() - status=0 clientIf=5
BluetoothGatt com.reader.example D onClientConnectionState() - status=0 clientIf=5 device=CC:D3:1E:69:XX:XX
BluetoothGatt com.reader.example D discoverServices() - device: CC:D3:1E:69:XX:XX
BluetoothGatt com.reader.example D onSearchComplete() = Device=CC:D3:1E:69:XX:XX Status=0
BluetoothGatt com.reader.example D setCharacteristicNotification() - uuid: 0000ffa1-0000-1000-8000-XXXXXXX enable: true
BluetoothGatt com.reader.example D requestConnectionPriority() - params: 1
BluetoothGatt com.reader.example D configureMTU() - device: CC:D3:1E:69:XX:XX mtu: 128
BluetoothGatt com.reader.example D onConnectionUpdated() - Device=CC:D3:1E:69:XX:XX interval=12 latency=0 timeout=500 status=0
BluetoothGatt com.reader.example D onConfigureMTU() - Device=CC:D3:1E:69:XX:XX mtu=128 status=0
TrafficStats com.reader.example D tagSocket(82) with statsTag=0xffffffff, statsUid=-1
Internet com.reader.example I NetworkCapabilities.TRANSPORT_WIFI
mali_gralloc com.reader.example I unregister: id=0x286000008fc, base=0x0, importpid=23060
mali_gralloc com.reader.example I unregister: id=0x286000008fd, base=0x0, importpid=23060
mali_gralloc com.reader.example I unregister: id=0x286000008fb, base=0x0, importpid=23060
mali_gralloc com.reader.example I unregister: id=0x286000008fe, base=0x0, importpid=23060
Battery com.reader.example E 98
mali_gralloc com.reader.example I register: id=0x2860000090f, importpid=-1
mali_gralloc com.reader.example I register: id=0x28600000910, importpid=-1
mali_gralloc com.reader.example I register: id=0x28600000911, importpid=-1
mali_gralloc com.reader.example I register: id=0x28600000912, importpid=-1
Parcel com.reader.example W Expecting binder but got null!
Internet com.reader.example I NetworkCapabilities.TRANSPORT_WIFI
mali_gralloc com.reader.example I unregister: id=0x28600000912, base=0x0, importpid=23060
mali_gralloc com.reader.example I unregister: id=0x28600000911, base=0x0, importpid=23060
mali_gralloc com.reader.example I unregister: id=0x28600000910, base=0x0, importpid=23060
mali_gralloc com.reader.example I unregister: id=0x2860000090f, base=0x0, importpid=23060

@VijayRathodM
Copy link
Author

any update ?

@Syedovaiss
Copy link

Facing same issue while connecting via Usb on OEM devices
Reader frequentie throwing USB unexpectedly disconnected

@VijayRathodM
Copy link
Author

VijayRathodM commented Dec 3, 2024

any update? @sjl-stripe ?

@sjl-stripe
Copy link
Collaborator

@Syedovaiss could you open a new ticket for your issue? When creating the ticket, information like the stack trace, reader serial number and reproduction steps will help us root cause the issue quicker.

@sjl-stripe
Copy link
Collaborator

Hi @VijayRathodM,

Thank you for the detailed information. After reviewing our logs, it appears that the issue is caused by unhandled NullPointerExceptions in your callback methods (specifically in onSuccess and onFailure). This can prevent the Terminal SDK from completing operations and invoking callbacks properly.

Suggestion:

Add try-catch blocks inside your onSuccess and onFailure methods to handle any exceptions.

val collectPaymentMethodCallback = object : PaymentIntentCallback {
    override fun onSuccess(paymentIntent: PaymentIntent) {
        try {
            // Your success handling code
        } catch (exception: Exception) {
            Log.e("CollectPaymentMethod", "Exception in onSuccess", exception)
        }
    }

    override fun onFailure(e: TerminalException) {
        try {
            // Your error handling code
        } catch (exception: Exception) {
            Log.e("CollectPaymentMethod", "Exception in onFailure", exception)
        }
    }
}

val processPaymentIntentCallback = object : PaymentIntentCallback {
    override fun onSuccess(paymentIntent: PaymentIntent) {
        try {
            // Your success handling code
        } catch (exception: Exception) {
            Log.e("ProcessPaymentIntent", "Exception in onSuccess", exception)
        }
    }

    override fun onFailure(e: TerminalException) {
        try {
            // Your error handling code
        } catch (exception: Exception) {
            Log.e("ProcessPaymentIntent", "Exception in onFailure", exception)
        }
    }
}

val disconnectReaderCallback = object : Callback {
    override fun onSuccess() {
        try {
            // Your success handling code
        } catch (exception: Exception) {
            Log.e("DisconnectReader", "Exception in onSuccess", exception)
        }
    }

    override fun onFailure(e: TerminalException) {
        try {
            // Your error handling code
        } catch (exception: Exception) {
            Log.e("DisconnectReader", "Exception in onFailure", exception)
        }
    }
}

// Handle exceptions for your other callbacks similarly

Why This Helps:

  • Unhandled exceptions in callbacks disrupt the Terminal SDK's operation queue.
  • Wrapping your code in try-catch blocks ensures exceptions are handled, allowing the Terminal SDK to function correctly.

Please try implementing these changes, and let us know if the issue persists.

@VijayRathodM
Copy link
Author

VijayRathodM commented Dec 9, 2024

@sjl-stripe
Same issue, i have same implement as you suggest, nothing to any callback action or exception

val disconnectReaderCallback =
    object : Callback {
        override fun onSuccess() {
            try {
                // Your success handling code
                callBackFragment()
            } catch (exception: Exception) {
                Log.e("DisconnectReader", "Exception in onSuccess", exception)
            }
        }

        override fun onFailure(e: TerminalException) {
            try {
                // Your error handling code
                Log.e("DisconnectReader", "onFailure()")
            } catch (exception: Exception) {
                Log.e("DisconnectReader", "Exception in onFailure", exception)
            }
        }
    }

Terminal.getInstance().disconnectReader(disconnectReaderCallback)

@sjl-stripe
Copy link
Collaborator

sjl-stripe commented Dec 9, 2024

@VijayRathodM thanks for trying out my recommendation.

Just to confirm, have you tried adding the try/catch blocks to your other callbacks, like collectPaymentMethodCallback and processPaymentIntentCallback? I think the root cause of this issue isn't from the disconnectReaderCallback specifically.

@VijayRathodM
Copy link
Author

VijayRathodM commented Dec 10, 2024

@sjl-stripe

Yes, we have implemented try/catch blocks for every callback and set up terminal error logging, but no operations or actions are being logged.

Just to confirm, is it possible for the reader to disconnect after creating a payment intent and getting ready to swipe or insert the card during this flow?

This issue has been ongoing for a long time, so we request the Stripe team to take this matter seriously and provide a resolution.

Terminal.initTerminal(
                    requireContext(),
                    LogLevel.ERROR,
                    TokenProvider(requireContext()),
                    TerminalEventListener()
                )

@VijayRathodM
Copy link
Author

@sjl-stripe any update ?

1 similar comment
@VijayRathodM
Copy link
Author

@sjl-stripe any update ?

@xiaoshen-stripe
Copy link
Contributor

Hi @VijayRathodM appreciate the details provided and trying the suggested workaround.
Our team is actively investigating however with the holidays approaching, we will pick this back up as a priority in the new year.

In the meantime, wondering if you can use the workaround suggested of implementing the ReaderDisconnectListener in your application - while not ideal, this should allow you to detect disconnects and navigate appropriately.

Thanks

@VijayRathodM
Copy link
Author

@xiaoshen-stripe any update ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants