stripe / stripe-terminal-android

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

The Stripe Terminal ConnectionToken has already been redeemed. Please generate a new one using v1/terminal/connection_tokens #425

Closed udayTechnosouls closed 9 months ago

udayTechnosouls commented 9 months ago

I got this message after attempting to disconnect one reader and then switching to another reader in the same session. I have init Terminal like val tokenProvider = TokenProvider(STRIPE_TOKEN) Terminal.initTerminal( context = it, logLevel = logLevel, tokenProvider = tokenProvider,

After I call Terminal.getInstance().discoverReaders and then Terminal.getInstance().connectBluetoothReader

  1. the first time it connects successfully
  2. on second time it discover reader but when try to connect it give onFailure with Token error.
  3. in 2nd step Strip terminal is call "https://api.stripe.com/v1/terminal/connection_tokens/activate" API with below log

StripeTerminal I class=RestClient message="url=https://api.stripe.com/v1/terminal/connection_tokens/activate request=**** response={"error":{"message":"The Stripe Terminal ConnectionToken has already been redeemed. Please generate a new one using v1/terminal/connection_tokens.","type":"invalid_request_error"}}"

chr-stripe commented 9 months ago

Hi @udayTechnosouls, please review our documentation for ConnectionTokenProvider and check that your TokenProvider does not cache and reuse the same connection token when the Terminal SDK requests a new one.

https://stripe.dev/stripe-terminal-android/external/com.stripe.stripeterminal.external.callable/-connection-token-provider/index.html

An overview of the lifecycle of a connection token:

  • When Stripe Terminal is initialized, the SDK attempts to proactively request an connection token from your backend server.
  • Do not cache or hardcode the connection token.
  • The SDK uses the connection to connect to a reader.
  • Subsequent calls to connect require a new connection token. If you disconnect from a reader, and then call connect again, the SDK will need a new connection token from your backend server. The SDK manages the connection token’s lifecycle and will always request a new connection token automatically when necessary.
dmatthews-stripe commented 9 months ago

Hi @udayTechnosouls , we will be closing this ticket due to inactivity, if you continue to experience any further issues please open up a new ticket.