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
104 stars 50 forks source link

ERROR First initialize the Stripe Terminal SDK before performing any action #659

Open abhijitCN opened 5 months ago

abhijitCN commented 5 months ago

### In my Root(index.js) I initialized and API call for token and in App.js useEffect call the const { initialize } = useStripeTerminal() as per the documentation but still I get ERROR First initialize the Stripe Terminal SDK before performing any action PLEASE HELP.

  1. In my indej.js

import { StripeTerminalProvider } from '@stripe/stripe-terminal-react-native'; import { AppRegistry } from 'react-native'; import { name as appName } from './app.json'; import App from './src/App';

const ReduxAppWrapper = () => { const fetchTokenProvider = async () => { try { const response = await fetch( FetchTokenApi/stripe/tokens, { method: 'GET', headers: { 'Content-Type': 'application/json', }, }, ); const {secret} = await response.json(); console.log('fetch Token Provider secret KEY >> ', secret); return secret; } catch (error) { console.log('fetch Token Provider eror >> ', error); } };

return ( <StripeTerminalProvider logLevel="verbose" tokenProvider={fetchTokenProvider}>

</StripeTerminalProvider>

); }; AppRegistry.registerComponent(appName, () => ReduxAppWrapper);

  1. In my App.js

function App() { const { initialize } = useStripeTerminal();

useEffect(() => { console.log('USE EFFECT >>initialized stripe-terminal in ROOT > '); initialize({ logLevel: 'verbose', }); }, [initialize]);

return ( <>

  <Toast />
      </>

); } export default App;

@kevinlam92 @mihaildu @TheRusskiy @SudoPlz & ANYONE face this issue

nazli-stripe commented 3 months ago

@abhijitCN are you still running into this issue? initialize method returns a Promise and you'll need to wait for its completion before calling other methods.

MoinJanjua commented 2 months ago

Hi ; I also have the same issue I am trying to implement card reader sdk ReactNative

"First initialize the Stripe Terminal SDK before performing any action"

SDK version "@stripe/stripe-terminal-react-native": "^0.0.1-beta.19",

GabrielDuarteJr commented 2 months ago

I have the same issue, I initialize the SDK and after I call the discoverReaders and I have the error, this is my code:

const { error, reader } = await initialize(); ... const { error: discoverReadersError } = await discoverReaders({ discoveryMethod: 'bluetoothScan', simulated: true, });

when the promise of initialize is finished the SDK shouldn't it be ready?

abhijitCN commented 3 weeks ago

I have the same issue, I initialize the SDK and after I call the discoverReaders and I have the error, this is my code:

const { error, reader } = await initialize(); ... const { error: discoverReadersError } = await discoverReaders({ discoveryMethod: 'bluetoothScan', simulated: true, });

when the promise of initialize is finished the SDK shouldn't it be ready?

@GabrielDuarteJr hello, have you got any solution for it!!

w4nd3r1ingY4k commented 2 weeks ago

hi, I'm also having this issue!

My root is wrapped in a stripe terminal provider (splash screen) then the home page initialises and the payment page scans for readers, but I am getting that error when my useEffect to scan for readers kicks in. Any coms / help would be appreciated, thanks