stripe / stripe-terminal-android

Stripe Terminal Android SDK
https://stripe-terminal-android-nine.vercel.app
Other
81 stars 43 forks source link

INTEGRATION_ERROR.NOT_CONNECTED_TO_READER #327

Closed L-is-0 closed 7 months ago

L-is-0 commented 1 year ago

Summary

terminal tap to pay, getting INTEGRATION_ERROR.NOT_CONNECTED_TO_READER

Code to reproduce

We are getting this INTEGRATION_ERROR.NOT_CONNECTED_TO_READER in our code when trying to collectPayment, could your please kindly advise on it regarding why it happened and how we can resolve it? When the reader is disconnect, does the app receive any notification or is there any way we can detect when a reader is disconnected?

Android version

Android 11

Impacted devices (Android devices or readers)

Simulated Reader - tap to pay

SDK version

Other information here is the logs from our code: URL: postPaymentIntent Type: POST Async: true Auth: true JSON: {"amount":"3660","fees":[{"donation":{"additional_donation_amounts":"0.00","charities":{"charity":{"id":"802385","name":"British Paralympic Association (Charity No. 802385)","solicitation_message":"Every penny you give goes to charity: 90% to British Paralympic Association (Registered Charity Number. 802385) and 10% to Pennies (Registered Charity Number 1122489).","soundbite_message":" ","thank_you_message":"Thank you for donating to The British Paralympic Association.","url":"https://paralympics.org.uk/"}},"donation_amount":"0.40","hash":"ROUNDUP40"},"fee":0,"feedesc":"","feename":"Donation","paymentid":1008,"posted":0,"statuscode":1,"type":"3"}],"origin":"T2_2","sessionid":"61569","tableid":"18"}

Wed May 17 12:26:23 GMT+01:00 2023 AwsApi-1101 ttintegrations/stripe/postPaymentIntent: onSuccess - client secret generated Wed May 17 12:26:23 GMT+01:00 2023 ContactlessPaymentUtil-1101 retrieving payment intent... Wed May 17 12:26:23 GMT+01:00 2023 TokenProvider-1101 fetchConnectionToken... Wed May 17 12:26:23 GMT+01:00 2023 ApiEndpoints-1101 live aws url Wed May 17 12:26:23 GMT+01:00 2023 AwsApiManager-1101 New request: URL: /stripe/getConnectionToken Type: GET Async: false Auth: true JSON: null Wed May 17 12:26:23 GMT+01:00 2023 apiEndpoint-1101 onSuccess: Response{protocol=h2, code=200, message=, url=/stripe/getConnectionToken} Wed May 17 12:26:23 GMT+01:00 2023 TokenProvider-1101 generated token secret Wed May 17 12:26:23 GMT+01:00 2023 TokenProvider-1101 fetchConnectionToken successful Wed May 17 12:26:23 GMT+01:00 2023 ContactlessPaymentUtil-1101 retrievePaymentIntent success Wed May 17 12:26:23 GMT+01:00 2023 StripeUseCase-1101 generated payment intent at: 2023-05-17 12:26:23 Wed May 17 12:26:23 GMT+01:00 2023 ContactlessPaymentUtil-1101 collectPayment() onFailure - exception: INTEGRATION_ERROR.NOT_CONNECTED_TO_READER Wed May 17 12:26:23 GMT+01:00 2023 BaseActivity-1101 isAppOnForeground true Wed May 17 12:26:23 GMT+01:00 2023 ApiEndpoints-1101 live aws url Wed May 17 12:26:23 GMT+01:00 2023 AwsApiManager-1101 New request: URL: /ttintegrations/getErr Type: POST Async: true Auth: true JSON: {"appforeground":true,"deviceid":"907885","error_code":"INTEGRATION_ERROR.NOT_CONNECTED_TO_READER","integration":"stripe","message":"LocalMobile reader is not connected","step":"payment","tableid":18}

maggiewhite-stripe commented 1 year ago

@L-is-0 There is information about how to handle unexpected disconnects in our public documentation here:

To get started, provide the current application context, the ConnectionTokenProvider implemented in Step 3, and a TerminalListener object. You can use this listener to handle events from the SDK, such as disconnects. For more information, see Handling disconnects.

https://stripe.com/docs/terminal/payments/setup-integration?terminal-sdk-platform=android#initialize

There's more information here about how to handle unexpected disconnects, but unfortunately it's bluetooth specific: https://stripe.com/docs/terminal/payments/connect-reader?terminal-sdk-platform=android&reader-type=bluetooth#handling-disconnects

