stripe-terminal-react-native icon indicating copy to clipboard operation
stripe-terminal-react-native copied to clipboard

Unable to reconnect to the same reader - Connection Token already redeemed

Open usamamoinakhter opened this issue 2 years ago • 4 comments

Describe the bug After disconnecting from the stripe M2 reader, I cannot reconnect to the same device. It throws The Stripe Terminal ConnectionToken has already been redeemed. The documentation suggested that I should call clearCachedCredentials()after disconnecting in order to generate a new connection-token but it still throws the same error. I was successfully able to reconnect after restarting the application though.

To Reproduce Steps to reproduce the behavior:

  1. Discover Readers
  2. Connect to a reader
  3. Disconnect connection with the reader
  4. Discover Again
  5. Connect with the same reader

Expected behavior The device should be connected to the same reader again

Smartphone (please complete the following information):

  • Device: Lenovo TB-X606F
  • OS: Android Version 10
  • SDK Version 0.0.1-beta.8

usamamoinakhter avatar Sep 06 '22 22:09 usamamoinakhter

Hi @usamamoinakhter I'm trying to reproduce but wanted to confirm: When attempting the second connect is your connection token provider receiving the request for another token? Or are you not even seeing that request for a new connection token?

Is there possibly any caching at that layer? The expectation is the SDK should request another connection token from your connection token provider when attempting to connect the second time. If the same connection token was returned in the second call due to any caching that would exhibit this same error.

bric-stripe avatar Sep 09 '22 19:09 bric-stripe

I just confirmed using our example-app and watching logs in my merchant backend for that that when I disconnect and reconnect it fetches a new connection token. I was using android on a pixel 3 but wouldn't expect any device specific issues here. Are you able to reproduce the error using the example app?

bric-stripe avatar Sep 09 '22 20:09 bric-stripe

Hey @bric-stripe , thank you for the response. This is the code we have been using

const fetchTokenProvider = async (): Promise<string> => {
      console.log("Fetching Token");
      const response = await call({
          url: `${servicesConst.serviceEndpoints.STRIPE_TOKEN}`,
          method: servicesConst.serviceMethods.POST,
          params: {
              store_id: storeId
          },
      });
      if (!response)
          return "";
      const { secret } = response as StripeToken;
      return secret;
  };
            <StripeTerminalProvider
                logLevel="verbose"
                tokenProvider={fetchTokenProvider}>
                <Auth />
            </StripeTerminalProvider>

I don't think the token is cached. The problem is I see the log only the first time, the second time the function doesn't even get called. I will check against example-app and see if it works fine or not.

usamamoinakhter avatar Sep 12 '22 01:09 usamamoinakhter

@bric-stripe Do you have an updates on this?

ghost avatar Sep 15 '22 21:09 ghost

@usamamoinakhter @claudelama-solet apologies for the delay getting back to this.

I'm still unable to reproduce the problem, both with and without calling clearCachedCredentials (though for the use case here that shouldn't be necessary to force it to refresh the connection token).

Does the issue reproduce 100% of the time when connect > disconnect > connect again and it repros? If not, how frequently are you seeing this? Is it after some amount of time between connecting and disconnecting? Note the M2 will reset itself every 24h for PCI compliance which will cause a disconnect but should be able to be reconnected to right away and should request a fresh connection token.

Are you able to reproduce the error using the example app from the repo? The sample code provided seems correct but knowing if it works in the example app can hopefully help us hunt for differences and/or ideally get a repro from the example app that we can debug/fix.

Also, could you provide an M2 serial number and rough timing of when you hit the connection token already redeemed issue? With that we can look through some logs to see if anything stands out.

also, if building for both iOS and Android are you seeing the issue with both platforms?

bric-stripe avatar Dec 02 '22 18:12 bric-stripe

@bric-stripe We had put a workaround in place since then. When we had the issue, it was 100% reproducible. We could reproduce it when power cycling the reader. What we saw at the time is that the SDK was never calling our function.

I can't speak as to why you can't reproduce the issue on your hand using the sample app. The date of the issue was between Sept 4 and September 15. One of the reader that exhibited the issue was STRM26139015920

ghost avatar Dec 05 '22 22:12 ghost

We had put a workaround in place since then

thanks, could you explain the work around you ended up with? Knowing that may help me realize what I'm missing in my attempts to reproduce the problem.

bric-stripe avatar Dec 05 '22 22:12 bric-stripe

As every time we tried to reconnect we were getting connection token already redeemed, we reset the list of discovered readers and launched a new discovery. This is to the best of what I can recall as we did this 3 months ago... I am looking at the code as I write this and it looks foreign to me right now :-)

ghost avatar Dec 05 '22 23:12 ghost

I'm going to close this issue, as we are not able to reproduce, and you seem to have a workaround. If you encounter it again, let us know, and we'll investigate further.

billfinn-stripe avatar Jan 04 '23 18:01 billfinn-stripe