stripe / stripe-terminal-react-native

React Native SDK for Stripe Terminal
https://stripe.com/docs/terminal/payments/setup-integration?terminal-sdk-platform=react-native
MIT License
103 stars 49 forks source link

Offline Initialization Issue with Wisepad 3 #668

Open jongbelegen opened 4 months ago

jongbelegen commented 4 months ago

Hey Stripe Team,

I'm encountering an issue with the Stripe Terminal React Native SDK on iOS for offline payments on the Wisepad 3. Offline payments work awesome when initializing the SDK when the device is online.

When starting the app without an internet connection I get the following error:

ERROR Couldn't fetch connection token. Please check your tokenProvider method

The hook also keeps returningisInitialized to false. I'm experiencing this behavior in dev mode. On production builds it seems to get initialized as you would expect. (Maybe some HTTP caching?)

Here's what I need to know:

Should I be caching the last successful requested token for offline use in my fetchTokenProvider function like this pseudo code, or should the stripe SDK handle this internally?

const fetchTokenProvider= async () => {
  try {
    const response = await fetch(`api/stripe-terminal`, { method: "POST", headers: { "Content-Type": "application/json" } });
    const { secret } = await response.json();
    lastSecret = secret;
    return secret;
  } catch (e) {
    return lastSecret;
  }
};

Some documentation about this would also be helpful I think.

Thanks in advance!

nazli-stripe commented 2 months ago

hey @jongbelegen are you still running into this issue?

jongbelegen commented 2 months ago

I guess by trail and error we figured it out. It seems that stripe SDK always prefers to do caching itself (because otherwise ill get an error that the token was already used). But it could be a bit better described in the docs that its ok for fetchTokenProvider to fail on prod.

Is it correct that the location of the terminal needs to be in proximity for this caching mechanism to work?