Step 1 is relevant to Tap to Pay but Step 2 is not.

L-is-0 commented 1 year ago

Hi @maggiewhite-stripe thanks for the respond. We have implemented this TerminalListener in our project, however we didn't receive any callback from it when we got the the NOT_CONNECT_TO_READER error. Can i check with you at what circumstances we will receive the callback from the listener?

maggiewhite-stripe commented 1 year ago

@L-is-0 You should receive a callback any time that the reader is disconnected without an application call to Terminal.disconnectReader while the application is in the foreground. Please note that right now, this callback is returned every time the tap to pay reader is disconnected: #306

The reader needs to be connected every time the application starts. You could also check Terminal.connectedReader to see if a reader is connected in your application onResume method and reconnect if the reader is not connected

L-is-0 commented 1 year ago

Hi @maggiewhite-stripe, thanks for your reply. Can i confirm with you that the reported error INTEGRATION_ERROR.NOT_CONNECTED_TO_READER - so you were saying the reason why we seen it is because that the app was trying to take payments without reader been connected?

maggiewhite-stripe commented 1 year ago

the reason why we seen [INTEGRATION_ERROR.NOT_CONNECTED_TO_READER] is because that the app was trying to take payments without reader been connected

Yes, that's correct! The error codes are all publicly documented at http://stripe.dev, here's the documentation for this specific error: https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.models/-terminal-exception/-terminal-error-code/-n-o-t_-c-o-n-n-e-c-t-e-d_-t-o_-r-e-a-d-e-r/index.html

maggiewhite-stripe commented 1 year ago

Closing as completed since there hasn't been any further discussion on this ticket - please re-open the ticket or create a new one if the shared documentation is unclear or doesn't resolve the issue

rezpilehvar commented 1 year ago

Hi @maggiewhite-stripe we are getting the same error here, we didn't get any disconnection callback after application goes to background for a while, we check the reader connection status when app comes to foreground but it returns CONNECTED, i reproduced this issue on the debugger and this is the result, as you can see in the watchers all of the states seem to be normal and everything is ready to start payment but after calling collectPaymentMethod we get the INTEGRATION_ERROR.NOT_CONNECTED_TO_READER error

image

Device: Sunmi v2s SDK version: 2.20.1

maggiewhite-stripe commented 1 year ago

@rezpilehvar Can you file a new issue and include the full stack trace of the TerminalException?

rezpilehvar commented 1 year ago

Hey @maggiewhite-stripe, WhatsApp Image 2023-06-22 at 13 46 49

this is the full stack trace of TerminalException:

rv-stripe commented 1 year ago

@rezpilehvar I'm able to reproduce something similar, but the reader status is NOT_CONNECTED after resume as expected. Can you make sure this is being checked after the activity resumes, and make sure you're on the latest SDK 2.21.1. If the issue persists, could you provide logs while reproducing the issue to help track down the issue?

L-is-0 commented 11 months ago

Hi @maggiewhite-stripe @rv-stripe could you please re-open this issue as the problem happens again the latest SDK version 2.21.1. Before started the payment flow, we have logic to check if the reader is connected in our application with this code "Terminal.getInstance().getConnectedReader() == null", and it returns false for this clause and continued with the payment collection.

However we are still getting INTEGRATION_ERROR.NOT_CONNECTED_TO_READER when calling the Terminal.getInstance().collectPayment().

L-is-0 commented 11 months ago

Hi @rezpilehvar just wondering that have you managed to resolve this issue? As i am having the same problem

maggiewhite-stripe commented 11 months ago

Hey @L-is-0 sorry for the delay in my response - as Renee mentioned, we've been having a hard time reproducing this issue locally, which makes it very hard to debug. I'll re-open this ticket. A payment ID and/or logcat logs would be very helpful in debugging this issue. If you are uncomfortable sharing logs on Github, please send them to support@stripe.com and link the support team to this comment so they can direct the logs to my team.

L-is-0 commented 10 months ago

Thank you @maggiewhite-stripe, i managed to get some logs on the devices which had this exact issue happened on 14th August. This log indicates the process when the app was trying to take payments after checking if Terminal.getInstance().getConnectedReader() != null && Terminal.getInstance().getConnectionStatus() == ConnectionStatus.CONNECTED.

here is the original code for this part of the logic in our app

