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

Production Android Build Not Connect With Reader With Live_Stripe_KEY Using v0.0.1-beta.16 Version. #711

Open abhijitCN opened 6 months ago

abhijitCN commented 6 months ago

When we use the simulated true option, both Android and iOS work perfectly. However, when we set it to false, the reader does not connect. Calling connectLocalMobileReader() returns an error.

Below I have added my code, please review it once.

const [discoveredReader, setDiscoveredReader] = useState([]);
  useEffect(() => {
    console.log("NFC capability alert start")
    async function handleDiscoverReaders() {
      const {error, readers} = await discoverReaders({
        discoveryMethod: 'localMobile',
        //simulated: true,
      });
      Alert.alert('discoverReaders() readers >>', readers);
      if (error) {
        navigation.navigate('ReaderNotConnected');
      } else {
      }
    }
    handleDiscoverReaders();
  }, [discoverReaders]);
  const {discoverReaders, discoveredReaders,connectLocalMobileReader} = useStripeTerminal({
    onUpdateDiscoveredReaders: readers => {
      console.log('My Discovered Readers >> ', readers);
      setDiscoveredReader(readers[0]);
      console.log('ARRAY OF DiscoveredReaders >> ', discoveredReaders);
    },
    onDidChangeConnectionStatus: (status) => {
      console.log('Connection Status >> ', status);
    },
    onDidReportUnexpectedReaderDisconnect: (readers) => {
      Alert.alert('Reader Disconnected', 'Please try again');
    },
  });
  async function connectMobileReader() {
    const {reader, error} = await connectLocalMobileReader({
      reader: discoveredReader
      locationId: stripeLocation?.data?.id,
    });
    Alert.alert('connectLocalMobileReader() readers >>', reader);
    console.log('Reader connected successfully', reader);
    if (error) {
      console.log('connectLocalMobileReader error:', error);
      Alert.alert('Reader not connected');
      return;
    }
    Alert.alert('Reader connected successfully');
    navigation.navigate('NewPayment');
  }

Screenshot unnamed (1)

Stripe Terminal React Native SDK version

I have used the below listed devices

Additional context {YOUR BACKEND URL}/connection_token using this ConnectionToken in index.js

return (
    <StripeTerminalProvider logLevel="verbose" tokenProvider={fetchTokenProvider}>
    <Provider store={store}>
      <PersistGate loading={null} persistor={persistor}>
          <App />
      </PersistGate>
    </Provider>
    </StripeTerminalProvider>
  ); 

Call initialize in app.js

useEffect(() => {
    initialize({
      logLevel: 'verbose',
    });
  }, [initialize]); 

@nazli-stripe @billfinn-stripe can you please look into this and assist me.

mikrich commented 6 months ago

@abhijitCN I am also experiencing a similar issue, I'm testing out a Production build on Android and am getting an error back from stripe when attempting to connect using connectLocalMobileReader.. The message I'm seeing in the error object is No such location: <locationId>. However the location exists. Are you getting a similar message?

abhijitCN commented 6 months ago

@mikrich Thanks for the response,

In our project, location is coming from the backend API I passed the location ID in Stripe. after that I call connectLocalMobileReader() function, and in throw the error the reader is not connecting.

Below Code where I getting error.

async function connectMobileReader() { const {reader, error} = await connectLocalMobileReader({ reader: discoveredReader locationId: stripeLocation?.data?.id, }); if (error) { console.log('connectLocalMobileReader error:', error); Alert.alert('Reader not connected'); return; } }

mikrich commented 6 months ago

what message do you see when you log out console.log('connectLocalMobileReader error:', error); If you are testing on a device you will need to print it out in the alert for example Alert.alert(JSON.strigify(error))

abhijitCN commented 6 months ago

Screenshot_20240529_182236_blink I have attached a screenshot of my error. Have you Faced this !!

mikrich commented 6 months ago

I was facing a different issue No such location: <locationId> however it turns out the request for the token (on our backend) had been set up incorrectly which has now been fixed and it's working. I've not seem the issue you are experiencing.

abhijitCN commented 6 months ago

@mikrich Which Stripe Terminal React Native SDK version are you using?

mikrich commented 6 months ago

@abhijitCN the latest v0.0.1-beta.18

abhijitCN commented 6 months ago

@mikrich can you please look into this and assist me. unnamed (2)

mikrich commented 6 months ago

@abhijitCN this message will show if you don't provide a locationId: https://docs.stripe.com/terminal/payments/connect-reader?terminal-sdk-platform=react-native&reader-type=tap-to-pay#connect-reader

abhijitCN commented 5 months ago

Hi, @mikrich I have a query that my Screen Short Error and your error are the same? unnamed (2)

dshalaby commented 5 months ago

I'm getting the same error (in test mode), and I know that:

(1) I'm the location id from the correct Stripe account/dashboard that is connected in test mode (2) The location id is valid and entered correctly

Android stripe-terminal sdk v2.19.0

Logcat shows this:

 class=TerminalSession
 com.stripe.stripeterminal.external.models.TerminalException: No such location: 'tml_xxxxxxxxxxx'
nazli-stripe commented 5 months ago

@dshalaby are you using the Android SDK directly? the repo for that is https://github.com/stripe/stripe-terminal-android/issues

CarlMenke commented 3 weeks ago

I was facing a different issue No such location: <locationId> however it turns out the request for the token (on our backend) had been set up incorrectly which has now been fixed and it's working. I've not seem the issue you are experiencing.

Im running into this same issue, any chance you could share how you have your connection token endpoint set up in your backend?

dshalaby commented 3 weeks ago

@nazli-stripe Yes I was thank you, sorry for the late reply.

@CarlMenke My connection token endpoint was working fine in so far as the Stripe SDK. Our issue was something internal in our application rather than anything on the Stripe side. In our case this error was coming about because of a conflict in the initial Connect OAUTH token grant and our connection token endpoint.