Switching card readers in stripe terminal

Viewed 102

I'm using com.stripe:stripeterminal:1.0.17, I'm trying to switch card readers in the app, but I get crash when try to initTerminal: You can only call initTerminal before requesting the Terminal instance for the first time.

I am clearing cache, I think something is wrong in this function, I am not keen on java, so hard to find the problem:

 public void stripeTerminal(String stripeTerminalToken) {
    Activity currentActivity = getCurrentActivity();
      terminalToken = stripeTerminalToken;
      try {
        Log.i("find_me", "terminal: " + terminal);
        if (terminal != null) {
          terminal.clearCachedCredentials();
        }

        Terminal.initTerminal(mContext, LogLevel.VERBOSE, new TokenProvider(),
        new TerminalEventListener());
        terminal = Terminal.getInstance();
 
      } catch(TerminalException e) {
          Exception exception = new Exception(e.getErrorMessage());
          Crashlytics.logException(exception);
          WritableMap params = Arguments.createMap();
          params.putString("errorMsg", e.getErrorMessage());
          sendEventToJS(mContext, "stripeDevicesList", params);
          if (terminal != null) {
            terminal.clearCachedCredentials();
          }
          terminal = null;
      }
  }
1 Answers

You can solve this by adding a Terminal.isInitialized check prior to calling Terminal.initTerminal. Terminal.clearCachedCredentials is for switching accounts - it doesn't allow you to call Terminal.initTerminal multiple times.

Related