React Native
The SDK provides multiple options for your workflow.
The core react element is ReaderSDKProvider, responsible for managing the SDK's lifecycle. It is crucial to ensure that all operations are performed within this component.
To don't waste resources, the ReaderSDKProvider should be utilized as close as possible to the intended operation.
Additionally, a variety of hooks are available to use within this component, enabling operations like scanning readers, conducting transactions (e.g., payments, returns), and more.
Detailed explanations of these functionalities will be provided in the upcoming sections.
Prerequisites
Before getting started, the documentation assumes you are able to create a project with React Native. If you do not meet these prerequisites, follow the links below
Flipper bug
The latest version of React comes with a version of Flipper (a debugging tool) that does not support the Urovo operating system. Therefore, if you install the application on a Urovo device, the application will crash. Since we don't use Flipper, the fix is to comment out the line that initializes it. This is a temporary fix since there is currently no information about the error.
To "fix" this bug, we need to go to the file android/app/src/main/java/com/demogeopagos/MainApplication.java and comment out the following line:
ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
Configuration
-
Request Access Credentials
Contact the Geopagos team to obtain a username and password for accessing the private Nexus repositories where the React Native SDK is hosted. -
Encode Credentials in Base64
Convert your credentials to Base64 using the following format:{username:password}You can use a Base64 encoder or run the following command in a Unix-based terminal:
echo -n 'username:password' | base64 -
Create the .npmrc file
In the root of your project, create a file named .npmrc and add the following content:@geopagos:registry=https://nexus.geopagos.io/repository/geo-npm-hosted-internal/
//nexus.geopagos.io/repository/geo-npm-hosted-internal/:_auth=YOUR_BASE64_AUTH_TOKEN
always-auth=trueReplace YOUR_BASE64_AUTH_TOKEN with the actual Base64-encoded string from step 2.
-
Proceed with Installation
You should now be able to install the SDK and related packages as usual using npm or yarn.
Installation
Install the React Native module to the root of your React Native project with NPM or Yarn:
# Using npm
npm install @geopagos/react-native-readers-sdk
# Using Yarn
yarn add @geopagos/react-native-readers-sdk
And for each type of reader you want to support (you may choose to support one or more)
- QPOS
- MagicPOS
- Urovo SmartPOS
- MoreFun SmartPOS
# Using npm
npm install @geopagos/react-native-qpos-reader-sdk
# Using Yarn
yarn add @geopagos/react-native-qpos-reader-sdk
# Using npm
npm install @geopagos/react-native-magicpos-reader-sdk
# Using Yarn
yarn add @geopagos/react-native-magicpos-reader-sdk
# Using npm
npm install @geopagos/react-native-urovo-reader-sdk
# Using Yarn
yarn add @geopagos/react-native-urovo-reader-sdk
# Using npm
npm install @geopagos/react-native-more-fun-reader-sdk
# Using Yarn
yarn add @geopagos/react-native-more-fun-reader-sdk
Configure the SDK
This SDK exposes a provider component that accepts the following properties:
- endpoint (required): is a string with the URL path of the processor URL. Geopagos will provide this URL
- readers (required): is an array of reader installers. According to the dependencies you added
- applicationKey (required): is the application key provided to use this sdk. Geopagos will provide this key, alongside the
- plugins: is an array of plugins installers. According to the dependencies you added
- logger: is a custom logger you can provide to get additional information about what the sdk is doing (is useful for debugging purposes) credentials
<ReadersSdkProvider
endpoint={"https://some-endpoint.geopagos.com/"}
readers={[urovoReader.createInstaller({ profile: Profiles.ARGENTINA })]}
applicationKey={"SOME_APPLICATION_KEY"}
plugins={[forcePinDeciderPlugin.createInstaller(true)]}
logger={sdkLogger}
></ReadersSdkProvider>
About installers
Each reader has its own installer. If you have added the QPOS, MAGICPOS, and/or UROVO dependencies as mentioned above, you will gain access to the installer object.
The installer object with the function createInstaller may or may not require parameters, depending on the specific reader being used:
urovoReader.createInstaller({ profile: Profiles.ARGENTINA })qposReader.createInstaller()
Initialization example (supporting Urovo and QPOS)
<ReadersSdkProvider
readers={[urovoReader.createInstaller({ profile: Profiles.ARGENTINA }), qposReader.createInstaller()]}
></ReadersSdkProvider>
Scan devices
In order to use this functionality, your application needs Location and Bluetooth permissions to be granted.
To initiate a transaction, a reader is required. Therefore, the first step is to scan for available readers.
The SDK provides the useReaderScanner hook specifically for this purpose.
When utilizing this hook, it is necessary to execute it within the scope of the ReadersSdkProvider (which handles SDK initialization).
This hook can accept an optional numeric parameter as a scan timeout in milliseconds. If no value is provided, it defaults to a predetermined value.
The timeout is utilized when scanning Bluetooth devices, whereas SmartPOS reader detection occurs instantly.
The hook will provide you with the following properties:
- foundReaders: This property will be updated during the scanning process with a list of the readers found.
- scanError: In case of any scanning errors, such as lack of Bluetooth permissions, this property will indicate the specific error.
- isScanning: This boolean property informs whether the scanning process is currently in progress or has completed.
- isInitializing: As the SDK initialization process may take some time and the functioning of this hook relies on the SDK being fully initialized, this property allows you to display a loader while the SDK is being initialized.
const { foundReaders, scanError, isScanning, isInitializing } = useReaderScanner(3000)