if (Terminal.getInstance().getConnectedReader() == null || Terminal.getInstance().getConnectionStatus() != ConnectionStatus.CONNECTED) {
                reconnectMobileReader(amountInPence, donationAmountInPence, activity, stripePaymentHelper, feeObject);
            } else {
                LogUtil.d(TAG, "reader connection status: " + Terminal.getInstance().getConnectionStatus());
                terminalInitFailedAttempt = 0;
                try {
                    createPaymentIntentAttempt += 1;
                    createPaymentIntent(amountInPence, donationAmountInPence, activity, stripePaymentHelper, feeObject);
                } catch (JSONException e) {
                    stripePaymentHelper.onContactlessLoadingError("READER_DISCONNECTED", e.getMessage());
                }
            }

Please feel free to reach out if you need any further info.


Mon Aug 14 18:16:41 GMT+01:00 2023 BasketActivity-2901 onPlaceOrderViaPayNowSuccess
Mon Aug 14 18:16:41 GMT+01:00 2023 StripeUtil-2901 stripeTerminalCollectPayment
Mon Aug 14 18:16:41 GMT+01:00 2023 StripeUseCase-2901 start payment at: 2023-08-14 18:16:41
Mon Aug 14 18:16:41 GMT+01:00 2023 ContactlessPaymentUtil-2901 reader connection status: CONNECTED
Mon Aug 14 18:16:41 GMT+01:00 2023 ContactlessPaymentUtil-2901 creating payment intent..., amount in pence is: 2440, donation in pence is : 25
Mon Aug 14 18:16:41 GMT+01:00 2023 AwsApiManager-2901 New request:
URL:/stripe/postPaymentIntent
Type: POST
Async: true
Auth: true
Mon Aug 14 18:16:41 GMT+01:00 2023 BasketAdapter-2901 my basket size is :0
Mon Aug 14 18:16:41 GMT+01:00 2023 AwsApi-2901 ttintegrations/stripe/postPaymentIntent: onSuccess - 
Mon Aug 14 18:16:41 GMT+01:00 2023 ContactlessPaymentUtil-2901 retrieving payment intent...
Mon Aug 14 18:16:42 GMT+01:00 2023 TokenProvider-2901 fetchConnectionToken...
Mon Aug 14 18:16:42 GMT+01:00 2023 AwsApiManager-2901 New request:
/stripe/getConnectionToken
Type: GET
Async: false
Auth: true
JSON: null
Mon Aug 14 18:16:43 GMT+01:00 2023 apiEndpoint-2901 onSuccess: Response{protocol=h2, code=200, message=, url=/stripe/getConnectionToken}
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 response is 
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 generated token secret is : Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 fetchConnectionToken successful
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 fetchConnectionToken...
Mon Aug 14 18:16:43 GMT+01:00 2023 ApiEndpoints-2901 live aws url
Mon Aug 14 18:16:43 GMT+01:00 2023 AwsApiManager-2901 New request:
URL: /stripe/getConnectionToken
Type: GET
Async: false
Auth: true
JSON: null
Mon Aug 14 18:16:43 GMT+01:00 2023 apiEndpoint-2901 onSuccess: Response{protocol=h2, code=200, message=, url=/ttintegrations/stripe/getConnectionToken}
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 response is 
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 fetchConnectionToken successful
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 generated token secret is : 
Mon Aug 14 18:16:44 GMT+01:00 2023 ContactlessPaymentUtil-2901 retrievePaymentIntent success
Mon Aug 14 18:16:44 GMT+01:00 2023 StripeUseCase-2901 generated payment intent at: 2023-08-14 18:16:44
Mon Aug 14 18:16:44 GMT+01:00 2023 ConnectionStatusChange-2901 WAITING_FOR_INPUT
Mon Aug 14 18:16:44 GMT+01:00 2023 ConnectionStatusChange-2901 READY
Mon Aug 14 18:16:44 GMT+01:00 2023 ContactlessPaymentUtil-2901 collectPayment() onFailure - exception: INTEGRATION_ERROR.NOT_CONNECTED_TO_READER
Mon Aug 14 18:16:44 GMT+01:00 2023 BaseActivity-2901 isAppOnForeground true
L-is-0 commented 10 months ago

Hi @maggiewhite-stripe @rv-stripe could you please kindly advise on how we could resolve the issue from our side?

L-is-0 commented 10 months ago

Sorry for chasing @maggiewhite-stripe @rv-stripe , just wondered does the device logs be any helpful for your debugging or is there anything else you need from our side?

rv-stripe commented 10 months ago

@L-is-0 For the code that you provided above, where is that invoked from? It's important that this logic is checked in the onResume part of the lifecycle in your application.

L-is-0 commented 10 months ago

