Giter Site home page Giter Site logo

Comments (14)

arekkubaczkowski avatar arekkubaczkowski commented on August 10, 2024 1

I believe those changes might fix the issue on Android 12
https://github.com/stripe/stripe-terminal-react-native/pull/56/files#diff-ed8534ece8080a880075e103269eb1b9bdff22e8dfcf8427d7d977603292b889R7

https://github.com/stripe/stripe-terminal-react-native/pull/56/files#diff-8fc083d75c4d06482dc1ee1c9ba3edab0192a99add6fa96679b6ed189a049c88R15

from stripe-terminal-react-native.

jdivock-stripe avatar jdivock-stripe commented on August 10, 2024

To be clear, this happens at the time of connect to a BT reader.

In addition to app checks, I tried adding

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

As is used in the example app with no change in behavior.

from stripe-terminal-react-native.

jdivock-stripe avatar jdivock-stripe commented on August 10, 2024

Can we also clean up the guidance or just provide a utility in the SDK that handles this? We should make it clear and easy for users to be able to write an app that can work on either platform and currently the android checks need a guard around them to not execute on iOS

from stripe-terminal-react-native.

jdivock-stripe avatar jdivock-stripe commented on August 10, 2024

chatting with @dhenry-stripe we may need to upgrade the android SDK here to one that uses a version of the bbpos SDK that supports android 12

from stripe-terminal-react-native.

arekkubaczkowski avatar arekkubaczkowski commented on August 10, 2024

@jdivock-stripe to clarify, didn't you make it work yet right? And you are facing the same issue in the example app?
I've covered this case in the README file https://github.com/stripe/stripe-terminal-react-native#android-1 and actually this code snippet should do the trick. If it's not, I need to investigate it again.

from stripe-terminal-react-native.

jdivock-stripe avatar jdivock-stripe commented on August 10, 2024

The guidance in the doc does not work as described, as mentioned in the comment above it may just be a matter of upgrading the underlying android SDK

from stripe-terminal-react-native.

arekkubaczkowski avatar arekkubaczkowski commented on August 10, 2024

@jdivock-stripe I've initialized new react native project (cli) and just installed stripe-terminal-react-native library. I haven't encountered any issue regarding permissions, this is the full code that I used to make it works:

import React, {useEffect, useState} from 'react';
import {
  Alert,
  PermissionsAndroid,
  Platform,
  ScrollView,
  Text,
  TouchableOpacity,
  View,
} from 'react-native';

import {
  connectBluetoothReader,
  Reader,
  StripeTerminalProvider,
  useStripeTerminal,
} from 'stripe-terminal-react-native';

const App = () => {
  const [permissionsGranted, setPermissionsGranted] = useState(false);
  const [discovered, setDiscovered] = useState<Reader.Type[]>([]);
  const [connected, setConnected] = useState<Reader.Type>([]);

  const fetchTokenProvider = async () => {
    const response = await fetch('http://10.0.2.2:3002/connection_token', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({}),
    });
    const {secret} = await response.json();
    return secret;
  };

  const style = {
    flex: 1,
    height: 800,
  };

  useEffect(() => {
    async function init() {
      try {
        const granted = await PermissionsAndroid.request(
          'android.permission.ACCESS_FINE_LOCATION',
          {
            title: 'Location Permission Permission',
            message: 'App needs access to your Location ',
            buttonPositive: 'Agree',
          },
        );

        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
          console.log('You can use the Location');
          setPermissionsGranted(true);
        } else {
          Alert.alert(
            'Location services are required in order to connect to a reader.',
          );
        }
      } catch {
        Alert.alert(
          'Location services are required in order to connect to a reader.',
        );
      }
    }

    if (Platform.OS === 'android') {
      init();
    } else {
      setPermissionsGranted(true);
    }
  }, []);

  const {discoverReaders} = useStripeTerminal({
    onFinishDiscoveringReaders: finishError => {
      console.log('finishError', finishError);
    },
    onUpdateDiscoveredReaders: readers => {
      console.log('readers', readers);
      setDiscovered(readers);
    },
  });

  const handleConnect = async () => {
    const {reader, error} = await connectBluetoothReader({
      readerId: discovered[0].serialNumber,
      // locationId: selectedLocation?.id,
    });
    if (reader) {
      setConnected(reader);
    }
  };

  const handleDiscover = async () => {
    const {error} = await discoverReaders({
      discoveryMethod: 'bluetoothScan',
      simulated: true,
    });
    console.log('error', error);
  };

  return (
    <ScrollView contentContainerStyle={style}>
      {permissionsGranted && (
        <StripeTerminalProvider tokenProvider={fetchTokenProvider}>
          <>
            <TouchableOpacity
              style={{backgroundColor: '#dffaaa', width: 150, height: 45}}
              onPress={handleDiscover}>
              <Text>discoveredReaders</Text>
            </TouchableOpacity>
            {discovered.map(reader => (
              <View style={{height: 30}}>
                <Text>{reader.serialNumber}</Text>
              </View>
            ))}
            {discovered.length > 0 && (
              <TouchableOpacity
                style={{backgroundColor: '#dffaaa', width: 150, height: 45}}
                onPress={handleConnect}>
                <Text>Connect via bluetooth</Text>
              </TouchableOpacity>
            )}
            {connected && (
              <View style={{height: 30}}>
                <Text>Connected reader:</Text>
                <Text>{connected.serialNumber}</Text>
              </View>
            )}
          </>
        </StripeTerminalProvider>
      )}
    </ScrollView>
  );
};

export default App;

from stripe-terminal-react-native.

arekkubaczkowski avatar arekkubaczkowski commented on August 10, 2024

does it happen in simulated mode or only with physical readers?

from stripe-terminal-react-native.

arekkubaczkowski avatar arekkubaczkowski commented on August 10, 2024
terminal-permissions.mov

from stripe-terminal-react-native.

jdivock-stripe avatar jdivock-stripe commented on August 10, 2024

The example app crashes out immediately upon load on my Pixel 5a (android 12) my emulator loads, but that's a pixel 5 on android 11… setting up an AVD with 12 now to try to confirm. As stated earlier in the thread I think we're aware of BT changes in android 12 and it's my understanding we'll probably have to update the underlying terminal android sdk to resolve

from stripe-terminal-react-native.

jdivock-stripe avatar jdivock-stripe commented on August 10, 2024

Confirmed on the emulator as well, logged #57

from stripe-terminal-react-native.

arekkubaczkowski avatar arekkubaczkowski commented on August 10, 2024

also upgraded Android SDK version

from stripe-terminal-react-native.

ArekBiczysko avatar ArekBiczysko commented on August 10, 2024

@jdivock-stripe please let us know after you run Arek's code on the emulator if you still get the errors.

from stripe-terminal-react-native.

jdivock-stripe avatar jdivock-stripe commented on August 10, 2024

branch still crashes out on app load, hardware device isn't needed to repro as this is reproducible with an emulated Pixel 5 on android 12

logcat here:
https://gist.github.com/jdivock-stripe/2b248ae192a1772990fb2452f1821e4e

from stripe-terminal-react-native.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.