@netki/netki-mobilesdk

8.20.2 • Public • Published

React NativeTypeScript

NetkiSDK - React Native

Below you will find an overview on how to get going with the React Native installation of the Netki SDK.

Table of Contents

Supported Versions

We have tested and deployed the Netki React Native SDK on the following versions. These are not exclusive but are what we support currently. You may have luck with other versions. If you run into issues our team may be able to help you get around it or to build a compatible version.

  • npm:
  • gradle:
  • xcode: >=10
  • React Native: >=0.60.0
  • iOS: >= 17
  • Android: >= 14

Setup

General npm Configuration

1 - Login to npm

CD into your project directory. Then login to npm.

cd <YOUR PROJECT DIR>
npm login

2 - npm Install

Once you have a React Native project created, go to the root folder and execute.

npm install @netki/netki-mobilesdk

Android configuration

There is not specific configurations for android

iOS configuration

Step 1

On your pod file declare the Netki Library.

  pod 'NetkiSDK', :git => 'https://github.com/netkicorp/onboardid-pod.git', :tag => '8.10.0'

Step 2

If needed, request Camera and File Permissions.

Make sure to declare Camera and File permissions for the app to function properly. You can do this using Xcode UI or by editing the XML file.

INFOPLIST_KEY_NSCameraUsageDescription = "To take pictures";
INFOPLIST_KEY_NSPhotoLibraryAddUsageDescription = "To store pictures";
INFOPLIST_KEY_NSPhotoLibraryUsageDescription = "To store pictures";

Step 3

Make sure to run

  pod install

Expo setup

Configuration

The Expo Config Plugin will allow users on the managed workflow to use the Netki React Native SDK by automating the steps listed in the readme, and running them during expo prebuild (automatically run during eas build).

In order to use this, users will need to update their app.json file to include:

    "plugins": [
        "@netki/netki-mobilesdk"
    ],

After that depending your project you can keep configuring the plugin by either using EAS Build or EAS prebuild

If you decide to use EAS Build, make sure to configure a distribution channel and modify the generated package depending your needs.

Basic usage

The NetkiSDK uses the latest architecture of React Native, utilizing all methods asynchronously. For more details, you can refer to the official Documentation

You can call all methods using the following format:

  const jsFunction = async () => {
    try {
      const result = await netkiSDK.asyncMethodToExecute();
      console.log(result)
    } catch (error) {
      console.error(error);
    }
  };

All the async calls to the SDK return an object called ResultInfo

class ResultInfo(
    val status: RequestStatus,
    val errorType: ErrorType? = null,
    val message: String? = null
)

Step 1

To use the NetkiSDK in you .tsx file you can import it as follows:

  const netkiSDK = require("@netki/netki-mobilesdk").default;

Initialize SDK

Before using any of the methods initialize the SDK as below.

  netkiSDK.initialize();

If you want to set a different environment than production use:

  netkiSDK.initializeWithEnv("DEV");

To validate that the SDK is ready to be used you can do it with the method

  netkiSDK.isAvailable()

Step 2

Configure the SDK passing in the API key provided by Netki as the token.

  netkiSDK.configureWithToken(API_KEY);

Once the configuration callback block returns, the environment will be configured and ready to proceed.

Step 3

Start the process to scan the Id.

  netkiSDK.startIdentificationFlow("idType", "2_LETTER_COUNTRY_CODE");

Where:

idType: The type of id that will be used for the capture process.

The types are:

DRIVERS_LICENSE
PASSPORT
GOVERNMENT_ID

To fetch list of available ids use:

  netkiSDK.getAvailableIdTypes();

idCountry: The country that issued the id that will be used for the capture process.

To fetch the list of available countries use:

  netkiSDK.getAvailableCountries();

Step 4

Handling result of the capture process

To validate the result of the process, you can set up listeners for the events as follows:

  useEffect(() => {
    // Adding event listeners
    const successListener = DeviceEventEmitter.addListener('identificationFlowSuccess', (data) => {
      console.log("Success identification");
    });

    const cancelListener = DeviceEventEmitter.addListener('identificationFlowCancel', () => {
      console.log("User cancel the identification flow");
    });

    const errorListener = DeviceEventEmitter.addListener('identificationFlowError', (error) => {
      const errorType = error.errorType;
      const errorMessage = error.message;
      console.log(error);
    });

    // Cleanup on unmount
    return () => {
      successListener.remove();
      cancelListener.remove();
      errorListener.remove();
    };
  }, []);

Step 5

Once the capture process is successful, create the transaction for identification process.

To create the transaction for the identification process use:

  netkiSDK.submitIdentification();

If the previous method returns a success status, it means that the data was posted successfully, the result of the identification process will be posted to the defined backend callback, this is an async method.

The method returns an optional JSON object containing the extra data returned from the submission of the transaction. You can retrieve the data as follows:

  const result = await netkiSDK.submitIdentification();
  console.log(result)

Response Example The response will be a JSON object that may contain extra data, such as:

  {"tracking_did": "1234567890"}

If no extra data is returned, the result will be true.

If the previous method returns a success status, it means that the data was posted successfully, the result of the identification process will be posted to the defined backend callback, this is an async method.

Addiotional methods

Re-run Biometrics

To re-submit biometric data in the SDk, follow the steps below:

Steps to Re-run Biometrics

Repeat Steps 1 and 2 Begin by completing steps 1 and 2 from the previous section to prepare the environment and initialize the SDK.

Start the Biometric Capture Flow

Use the following command to initiate biometric data capture, replacing "transaction_id" with the appropriate transaction ID:

  netkiSDK.startBiometricsFlow("transaction_id");
Handle the Biometric Flow Results

Use the same listeners specified in Step 4 of the previous section to handle the biometric capture results. These listeners will capture events such as success or failure.

Submit the Captured Biometrics

Once the success event is received, submit the captured biometric data by calling:

  netkiSDK.submitBiometrics();

Extra data

If you want to set extra data specific to your business use:

  netkiSDK.setBusinessMetadata(metadata_json);

Where: metadata_json: Json format string with the data, example: JSON.stringify({ key: "value", key_b: "value_b" })

Error handling

Method invocation

In case when the ResultInfo returns an error status, it will return an ErrorType, the possible values for these are:

NO_INTERNET
INVALID_DATA
INVALID_TOKEN
INVALID_ACCESS_CODE
INVALID_PHONE_NUMBER
INVALID_CONFIRMATION_CODE
UNEXPECTED_ERROR
USER_CANCEL_IDENTIFICATION

In case that there is more information about the error, you can find it in the message inside ResultInfo.

Author

Netki, ops@netki.com

License

NetkiSDK is available under the MIT license. See the LICENSE file for more info.

Readme

Keywords

Package Sidebar

Install

npm i @netki/netki-mobilesdk

Weekly Downloads

81

Version

8.20.2

License

ISC

Unpacked Size

1.48 MB

Total Files

204

Last publish

Collaborators

  • idramp
  • josh.rossi
  • laszlolm
  • charliecruzan
  • tech.bitcoin
  • carlosnetki
  • valentin_kurakin
  • alan10fm
  • netkiops
  • gaiverrr
  • jtangowski
  • justinwnewton
  • hsortiz_athena
  • alfonsocejudo
  • jjovel06
  • alphapointdev
  • mbeade