# Implementation Guide

### Authentication

A unique access token should be created upon each SDK entry. In order to generate an access token, please refer to Valify's [Authentication](https://valify.gitbook.io/documentation/apis/oauth-token) Documentation.

{% hint style="warning" %}
**Security Warning:** For improved security, consider implementing the access token fetching logic outside the Activity. This helps keep sensitive credentials secure and reduces potential exposure within the Activity/Fragment code.
{% endhint %}

### Configurations

The plugin builder is separated into two components.

#### Required Configurations

Initialize the required parameters as follows while adding the required configurations

```javascript
const token = "token";
const baseUrl = "base_url";
const bundleKey = "your_bundle_key";

```

#### Optional Configurations

Initialize the required parameters as follows while adding the desired configurations

<pre class="language-javascript"><code class="lang-javascript">const language = "&#x3C;insert_language>"; // "en" is set as default
const dataValidation = &#x3C;boolean>; // false is set as default
const reviewData = &#x3C;boolean>; // default is true
const captureOnlyMode = &#x3C;boolean>; // default is false
const primaryColor = "&#x3C;hex_color_code>"; //hexString color 
<strong>const headers = {}; // default is empty
</strong>const enable_logging = &#x3C;boolean>; // default false 
const sslCertificate = ""; // certificate, no default
const setDocumentVerificationPlus = &#x3C;boolean> // default is false
const setCollectUserInfo = &#x3C;boolean> //default is false
const setAdvancedConfidence  = &#x3C;boolean> //default is false

</code></pre>

### Configurations Breakdown

This section shows the breakdown of all optional builder configurations.&#x20;

1. The following line is where the user interface language is set.&#x20;

```javascript
const language = "<insert_language>"; // ["ar" or "en"] 
```

{% hint style="info" %}
The currently supported languages are Arabic and English
{% endhint %}

2. If the following line is set to true, an extra layer of validations is added to the SDK response.

```javascript
const dataValidation = <boolean>;
```

4. If the following line is set to true, a screen is added to the user flow that displays the images captured and the OCR result to the user.

```javascript
const reviewData = <boolean>;
```

6. If the following line is set to true, the SDK purely performs image capturing and only returns these images in the SDK response.

```javascript
const captureOnlyMode = <boolean>;
```

7. The following line is optional and can be used to set your company's branding color to the SDK's user interface.

```javascript
const primaryColor = "<hex_color_code>";
```

8. The following line is optional and can be used to set any headers that may be required for purposes specific to your application. Any headers set will be sent along with each API call made by the SDK.&#x20;

```javascript
const headers = {};
```

9. The following line is optional and can be used to receive event logs from the SDK experience to be used for user behavior analysis.&#x20;

```javascript
const enable_logging = <boolean>;
```

10. The following line is optional and can be used to set an SSL certificate that may be required for purposes specific to your application.&#x20;

```javascript
const sslCertificate = "";
```

11. If this flag is set to **true**, the SDK performs additional **data validations** on the document.\
    These validations are returned in the SDK response as **flags**, and **you must implement your own handling logic based on these flags** [**\[Handling Document Verification Plus  Flags in Code\]**](/valify-ios-sdk-documentation/document-capture/android-native-sdk/sdk-response.md#document-verification-plus-case-handling) , the SDK does not auto-reject or block the transaction.

    &#x20;      View Document Verification Plus Breakdown here: [**\[Understanding Document verification plus flag\]**](https://valify.gitbook.io/documentation/apis/egy-nid-ocr/egy-nid-ocr#document-verification-plus-breakdown)

```javascript
const setDocumentVerificationPlus = <boolean>
```

12. If this flag is set to **true**, the SDK detects **potential physical or digital manipulation in the National ID**. These validations are returned in the SDK response as **flags**, and **you must implement your own handling logic based on these flags** [**\[Handling Advanced Confidence Flags in Code\]** ](https://valify.gitbook.io/valify-ios-sdk-documentation/document-capture/cordova-plugin/plugin-response#advance-confidence-case-handling), the SDK does not auto-reject or block the transaction.

    &#x20;View Advanced Confidence Breakdown here: [**\[Understanding Advanced  Confidence flag\]**](https://valify.gitbook.io/documentation/kyc/kyc-documents/egy-nid-ocr/egy-nid-ocr#advanced-confidence-breakdown)

```javascript
const setAdvancedConfidence  = <boolean>
```

13. description here (location permission needed for android)

```javascript
const setCollectUserInfo = <boolean>
```

### Parameter Declaration

Declare the SDK parameters with the configuration variables previously created

```javascript
const params = {
  access_token: token,
  base_url: baseUrl,
  bundle_key: bundleKey,
  language: language,
  data_validation: dataValidation,
  review_data: reviewData,
  capture_only_mode: captureOnlyMode,
  ssl_certificate: sslCertificate,
  primary_color: primaryColor,
  enable_logging: enableLogging,
  set_document_verification_plus: setDocumentVerificationPlus,
  set_collect_user_info: setCollectUserInfo, 
  set_advanced_confidence: setAdvancedConfidence 
};
```

### Start the SDK

Use the following code snippet to run the plugin

```javascript
window.VIDVOCRPlugin.startOCR(
        params, headers,
        (result) => {
          console.log('valify success result : ', result);
          const s = result.toString();
          const json = JSON.parse(s);
  if(json.nameValuePairs.state=="CAPTURED_IMAGES"){
//  Process is still running, you receive any captured image here
      	}else if(json.nameValuePairs.state=="EVENT_LOGS"){
 // Process is still running, you receive here any event during user’s session
     }else if(json.nameValuePairs.state=="ERROR_LOGS"){
 // Process is still running, you receive here any error during user’s session
}else if(json.nameValuePairs.state=="SUCCESS"){
 // Process finished successfully 
}
        },
        (error) => {
          console.log('error in valify', error);
          const s = error.toString();
          const json = JSON.parse(s);
           if (json.nameValuePairs.state=="EXIT") {
            // user exits the SDK due to an error occurred
          } else if (json.nameValuePairs.state=="ERROR"){ 
           // user exits the SDK due to builder error }
        } else if (json.nameValuePairs.state=="FAILURE"){ 
           // user exits the SDK due to service failure }
        }
        });
```

### Sample Integration Example

Check out our [GitHub repository](https://github.com/Valify-Solutions/VIDVOCR-Liveness-Cordova-Demo) for a simple integration app demonstrating how to use our SDK. The repository includes step-by-step instructions and sample code to help you get started quickly.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://valify.gitbook.io/valify-ios-sdk-documentation/document-capture/cordova-plugin/implementation-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
