stripe / stripe-terminal-android

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

Issue connecting to reader #477

Closed thelight413 closed 3 months ago

thelight413 commented 4 months ago

Summary

I'm getting an error when trying to discover readers whether it's NFC or an M2 reader. The error I'm getting is

Screenshot 2024-07-25 at 6 22 45 PM

Code to reproduce

public void discoverReaders(String method, int simulated, int timeout) {
        boolean isSimulated = isApplicationDebuggable();
        try {
            DiscoveryConfiguration discoveryConfiguration = null;
//            discMethod = DiscoveryMethod.valueOf(DiscoveryMethod.BLUETOOTH_SCAN.);
// Our only discovery method for Android
            if (method.equals("internet")) {
//                discoveryConfiguration = new DiscoveryConfiguration.InternetDiscoveryConfiguration(location,isSimulated);
            } else if (method.equals("local")) {
                isSimulated = isApplicationDebuggable();
                discoveryConfiguration = new DiscoveryConfiguration.LocalMobileDiscoveryConfiguration(isSimulated);
            } else if (method.equals("embedded")) {
            } else if (method.equals("handoff")) {
                discoveryConfiguration = new DiscoveryConfiguration.HandoffDiscoveryConfiguration();

            } else if (method.equals("usb")) {
                discoveryConfiguration = new DiscoveryConfiguration.BluetoothDiscoveryConfiguration(timeout, isSimulated);
            } else {
                discoveryConfiguration = new DiscoveryConfiguration.BluetoothDiscoveryConfiguration(timeout, isSimulated);

            }
//            DiscoveryConfiguration discoveryConfiguration = new DiscoveryConfiguration(timeout, discMethod, isSimulated);
            Callback statusCallback = new Callback() {
                @Override
                public void onSuccess() {
                    pendingDiscoverReaders = null;
                    WritableMap readerCompletionResponse = Arguments.createMap();
                    sendEventWithName(EVENT_READER_DISCOVERY_COMPLETION, readerCompletionResponse);
                }

                @Override
                public void onFailure(@Nonnull TerminalException e) {
                    pendingDiscoverReaders = null;
                    WritableMap errorMap = Arguments.createMap();
                    errorMap.putString(ERROR, e.getErrorMessage());
                    sendEventWithName(EVENT_READER_DISCOVERY_COMPLETION, errorMap);
                }
            };

            abortDiscoverReaders();
            if (ActivityCompat.checkSelfPermission(getContext().getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext().getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                // TODO: Consider calling
                //    ActivityCompat#requestPermissions
                // here to request the missing permissions, and then overriding
                //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                //                                          int[] grantResults)
                // to handle the case where the user grants the permission. See the documentation
                // for ActivityCompat#requestPermissions for more details.
                return;
            }
            assert discoveryConfiguration != null;
            pendingDiscoverReaders = Terminal.getInstance().discoverReaders(discoveryConfiguration, this, statusCallback);

        } catch (Exception e) {
            e.printStackTrace();

            if (e.getMessage() != null) {
                WritableMap writableMap = Arguments.createMap();
                writableMap.putString(ERROR, e.getMessage());
                sendEventWithName(EVENT_READER_DISCOVERY_COMPLETION, writableMap);
            }
        }
    }

Android version

Android 14

Impacted devices (Android devices or readers)

Pixel 6, M2 reader or NFC reader

SDK version

3.7.1

Other information

ugochukwu-stripe commented 3 months ago

@thelight413 the logs above are a warning from the SDK's failed attempt to fetch cached locations; it does not fail the discovery operation. The log immediately afterwards onUpdateDiscoveredReaders confirms the sdk returns an empty list of readers to your application. Please see details ^1 for using your M2 reader, and let us know if you're having issues with discovery.

thelight413 commented 3 months ago

I got it to discover the reader but it stays on the status "connecting" for a while and then just disconnects. The error I get is "timed out waiting for connection token".

Screenshot 2024-07-26 at 4 18 52 PM Screenshot 2024-07-26 at 4 20 19 PM
thelight413 commented 3 months ago

Just to add just in case this helps. It seems like connection token is being refreshed twice. once during initialization and once during forwarding offline payments. Its refreshing one after the other.

Screenshot 2024-07-26 at 5 25 00 PM
ugochukwu-stripe commented 3 months ago

Terminal requires a connection token ^1 to activate your session so the reader can take payments, it seems your application is not providing a ConnectionToken hence the error. I'd suggest trying the example application ^2 if you haven't already to resolve integration errors in your application. Closing this out since it is an integration issue, feel free to open a new issue if you find bugs with the library.

thelight413 commented 3 months ago

I'm still having this issue. When you run the app for the first time, do an initialization, discover readers and trying to connecting to a reader it will not connect to the reader because it doesn't attempt at getting the connection token. I put logs before and after it gets a connection token and it doesn't try getting the connection token on a fresh install. But if I swipe out of the app and run the app again it does get the connection

ugochukwu-stripe commented 3 months ago

Can you reproduce with example application ^1?