Hi @rv-stripe, thank you for your respond. The code above is triggered after the user selects the payment option but before the contactless UI is displayed. This approach is crucial for our standalone application, which runs continuously on a dedicated tablet. Our goal is to ensure that the reader is connected before any contactless payments are initiated, even if the device has been idle overnight with the application running in the foreground. Additionally, we aim to guarantee that the reader remains connected in scenarios where the internet connection is lost and can be swiftly reestablished during the day.

Concerning the statement "It's important that this logic is checked in the onResume part of the lifecycle in your application," should we still consider this, given that our application remains in the foreground and already includes logic to verify reader connectivity during startup?

rv-stripe commented 10 months ago

Are you checking the connectivity at startup or before every transaction?

L-is-0 commented 10 months ago

Hi @rv-stripe, we do check the connectivity at startup and before every transaction just in case the connection is dropped at some point when wifi is not stable. However the my confusion is if "Terminal.getInstance().getConnectionStatus()" is showing CONNECTED, why it would show reader is not connected error when the app trying to collectPayment?

rv-stripe commented 10 months ago

It's possible for the status to change between the calls, but that seems unlikely if the app remains in the foreground. If you could provide us with adb logs of the event happening, that would be helpful. I'll see what else we can find on our end as well

L-is-0 commented 10 months ago

@rv-stripe thank you, if you could please check any useful logs from server side it would be wonderful, this is the logs from the app side when it happened

Mon Aug 14 18:16:41 GMT+01:00 2023 BasketActivity-2901 onPlaceOrderViaPayNowSuccess
Mon Aug 14 18:16:41 GMT+01:00 2023 StripeUtil-2901 stripeTerminalCollectPayment
Mon Aug 14 18:16:41 GMT+01:00 2023 StripeUseCase-2901 start payment at: 2023-08-14 18:16:41
Mon Aug 14 18:16:41 GMT+01:00 2023 ContactlessPaymentUtil-2901 reader connection status: CONNECTED
Mon Aug 14 18:16:41 GMT+01:00 2023 ContactlessPaymentUtil-2901 creating payment intent..., amount in pence is: 2440, donation in pence is : 25
Mon Aug 14 18:16:41 GMT+01:00 2023 AwsApiManager-2901 New request:
URL:/stripe/postPaymentIntent
Type: POST
Async: true
Auth: true
Mon Aug 14 18:16:41 GMT+01:00 2023 BasketAdapter-2901 my basket size is :0
Mon Aug 14 18:16:41 GMT+01:00 2023 AwsApi-2901 ttintegrations/stripe/postPaymentIntent: onSuccess - 
Mon Aug 14 18:16:41 GMT+01:00 2023 ContactlessPaymentUtil-2901 retrieving payment intent...
Mon Aug 14 18:16:42 GMT+01:00 2023 TokenProvider-2901 fetchConnectionToken...
Mon Aug 14 18:16:42 GMT+01:00 2023 AwsApiManager-2901 New request:
/stripe/getConnectionToken
Type: GET
Async: false
Auth: true
JSON: null
Mon Aug 14 18:16:43 GMT+01:00 2023 apiEndpoint-2901 onSuccess: Response{protocol=h2, code=200, message=, url=/stripe/getConnectionToken}
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 response is 
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 generated token secret is : Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 fetchConnectionToken successful
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 fetchConnectionToken...
Mon Aug 14 18:16:43 GMT+01:00 2023 ApiEndpoints-2901 live aws url
Mon Aug 14 18:16:43 GMT+01:00 2023 AwsApiManager-2901 New request:
URL: /stripe/getConnectionToken
Type: GET
Async: false
Auth: true
JSON: null
Mon Aug 14 18:16:43 GMT+01:00 2023 apiEndpoint-2901 onSuccess: Response{protocol=h2, code=200, message=, url=/ttintegrations/stripe/getConnectionToken}
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 response is 
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 fetchConnectionToken successful
Mon Aug 14 18:16:43 GMT+01:00 2023 TokenProvider-2901 generated token secret is : 
Mon Aug 14 18:16:44 GMT+01:00 2023 ContactlessPaymentUtil-2901 retrievePaymentIntent success
Mon Aug 14 18:16:44 GMT+01:00 2023 StripeUseCase-2901 generated payment intent at: 2023-08-14 18:16:44
Mon Aug 14 18:16:44 GMT+01:00 2023 ConnectionStatusChange-2901 WAITING_FOR_INPUT
Mon Aug 14 18:16:44 GMT+01:00 2023 ConnectionStatusChange-2901 READY
Mon Aug 14 18:16:44 GMT+01:00 2023 ContactlessPaymentUtil-2901 collectPayment() onFailure - exception: INTEGRATION_ERROR.NOT_CONNECTED_TO_READER
Mon Aug 14 18:16:44 GMT+01:00 2023 BaseActivity-2901 isAppOnForeground true
L-is-0 commented 9 months ago

