BreX900 / mek-packages

10 stars 13 forks source link

After `Terminal.getInstance` is called, subsequent calls do not override the fetch token method #63

Open joelsuite opened 3 months ago

joelsuite commented 3 months ago

When the Terminal.getInstance() method is called and passed a fetchToken method, subsequent calls to getInstance passing a new fetchToken method, to create new instances of a Terminal do not appear to override the fetchToken method passed in the first call. It appears that the fetchToken method is run a second time in the second getInstance call. However, the fetchToken method is the original method passed, not a new method.

marcelocbf commented 2 months ago

I can attest I have the same problem. the getInstance(connectionTokenFetcher) only retrieves the same instance created on the first call, but it doesn't make sense to me since a connectionTokenFetcher arg is required and will likely be different on the second call

@joelsuite , I don't know if it helps, in my case I needed to switch the stripe account id that the fetcher uses to retrieve the connection token from the right account (multiple accounts in the same app), so I created a singleton temporarily so I can change the stripe account id there and have the same fetch function to work.

I can probably help working on a solution, but since, I'm not deeply involved in the project. I'm not sure how the maintainers want to solve this; maybe mimicking the underlying platform with initTerminal(|args and tokenProvider|) and getInstance(|no args|) or maybe simply retrieving a new instance every time with an updated fetchToken...

BreX900 commented 1 month ago

For now I think it will stay that way. Natively there is only one instance of Terminal. Simply put even if I fixed it Terminal.getInstance would always return the same instance overwriting the previous fetchToken method.

In the next major I think I will replicate the native code signature. So there will be an init method that you can call only once by passing fetchToken.

Workaround: Being that you pass it a function you can return from that function different tokens

Translated with DeepL.com (free version)

joelsuite commented 1 month ago

Thanks for your reply, we appreciate the time you've taken to respond.

For the purposes we are using the package for it would actually be beneficial to be able to overwrite the previous fetchToken method, so that we can get a new token before attempting to reconnect to a reader for example.

As it currently stands we seem to have no way to update the token once fetchToken has been passed. We find that even though we have passed a fetchToken method that is able to dynamically get a token, this method appears to only be called once on the terminal instantiation, and we can't seem to see a way to have it called again to update the token. We might be missing something, is there a way to trigger subsequent calls to fetchToken?

rennyrocha commented 1 month ago

We find that even though we have passed a fetchToken method that is able to dynamically get a token, this method appears to only be called once on the terminal instantiation, and we can't seem to see a way to have it called again to update the token.

I'm having the same issue currently. Once I unpair from a reader, I'm not able to connect to another one in no way even using new tokens. There's always the same output error:

flutter: TerminalException: stripeApiError The Stripe Terminal ConnectionToken has already been redeemed. Please generate a new one using v1/terminal/connection_tokens.

Is there a workaround for this? How do you disconnect from a reader and then connect to another one?!