Skip to content

Latest commit

 

History

History
302 lines (197 loc) · 15.9 KB

README.md

File metadata and controls

302 lines (197 loc) · 15.9 KB

Instnt Android SDK

This documentation covers the basics of Instnt Android SDK. For a detailed overview of Instnt's functionality, visit the Instnt documentation library

Table of Contents

Prerequisites

  • Sign in to your account on the Instnt Accept's dashboard and create a customer signup workflow that works for your company. Get the workflow ID, which is essential while integrating with Instnt SDK. Refer Quick start guide and Developer guide, for more information.

  • SDK integration depends on your workflow; read the Instnt Accept integration process to understand the functionalities provided by Instnt and how to integrate SDK with your application.

Note: Your implementation with Instnt's SDK may diverge from the integration shown in the sample app. Please contact the Instnt support team for additional questions related to Integration.

Requirements

  • Android Studio 3+
  • Android 4.4 (API 19+)

Getting Started

Instnt android SDK is comprised of android components and mechanisms to facilitate communication between your application, user device and Instnt's APIs.

Note that a Workflow ID is required to execute the android functions properly. For more information concerning Workflow IDs, please visit Instnt's documentation hub.

Install InstntSDK

Gradle

include the instnt SDK aar file in your apps' build.gradle dependency

dependencies {
      implementation 'org.instnt:instntsdk:2.0.4'
}

Initialize transaction

Instnt treats each signup as a transaction. To initialize the signup session and to begin the transaction use the static method instantSDK = InstntSDK.init(this.formKey, serverUrl, this);

formKey : workflowID ServerURl: production URL or sandbox URL this : CallbackHandler

The function returns an InstntSDK interface object; that interface object is used to invoke other SDK functionalities. This interface and various callback handlers listed below are the SDK artifacts you need to interact with.

See the following sample code implementation of initializing the transaction.

public class MainActivity implements CallbackHandler  {

    private InstntSDK instantSDK;

    private void init() {
        String formKey = "REPLACE_YOUR_FORM_KEY";
        String serverURL = "REPLACE_SERVER_URL"; // sandbox or production
        instantSDK = InstntSDK.init(formKey, serverURL, this);
    }

Document verification

Document verification feature comes into the picture if you have enabled it during the workflow creation.

When this feature is enabled, the physical capture and verification of Government-issued identification documents such as Driver's Licenses and Passports are available.

Note: Document Verification feature usage in your SDK requires a License key. Please contact the support at the email support@instnt.org for further assistance.

Document verification pre-requisites

  • Android mobile devices reasonably updated OS version, modern hardware spec, and a good camera

Document verification steps

  1. Firstly, you need to initialize the device camera for capturing the images like font/backside of a Drivers's License, then obtain a pre-signed URL to scan and upload the document and is taken care of by functioning the SDK; see the following sample code:
private void scanDocument(String documentType) {
    if (checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[]{Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION}, MY_CAMERA_REQUEST_CODE);
    } else {
        instantSDK.scanDocument(this.isFront, this.isAutoUpload, documentType, getBaseContext(), DOCUMENT_VERIFY_LICENSE_KEY, this.instantSDK.getInstnttxnid());
    }
}
  1. Next, upload the attachment. The document verification has an auto-upload feature which is turned on by default. It uploads the image to Instnt cloud storage once the image gets captured successfully. If you donot want autoUpload to be on, upload attachment method on InstntSDK interface to initiate the upload.

Following sample code demonstrates the upload attachment process:

binding.uploadDocBtn.setVisibility(View.VISIBLE);
            binding.uploadDocBtn.setOnClickListener(v -> {
                this.instantSDK.uploadAttachment(imageData, true, false, this.instantSDK.getInstnttxnid());
  1. Next, verify the documents that were uploaded.

Following sample code demonstrates the verify document process:

this.instantSDK.verifyDocuments("License", this.instantSDK.getInstnttxnid());

OTP (One-Time Passcode)

OTP functionality can be enabled by logging in Instnt dashboard and enabling OTP in your workflow. Refer to the OTP section of the Quickstart guide for more information.

OTP flow

  • User enters mobile number as part of the signup screen.
  • Your app calls send OTP() SDK function and pass the mobile number.
  • Instnt SDK calls Instnt API and returns the response upon successful OTP delivery.
  • Your app shows the user a screen to enter the OTP code.
  • User enters the OTP code which they received.
  • Your app calls verify the OTP() SDK function to verify the OTP and pass mobile number and OTP code.
  • Instnt SDK calls Instnt API and returns the response upon successful OTP verification

InstntSDK provides two methods to conduct OTP verification. we have also provided the sample code for the implementation.

  1. sendOTP (mobileNumber)
private void sendOTP() {

    //Call send otp api
    View view = binding.containerStep3Contact.getChildAt(0);
    TextView mobile = view.findViewById(org.instnt.accept.instntsdk.R.id.value);
    String mobileNumber = mobile.getText() == null ? null : mobile.getText().toString();

    //Validate number
    if (!isValidE123(mobileNumber)) {
        showProgressDialog(false);
        CommonUtils.showToast(getBaseContext(), "Please enter a valid number with country code");
        return;
    }

    this.instantSDK.sendOTP(mobileNumber, this.instantSDK.getInstnttxnid());
}
  1. verifyOTP(mobileNumber, otpCode)
private void verifyOTP() {

    View view = binding.containerStep3Contact.getChildAt(0);
    TextView mobile = view.findViewById(org.instnt.accept.instntsdk.R.id.value);
    String mobileNumber = mobile.getText() == null ? null : mobile.getText().toString();

    View view1 = binding.containerStep4Otp.getChildAt(1);
    TextView otpText = view1.findViewById(org.instnt.accept.instntsdk.R.id.value);
    String otpCode = otpText.getText() == null ? null : otpText.getText().toString();

    this.instantSDK.verifyOTP(mobileNumber, otpCode, this.instantSDK.getInstnttxnid());
}

Submit form data

After gathering all the relevant end-user information and processing the documents, you can submit all the data to Instnt via a function.

See the sample code of the implementation:

private void submit() {
        Map<String, Object> paramMap = new HashMap<>();
        for (int i = 0; i<binding.containerStep2Name.getChildCount(); i++) {
            BaseInputView inputView = (BaseInputView) binding.containerStep2Name.getChildAt(i);
            inputView.input(paramMap);
        }

        for (int i = 0; i<binding.containerStep3Contact.getChildCount(); i++) {
            BaseInputView inputView = (BaseInputView) binding.containerStep3Contact.getChildAt(i);
            inputView.input(paramMap);
        }

        for (int i = 0; i<binding.containerStep5Address.getChildCount(); i++) {
            BaseInputView inputView = (BaseInputView) binding.containerStep5Address.getChildAt(i);
            inputView.input(paramMap);
        }

        Map<String, String> deviceInfoMap = this.instantSDK.getDeviceInfo(getBaseContext(), this.getWindowManager());
        paramMap.put("mobileDeviceInfo", deviceInfoMap);
        this.instantSDK.submitForm(paramMap);
    }

Please refer to the InstntSDK interface methods listed below for more details.

Callback handler

Instnt provides an Interface called CallbackHandler to implement in your application to handle the callback functions.

Method

Description

Input Parameters

initTransactionSuccessCallback

The callback function when transaction is initialized successfully.

(String instnttxnid)

scanDocumentSuccessCallback

The callback function when scan document is a success.

(InstntImageData imageData)

uploadAttachmentSuccessCallback

The callback function when uploading an attachment is a success.

(InstntImageData imageData)

verifyDocumentsInitiationCallback

The callback function when document verificationi initiated successfully.

(String message)

submitDataSuccessCallback

The callback function when submitting the data is successful.

(FormSubmitData formSubmitData)

sendOTPSuccessCallback

The callback function when sending a OTP is successful.

(String message)

verifyOTPSuccessCallback

The callback function when verifying the OTP is a success.

(String message)

instntErrorCallback

The callback function to handle error coming out from Instnt SDK.

(String message, ErrorCallbackType errorCallbackType)

InstntSDK interface

Method

Input Parameters

Return Parameters

Description

init

(String formKey, String serverUrl, CallbackHandler callbackHandler)

Initializes a user signup session. You need to implement the CallbackHandler class to handle the callbacks.

scanDocument

(boolean isFront, boolean isAutoUpload, String documentType, Context context, String documentVerifyLicenseKey, String instnttxnid)

This fuction enables the document scan. Here the input parameter "Context" that is passed must be getBaseContext() method.

uploadAttachment

(byte[] imageData, boolean isFront, boolean isSelfie, String instnttxnid)

Upload a document file to Instnt server. The input parameter is of the type boolean that represents if the front side of the document is being uploaded.

verifyDocuments

(String documentType, String instnttxnid)

Initiate document verification on Instnt server.

submitData

(Context context, WindowManager windowManager, Map < string, Object > body, String instnttxnid)

Submit the user entered data to Instnt server and initiate customer approval process.

sendOTP

(String mobileNumber, String instnttxnid)

Sends one-time password to the mobile number provided. The mobile number need to be in international format starting with + and country code

verifyOTP

(String mobileNumber, String otpCode, String instnttxnid)

Verifies one-time password that was sent to the provided mobile number.

getInstnttxnid

UUID

Instnt Transaction ID

isOTPverificationEnabled

boolean

Checks whether Instnt Form/Workflow has OTP verification enabled

isDocumentVerificationEnabled

boolean

Checks whether Instnt Form/Workflow has document verification enabled

Resource links

License

The instnt-android SDK is under MIT license.