Hi @rv-stripe sorry for chasing, but just wanted to check is there any luck on this issue?

L-is-0 commented 9 months ago

Hi @rv-stripe is there any updates on this issue?

L-is-0 commented 9 months ago

Hi @rv-stripe, we are still expiring this issue, is the log any helpful?

rv-stripe commented 9 months ago

@L-is-0 We're still looking into this, unfortunately I don't have an immediate update to provide.

L-is-0 commented 9 months ago

Hi @rv-stripe Can we please get a daily update as we have customers experiencing this problem on a daily basis.

rv-stripe commented 9 months ago

@L-is-0 Are you able to reconnect to the reader successfully after a disconnect occurs? Detecting a disconnect and reconnecting should mitigate the issue while we investigate the reason for your elevated level of disconnections.

L-is-0 commented 9 months ago

Hi @rv-stripe thanks for your response. Are you suggesting that we should listen to "onUnexpectedReaderDisconnect" method and reconnect to a reader whenever there is a disconnect?

rv-stripe commented 9 months ago

Yes. The TTP reader can become disconnected for several reasons, but it should always be safe to start the reconnection process automatically when this happens. Note that this may take some time, though, if the reader was disconnected due to network availability, so you should update the UI accordingly during the reconnection.

L-is-0 commented 9 months ago

Thanks @rv-stripe, we have the 'onUnexpectedReaderDisconnect' method implemented in the application but for some reason for this scenario it seems like the reader is disconnected just before payment stage and it is not practical for us to update the ui while reconnecting, that's the reason we need to check if the reader is disconnect before payment flow started initially

L-is-0 commented 9 months ago

Hi @rv-stripe, is there any other solution we could try for this scenario?

L-is-0 commented 9 months ago

Hi @rv-stripe Can we please get a daily update as we have customers experiencing this problem on a daily basis.

rv-stripe commented 9 months ago

@L-is-0 We are looking into ways to improve the experience around reader disconnections. However, you will need to handle these disconnection events in your application for a robust user experience. When you receive a disconnection error when collecting, it is typically safe to automatically attempt to reconnect to the reader and resume the payment once the connection has been established.

L-is-0 commented 9 months ago

Hi @rv-stripe thank you for your response. Just double checked the code, we already have the disconnection events implemented in our project, however we don't seem to receive any callback from it even when the reader is connected?

L-is-0 commented 9 months ago

Hi @rv-stripe Can we please get a daily update as we have customers experiencing this problem on a daily basis.

L-is-0 commented 9 months ago

Hi @rv-stripe Can we please get a daily update as we have customers experiencing this problem on a daily basis.

rv-stripe commented 9 months ago

We are aware of this issue and hope to fix it in a future release. We have enough information to determine the root cause and do not need additional logging from users encountering the issue. However, the solution for this may take some time to implement. Given that there are workarounds for this issue (described above) it may be some time before a full fix is made available. I will leave this ticket open in the meantime, and we will provide updates on the issue when we have more updates to provide.

L-is-0 commented 8 months ago

Hi @rv-stripe thanks for your reply, however the workaround described above doesn't work for us, so we might still waiting on the fixes to solve the current issue for our users. We would be much appreciated if a fix can be added to this as soon as possible and if you could kindly provide any update on this.

L-is-0 commented 8 months ago

Hi @rv-stripe Can we please get a daily update as we have customers experiencing this problem on a daily basis.

rv-stripe commented 8 months ago

@L-is-0 Please do not flood this issue with requests for updates. We will update this issue when we have information to provide.

gregl33 commented 8 months ago

Hello, I am the CTO of the business which you are asking to stop flooding with requests.

Your proposed workarounds do NOT work so we are currently left without any solutions at all.

We've had this problem DAILY for over 12 months now and are being swamped with client issues and support tickets every single day.

Please could you advise WHEN this will be fixed so we can update our clients accordingly. They have no trust that after 12 months there is any fix coming...

Alternatively, would it be more helpful to ask our clients to contact Stripe support each day? Or did you want to provide us with a formal Stripe response explaining why this problem has been occurring without any solution for so long?

bperez-stripe commented 7 months ago

This issue has been resolved after direct communication with the user.