# DeviceConnect: React Native

Device Connect React Native SDK is used to collect anonymised non-PII data from the devices of the users after taking explicit user consent.

# Requirements

Device Connect React Native SDK works on Android 5.0+ (API level 21+), on Java 8+ and AndroidX. In addition to the changes, enable desugaring so that our SDK can run smoothly on Android 7.0 and versions below.

  • Kotlin
  • Groovy
android {
    ...
    defaultConfig {
        ...
        // Minimum 5.0+ devices
        minSdk 21
        ...
    }
    ...
    compileOptions {
        // Flag to enable support for the new language APIs
        coreLibraryDesugaringEnabled = true
        // Sets Java compatibility to Java 8
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    // For Kotlin projects
    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.1.5")
}

# Add Plugin

Specify the following keys in local.properties file:

ACCESS_KEY=<ACCESS_KEY>
SECRET_KEY=<SECRET_KEY>
DC_SDK_VERSION=<DC_SDK_VERSION>
COMMON_SDK_VERSION=<COMMON_SDK_VERSION>
COMMON_FLAVOR=<COMMON_FLAVOR>
LOGGER_SDK_VERSION=<LOGGER_SDK_VERSION>

In the project level build.gradle file, add the repository urls to all allprojects block.

  • Kotlin
  • Groovy
maven {
    setUrl("s3://risk-manager-android-sdk/artifacts")
    credentials(AwsCredentials::class) {
        accessKey = <ACCESS_KEY>
        secretKey = <SECRET_KEY>
    }
    content {
        includeGroup("in.finbox")
    }
}

Add plugin dependency

  • NPM
  • Yarn
npm install --save react-native-risk-sdk

NOTE

Following will be shared by FinBox team at the time of integration:

  • ACCESS_KEY
  • SECRET_KEY
  • DC_SDK_VERSION
  • COMMON_SDK_VERSION
  • COMMON_FLAVOR
  • LOGGER_SDK_VERSION
  • CLIENT_API_KEY

# Create User

Call createUser method to create the user. It takes Client Api Key and Customer Id as the arguments.

IMPORTANT

Please make sure CUSTOMER_ID is not more than 64 characters and is alphanumeric (with no special characters). Also it should never be null or a blank string "".

The response to this method (success or failure) can be captured using the callback.

import FinBoxRiskSdk from 'react-native-risk-sdk';
//Function to trigger RiskSdk
const callModule = () => {
    FinBoxRiskSdk.createUser(
        "CLIENT_API_KEY",
        "CUSTOMER_ID",
        (errorStatus) => {
     // Error Callback
            console.log("Error status -> ", errorStatus)
        }, 
        (msg) => {
            // Success Callback, Call the periodic sync once the user has been created
     console.log("Final message", msg)
     FinBoxRiskSdk.startPeriodicSync(12) //Start the sync periodically after every 12 hour
 }
    )
}

You can read about the errors in the Error Codes section.

# Start Periodic Sync

This is to be called only on a successful response to createUser method's callback. On calling this the syncs will start for all the data sources configured as per permissions. The method below syncs data in the background at regular intervals:

FinBoxRiskSdk.startPeriodicSync(12) //Start the sync periodically after every 12 hour

Handle Sync Frequency

startPeriodicSync takes one argument which indicates the frequency of sync in hours.

# Match Details on Device

Device matching enables additional pattern recognition to match email, phone numbers and name. The matching happens on the device and the user phone numbers, email addresses won't leave the device.

Call setDeviceMatch method before starting the syncs.

FinBoxRiskSdk.setDeviceMatch("useremail@gmail.com", "Full Name", "9999999999");

# Forward Notifications to SDK

In certain cases, FinBox server requests critical data from SDK directly (other than scheduled sync period), to make sure this works it is required to forward FCM Notifications to SDK.

Add the following lines inside firebase.messaging().onMessage method.

FinBoxRiskSdk.forwardFinBoxNotificationToSDK(remoteMessage.data);

# Cancel Periodic

If you have already set up the sync for the user data, you can cancel it any time by the following code:

FinBoxRiskSdk.stopPeriodicSync();

# Reset User Data

In case the user data needs to be removed on the device so that you can re-sync the entire data, use the method resetData.

FinBoxRiskSdk.resetData();

# Forget User

In case the user choose to be forgotten, use the method forgetUser. This will delete the user details in our system.

FinBoxRiskSdk.forgetUser();
Last Updated: 7/29/2024, 12:04:34 PM