@digiotech/react-native 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +114 -0
  3. package/android/build.gradle +106 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +3 -0
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/digioreactnative/ArrayUtil.java +162 -0
  8. package/android/src/main/java/com/digioreactnative/DigioReactNativeModule.java +210 -0
  9. package/android/src/main/java/com/digioreactnative/DigioReactNativePackage.java +28 -0
  10. package/android/src/main/java/com/digioreactnative/JsonUtils.java +61 -0
  11. package/android/src/main/java/com/digioreactnative/MapUtil.java +179 -0
  12. package/digio-react-native.podspec +43 -0
  13. package/ios/DigioKycResponse.swift +18 -0
  14. package/ios/DigioReactNative-Bridging-Header.h +3 -0
  15. package/ios/DigioReactNative.mm +20 -0
  16. package/ios/DigioReactNative.swift +114 -0
  17. package/lib/commonjs/index.js +59 -0
  18. package/lib/commonjs/index.js.map +1 -0
  19. package/lib/commonjs/types/enums/environment.js +12 -0
  20. package/lib/commonjs/types/enums/environment.js.map +1 -0
  21. package/lib/commonjs/types/interfaces/digio_config.js +6 -0
  22. package/lib/commonjs/types/interfaces/digio_config.js.map +1 -0
  23. package/lib/commonjs/types/interfaces/digio_response.js +2 -0
  24. package/lib/commonjs/types/interfaces/digio_response.js.map +1 -0
  25. package/lib/commonjs/types/interfaces/error.js +2 -0
  26. package/lib/commonjs/types/interfaces/error.js.map +1 -0
  27. package/lib/commonjs/types/interfaces/gateway_event.js +6 -0
  28. package/lib/commonjs/types/interfaces/gateway_event.js.map +1 -0
  29. package/lib/commonjs/types/interfaces/theme.js +2 -0
  30. package/lib/commonjs/types/interfaces/theme.js.map +1 -0
  31. package/lib/module/index.js +46 -0
  32. package/lib/module/index.js.map +1 -0
  33. package/lib/module/types/enums/environment.js +6 -0
  34. package/lib/module/types/enums/environment.js.map +1 -0
  35. package/lib/module/types/interfaces/digio_config.js +2 -0
  36. package/lib/module/types/interfaces/digio_config.js.map +1 -0
  37. package/lib/module/types/interfaces/digio_response.js +2 -0
  38. package/lib/module/types/interfaces/digio_response.js.map +1 -0
  39. package/lib/module/types/interfaces/error.js +2 -0
  40. package/lib/module/types/interfaces/error.js.map +1 -0
  41. package/lib/module/types/interfaces/gateway_event.js +2 -0
  42. package/lib/module/types/interfaces/gateway_event.js.map +1 -0
  43. package/lib/module/types/interfaces/theme.js +2 -0
  44. package/lib/module/types/interfaces/theme.js.map +1 -0
  45. package/lib/typescript/src/index.d.ts +17 -0
  46. package/lib/typescript/src/index.d.ts.map +1 -0
  47. package/lib/typescript/src/types/enums/environment.d.ts +5 -0
  48. package/lib/typescript/src/types/enums/environment.d.ts.map +1 -0
  49. package/lib/typescript/src/types/interfaces/digio_config.d.ts +8 -0
  50. package/lib/typescript/src/types/interfaces/digio_config.d.ts.map +1 -0
  51. package/lib/typescript/src/types/interfaces/digio_response.d.ts +7 -0
  52. package/lib/typescript/src/types/interfaces/digio_response.d.ts.map +1 -0
  53. package/lib/typescript/src/types/interfaces/error.d.ts +5 -0
  54. package/lib/typescript/src/types/interfaces/error.d.ts.map +1 -0
  55. package/lib/typescript/src/types/interfaces/gateway_event.d.ts +17 -0
  56. package/lib/typescript/src/types/interfaces/gateway_event.d.ts.map +1 -0
  57. package/lib/typescript/src/types/interfaces/theme.d.ts +8 -0
  58. package/lib/typescript/src/types/interfaces/theme.d.ts.map +1 -0
  59. package/package.json +162 -0
  60. package/src/index.ts +91 -0
  61. package/src/types/enums/environment.ts +4 -0
  62. package/src/types/interfaces/digio_config.ts +8 -0
  63. package/src/types/interfaces/digio_response.ts +6 -0
  64. package/src/types/interfaces/error.ts +4 -0
  65. package/src/types/interfaces/gateway_event.ts +16 -0
  66. package/src/types/interfaces/theme.ts +7 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Ramanand Sirvi
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # Digio React Native SDK
2
+
3
+ Official React Native SDK for Digio Gateway Integration
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ yarn install @digiotech/react-native
9
+ ```
10
+
11
+ ## Documentation
12
+
13
+ Documentation of Digio Gateway Integration and their usage is available at <https://documentation.digio.in>
14
+
15
+ ### Basic Usage
16
+
17
+ Instantiate the Digio instance with `environment` & other options
18
+
19
+ ```tsx
20
+ import { Digio, DigioConfig, DigioResponse } from '@digiotech/react-native';
21
+
22
+ const config: DigioConfig = { environment: Environment.PRODUCTION };
23
+ const digio = new Digio(config);
24
+ const documentId = "<document_id>";
25
+ const identifier = "<email_or_phone>";
26
+ const digioResponse: DigioResponse = await digio.start(documentId, identifier);
27
+ ```
28
+
29
+ ### Consuming gateway events [Optional]
30
+
31
+ You can consume events and understand the flow or the journey of the user as he is performing it.
32
+
33
+ For a complete list of events and the payload associated with it, refer [here](https://docs.google.com/document/d/15LHtjGyXd_JNM0de8uH9zB7WllJikRl1d9e4qdy0-C0/edit?usp=sharing)
34
+
35
+ ```tsx
36
+ import { useEffect } from 'react';
37
+ import { Digio, DigioConfig, GatewayEvent } from '@digiotech/react-native';
38
+
39
+ function YourComponent() {
40
+ useEffect(() => {
41
+ const gatewayEventListener = digio.addGatewayEventListener(
42
+ (event: GatewayEvent) => {
43
+ // Do some operation on the received events
44
+ }
45
+ );
46
+
47
+ return () => {
48
+ gatewayEventListener.remove();
49
+ }
50
+ }, []);
51
+ }
52
+ ```
53
+
54
+ ### Complete Usage
55
+
56
+ ```tsx
57
+ import { useEffect } from 'react';
58
+ import { Digio, DigioConfig, GatewayEvent } from '@digiotech/react-native';
59
+
60
+ function YourComponent() {
61
+ useEffect(() => {
62
+ const gatewayEventListener = digio.addGatewayEventListener(
63
+ (event: GatewayEvent) => {
64
+ // Do some operation on the received events
65
+ }
66
+ );
67
+
68
+ return () => {
69
+ gatewayEventListener.remove();
70
+ }
71
+ }, []);
72
+
73
+ const triggerDigioGateway = async () => {
74
+ const config: DigioConfig = { environment: Environment.PRODUCTION };
75
+ const digio = new Digio(config);
76
+ const documentId = "<document_id>";
77
+ const identifier = "<email_or_phone>";
78
+ const tokenId = "<gateway_token_id";
79
+ const digioResponse: DigioResponse = await digio.start(documentId, identifier, tokenId);
80
+
81
+ }
82
+ }
83
+ ```
84
+
85
+ ## SDK Reference
86
+
87
+ ### DigioConfig
88
+
89
+ **Parameters:**
90
+
91
+ | Name | Type | Description |
92
+ |-----------------|---------|----------------------------------------------------------------------------------------|
93
+ | environment* | string | Environment for which you want to open gateway. One of `sandbox` or `production` |
94
+ | logo | string | Pass an URL of your brand logo. **Note:** Pass an optimised image url for best results |
95
+ | theme | string | Options for changing the appearance of the gateway. See below for options under it. |
96
+
97
+ **Theme:**
98
+
99
+ | Name | Type | Description |
100
+ |----------------|---------|--------------------------------------------------------------------------|
101
+ | primaryColor | string | Your brand colour's HEX code to alter CTA (call-to-action) button colors |
102
+ | secondaryColor | string | HEX Code to alter text colors |
103
+ | fontFamily | string | Font Family of your choice. For eg: Crimson Pro |
104
+ | fontFormat | string | Format of the Font Family Provided. For eg: ’woff2’,’ot’,’tt’ |
105
+ | fontUrl | string | Font Family URL. For eg: '{font_family_url}.woff2' |
106
+
107
+ ### DigioResponse [Response received from Gateway]
108
+
109
+ | Name | Type | Description |
110
+ |-------------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
111
+ | code* | number | SUCCESS = 1001 <br /> FAIL = 1002 <br /> CANCEL = -1000 <br /> WEBVIEW_CRASH = 1003 <br /> WEBVIEW_ERROR = 10017 <br /> SDK_CRASH = 1004 <br /> Location/Camera/MicroPhone Permission Denied By User = 1008 |
112
+ | documentId | string | Document ID Passed from the parent app. For eg: `KID22040413040490937VNTC6LAP8KWD` |
113
+ | message | string | Error message in case of crash or failure |
114
+ | permissions | Array<string> | List of mandatory permissions which are not given during kyc journey |
@@ -0,0 +1,106 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ maven { url 'https://jitpack.io' }
6
+ }
7
+
8
+ dependencies {
9
+ classpath "com.android.tools.build:gradle:7.2.1"
10
+ }
11
+ }
12
+
13
+ def isNewArchitectureEnabled() {
14
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
15
+ }
16
+
17
+ apply plugin: "com.android.library"
18
+
19
+ if (isNewArchitectureEnabled()) {
20
+ apply plugin: "com.facebook.react"
21
+ }
22
+
23
+ def getExtOrDefault(name) {
24
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["DigioReactNative_" + name]
25
+ }
26
+
27
+ def getExtOrIntegerDefault(name) {
28
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["DigioReactNative_" + name]).toInteger()
29
+ }
30
+
31
+ def supportsNamespace() {
32
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
33
+ def major = parsed[0].toInteger()
34
+ def minor = parsed[1].toInteger()
35
+
36
+ // Namespace support was added in 7.3.0
37
+ return (major == 7 && minor >= 3) || major >= 8
38
+ }
39
+
40
+ android {
41
+ if (supportsNamespace()) {
42
+ namespace "com.digioreactnative"
43
+
44
+ sourceSets {
45
+ main {
46
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
47
+ }
48
+ }
49
+ }
50
+
51
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
52
+
53
+ defaultConfig {
54
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
55
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
56
+
57
+ }
58
+
59
+ buildTypes {
60
+ release {
61
+ minifyEnabled false
62
+ }
63
+ }
64
+
65
+ lintOptions {
66
+ disable "GradleCompatible"
67
+ }
68
+
69
+ compileOptions {
70
+ sourceCompatibility JavaVersion.VERSION_1_8
71
+ targetCompatibility JavaVersion.VERSION_1_8
72
+ }
73
+ buildFeatures {
74
+ viewBinding true
75
+ dataBinding true
76
+ }
77
+ }
78
+
79
+ repositories {
80
+ mavenCentral()
81
+ google()
82
+ }
83
+
84
+
85
+ dependencies {
86
+ // For < 0.71, this will be from the local maven repo
87
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
88
+ //noinspection GradleDynamicVersion
89
+ implementation "com.facebook.react:react-native:+"
90
+ implementation 'com.github.digio-tech:gateway:v4.0.8'
91
+ implementation 'com.github.digio-tech:gateway_kyc:v4.0.8'
92
+ implementation 'androidx.appcompat:appcompat:1.6.1'
93
+ implementation 'com.google.android.material:material:1.9.0'
94
+ implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
95
+ implementation "androidx.camera:camera-core:1.1.0"
96
+ implementation "androidx.camera:camera-camera2:1.1.0"
97
+ implementation "androidx.camera:camera-lifecycle:1.1.0"
98
+ implementation "androidx.camera:camera-view:1.1.0"
99
+ implementation 'androidx.navigation:navigation-fragment:2.5.3'
100
+ implementation 'androidx.navigation:navigation-ui:2.5.3'
101
+ implementation 'androidx.preference:preference:1.2.0'
102
+ implementation 'com.google.android.gms:play-services-mlkit-face-detection:17.1.0'
103
+ implementation 'com.google.android.gms:play-services-location:21.0.1'
104
+ implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
105
+ }
106
+
@@ -0,0 +1,5 @@
1
+ DigioReactNative_kotlinVersion=1.7.0
2
+ DigioReactNative_minSdkVersion=21
3
+ DigioReactNative_targetSdkVersion=31
4
+ DigioReactNative_compileSdkVersion=31
5
+ DigioReactNative_ndkversion=21.4.7075529
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.digioreactnative">
3
+ </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,162 @@
1
+ package com.digioreactnative;
2
+
3
+ import com.facebook.react.bridge.Arguments;
4
+ import com.facebook.react.bridge.ReadableArray;
5
+ import com.facebook.react.bridge.ReadableType;
6
+ import com.facebook.react.bridge.WritableArray;
7
+ import com.facebook.react.bridge.WritableNativeArray;
8
+
9
+ import org.json.JSONArray;
10
+ import org.json.JSONException;
11
+ import org.json.JSONObject;
12
+
13
+ import java.util.Map;
14
+
15
+ public class ArrayUtil {
16
+
17
+ public static JSONArray toJSONArray(ReadableArray readableArray) throws JSONException {
18
+ JSONArray jsonArray = new JSONArray();
19
+
20
+ for (int i = 0; i < readableArray.size(); i++) {
21
+ ReadableType type = readableArray.getType(i);
22
+
23
+ switch (type) {
24
+ case Null:
25
+ jsonArray.put(i, null);
26
+ break;
27
+ case Boolean:
28
+ jsonArray.put(i, readableArray.getBoolean(i));
29
+ break;
30
+ case Number:
31
+ jsonArray.put(i, readableArray.getDouble(i));
32
+ break;
33
+ case String:
34
+ jsonArray.put(i, readableArray.getString(i));
35
+ break;
36
+ case Map:
37
+ jsonArray.put(i, MapUtil.toJSONObject(readableArray.getMap(i)));
38
+ break;
39
+ case Array:
40
+ jsonArray.put(i, ArrayUtil.toJSONArray(readableArray.getArray(i)));
41
+ break;
42
+ }
43
+ }
44
+
45
+ return jsonArray;
46
+ }
47
+
48
+ public static Object[] toArray(JSONArray jsonArray) throws JSONException {
49
+ Object[] array = new Object[jsonArray.length()];
50
+
51
+ for (int i = 0; i < jsonArray.length(); i++) {
52
+ Object value = jsonArray.get(i);
53
+
54
+ if (value instanceof JSONObject) {
55
+ value = MapUtil.toMap((JSONObject) value);
56
+ }
57
+
58
+ if (value instanceof JSONArray) {
59
+ value = ArrayUtil.toArray((JSONArray) value);
60
+ }
61
+
62
+ array[i] = value;
63
+ }
64
+
65
+ return array;
66
+ }
67
+
68
+ public static Object[] toArray(ReadableArray readableArray) {
69
+ Object[] array = new Object[readableArray.size()];
70
+
71
+ for (int i = 0; i < readableArray.size(); i++) {
72
+ ReadableType type = readableArray.getType(i);
73
+
74
+ switch (type) {
75
+ case Null:
76
+ array[i] = null;
77
+ break;
78
+ case Boolean:
79
+ array[i] = readableArray.getBoolean(i);
80
+ break;
81
+ case Number:
82
+ array[i] = readableArray.getDouble(i);
83
+ break;
84
+ case String:
85
+ array[i] = readableArray.getString(i);
86
+ break;
87
+ case Map:
88
+ array[i] = MapUtil.toMap(readableArray.getMap(i));
89
+ break;
90
+ case Array:
91
+ array[i] = ArrayUtil.toArray(readableArray.getArray(i));
92
+ break;
93
+ }
94
+ }
95
+
96
+ return array;
97
+ }
98
+
99
+ public static WritableArray toWritableArray(Object[] array) {
100
+ WritableArray writableArray = Arguments.createArray();
101
+
102
+ for (int i = 0; i < array.length; i++) {
103
+ Object value = array[i];
104
+
105
+ if (value == null) {
106
+ writableArray.pushNull();
107
+ } else if (value instanceof Boolean) {
108
+ writableArray.pushBoolean((Boolean) value);
109
+ } else if (value instanceof Double) {
110
+ writableArray.pushDouble((Double) value);
111
+ } else if (value instanceof Integer) {
112
+ writableArray.pushInt((Integer) value);
113
+ } else if (value instanceof String) {
114
+ writableArray.pushString((String) value);
115
+ } else if (value instanceof Map) {
116
+ writableArray.pushMap(MapUtil.toWritableMap((Map<String, Object>) value));
117
+ } else if (value.getClass() != null && value.getClass().isArray()) {
118
+ writableArray.pushArray(ArrayUtil.toWritableArray((Object[]) value));
119
+ }
120
+ }
121
+
122
+ return writableArray;
123
+ }
124
+
125
+ public static WritableArray jsonArrayToWritableArray(JSONArray jsonArray) {
126
+ WritableArray writableArray = new WritableNativeArray();
127
+
128
+ if (jsonArray == null) {
129
+ return null;
130
+ }
131
+
132
+ if (jsonArray.length() <= 0) {
133
+ return null;
134
+ }
135
+
136
+ for (int i = 0 ; i < jsonArray.length(); i++) {
137
+ try {
138
+ Object value = jsonArray.get(i);
139
+
140
+ if (value == null) {
141
+ writableArray.pushNull();
142
+ } else if (value instanceof Boolean) {
143
+ writableArray.pushBoolean((Boolean) value);
144
+ } else if (value instanceof Integer) {
145
+ writableArray.pushInt((Integer) value);
146
+ } else if (value instanceof Double) {
147
+ writableArray.pushDouble((Double) value);
148
+ } else if (value instanceof String) {
149
+ writableArray.pushString((String) value);
150
+ } else if (value instanceof JSONObject) {
151
+ writableArray.pushMap(MapUtil.jsonToWritableMap((JSONObject) value));
152
+ } else if (value instanceof JSONArray) {
153
+ writableArray.pushArray(jsonArrayToWritableArray((JSONArray) value));
154
+ }
155
+ } catch (JSONException e) {
156
+ e.printStackTrace();
157
+ }
158
+ }
159
+
160
+ return writableArray;
161
+ }
162
+ }
@@ -0,0 +1,210 @@
1
+ package com.digioreactnative;
2
+
3
+ import android.annotation.SuppressLint;
4
+ import android.app.Activity;
5
+ import android.content.BroadcastReceiver;
6
+ import android.content.Context;
7
+ import android.content.Intent;
8
+ import android.content.IntentFilter;
9
+ import android.text.TextUtils;
10
+
11
+ import androidx.annotation.NonNull;
12
+ import androidx.annotation.Nullable;
13
+ import androidx.core.content.ContextCompat;
14
+
15
+ import com.facebook.react.bridge.ActivityEventListener;
16
+ import com.facebook.react.bridge.Arguments;
17
+ import com.facebook.react.bridge.Promise;
18
+ import com.facebook.react.bridge.ReactApplicationContext;
19
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
20
+ import com.facebook.react.bridge.ReactMethod;
21
+ import com.facebook.react.bridge.ReadableMap;
22
+ import com.facebook.react.bridge.WritableArray;
23
+ import com.facebook.react.bridge.WritableMap;
24
+ import com.facebook.react.module.annotations.ReactModule;
25
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
26
+
27
+ import org.json.JSONException;
28
+ import org.json.JSONObject;
29
+
30
+ import java.util.HashMap;
31
+ import java.util.Iterator;
32
+ import java.util.Locale;
33
+ import java.util.Map;
34
+
35
+ import in.digio.sdk.gateway.DigioActivity;
36
+ import in.digio.sdk.gateway.DigioConstants;
37
+ import in.digio.sdk.gateway.enums.DigioEnvironment;
38
+ import in.digio.sdk.gateway.enums.DigioErrorCode;
39
+ import in.digio.sdk.gateway.model.DigioConfig;
40
+ import in.digio.sdk.gateway.model.DigioTheme;
41
+
42
+ @ReactModule(name = DigioReactNativeModule.NAME)
43
+ public class DigioReactNativeModule extends ReactContextBaseJavaModule {
44
+ public static final String NAME = "DigioReactNative";
45
+
46
+ public static final String AAR_VERSION = "4.0.8";
47
+ public static final int DIGIO_ACTIVITY = 73457843;
48
+ private Promise resultPromise;
49
+
50
+ private BroadcastReceiver eventBroadcastReceiver = new BroadcastReceiver() {
51
+
52
+ @Override
53
+ public void onReceive(Context context, Intent intent) {
54
+ if (intent.getStringExtra("data") != null) {
55
+ JSONObject jsonObject = null;
56
+ try {
57
+ jsonObject = new JSONObject(
58
+ intent.getStringExtra(
59
+ "data"
60
+ )
61
+ );
62
+ } catch (JSONException e) {
63
+ e.printStackTrace();
64
+ }
65
+ WritableMap resultMap = MapUtil.jsonToWritableMap(jsonObject);
66
+ getReactApplicationContext()
67
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
68
+ .emit("gatewayEvent", resultMap);
69
+ }
70
+ }
71
+ };
72
+
73
+ ActivityEventListener activityEventListener = new ActivityEventListener() {
74
+ @Override
75
+ public void onActivityResult(Activity activity, int requestCode, int resultCode, @Nullable Intent intent) {
76
+ if (requestCode == DIGIO_ACTIVITY) {
77
+ onNativeActivityResult(resultCode, intent);
78
+ }
79
+ }
80
+
81
+ @Override
82
+ public void onNewIntent(Intent intent) {
83
+
84
+ }
85
+ };
86
+
87
+ private void onNativeActivityResult(int resultCode, Intent data) {
88
+ WritableMap resultMap = Arguments.createMap();
89
+ resultMap.putInt("code", resultCode);
90
+ if (data != null) {
91
+ resultMap.putString("message", data.getStringExtra("message"));
92
+ String screenName = data.getStringExtra("screen_name");
93
+ if (TextUtils.isEmpty(screenName)) {
94
+ screenName = "starting_digio";
95
+ }
96
+ resultMap.putString("screen", screenName);
97
+ resultMap.putString("step", data.getStringExtra("step"));
98
+ resultMap.putString("documentId", data.getStringExtra("document_id"));
99
+ resultMap.putString("failingUrl", data.getStringExtra("failing_url"));
100
+ resultMap.putInt("errorCode", data.getIntExtra("error_code", resultCode));
101
+ String[] stringArrayExtra = data.getStringArrayExtra("permissions");
102
+ WritableArray permissionArray = Arguments.createArray();
103
+ if (stringArrayExtra != null && stringArrayExtra.length > 0) {
104
+ for (String permission : stringArrayExtra) {
105
+ permissionArray.pushString(permission);
106
+ }
107
+ }
108
+ resultMap.putArray(
109
+ "permissions", permissionArray);
110
+ }
111
+ if (resultCode == DigioConstants.RESPONSE_CODE_SUCCESS) {
112
+ if (resultMap.getString("message") == null) {
113
+ resultMap.putString("message", "KYC Success");
114
+ }
115
+ } else if (resultCode == DigioErrorCode.DIGIO_PERMISSIONS_REQUIRED.getErrorCode()) {
116
+ resultMap.putInt("errorCode", resultCode);
117
+ } else {
118
+ if (resultMap.getString("message") == null) {
119
+ resultMap.putString("message", "KYC Failure");
120
+ }
121
+ resultMap.putInt("errorCode", resultCode);
122
+ }
123
+ resultPromise.resolve(resultMap);
124
+ }
125
+
126
+ @SuppressLint("WrongConstant")
127
+ public DigioReactNativeModule(ReactApplicationContext reactContext) {
128
+ super(reactContext);
129
+ reactContext.addActivityEventListener(activityEventListener);
130
+ ContextCompat.registerReceiver(
131
+ reactContext, eventBroadcastReceiver,
132
+ new IntentFilter(DigioConstants.GATEWAY_EVENT),
133
+ ContextCompat.RECEIVER_NOT_EXPORTED
134
+ );
135
+ }
136
+
137
+ @Override
138
+ @NonNull
139
+ public String getName() {
140
+ return NAME;
141
+ }
142
+
143
+ @ReactMethod
144
+ public void start(String documentId, String identifier, String tokenId, ReadableMap additionalData, ReadableMap config, Promise promise) {
145
+ this.resultPromise = promise;
146
+ try {
147
+ Intent intent = new Intent(this.getCurrentActivity(), DigioActivity.class);
148
+ DigioConfig digioConfig = new DigioConfig();
149
+ String environment = config.getString("environment");
150
+ String logo = config.getString("logo");
151
+ if (!TextUtils.isEmpty(environment)) {
152
+ try {
153
+ digioConfig.setEnvironment(DigioEnvironment.valueOf(environment.toUpperCase(Locale.ENGLISH)));
154
+ } catch (Exception e) {
155
+ e.printStackTrace();
156
+ }
157
+ }
158
+ if (!TextUtils.isEmpty(logo)) {
159
+ digioConfig.setLogo(logo);
160
+ }
161
+ DigioTheme digioTheme = new DigioTheme();
162
+
163
+ String primaryColor = config.getString("primaryColor");
164
+ if (!TextUtils.isEmpty(primaryColor)) {
165
+ digioTheme.setPrimaryColorHex(primaryColor);
166
+ }
167
+ String secondaryColor = config.getString("secondaryColor");
168
+ if (!TextUtils.isEmpty(secondaryColor)) {
169
+ digioTheme.setSecondaryColorHex(secondaryColor);
170
+ }
171
+ String fontFormat = config.getString("fontFormat");
172
+ if (!TextUtils.isEmpty(fontFormat)) {
173
+ digioTheme.setFontFormat(fontFormat);
174
+ }
175
+ String fontFamily = config.getString("fontFamily");
176
+ if (!TextUtils.isEmpty(fontFamily)) {
177
+ digioTheme.setFontFamily(fontFamily);
178
+ }
179
+ String fontUrl = config.getString("fontUrl");
180
+ if (!TextUtils.isEmpty(fontUrl)) {
181
+ digioTheme.setFontUrl(fontUrl);
182
+ }
183
+
184
+ digioConfig.setTheme(digioTheme);
185
+
186
+ intent.putExtra("config", digioConfig);
187
+ intent.putExtra("aar_version", AAR_VERSION);
188
+ intent.putExtra("navigation_graph", R.navigation.workflow);
189
+ intent.putExtra("document_id", documentId);
190
+ intent.putExtra("customer_identifier", identifier);
191
+ intent.putExtra("token_id", tokenId);
192
+ HashMap additionalDataMap = new HashMap();
193
+ if (additionalData != null) {
194
+ Iterator<Map.Entry<String, Object>> entryIterator = additionalData.getEntryIterator();
195
+ while (entryIterator.hasNext()) {
196
+ Map.Entry<String, Object> objectEntry = entryIterator.next();
197
+ additionalDataMap.put(objectEntry.getKey(), objectEntry.getValue());
198
+ }
199
+ }
200
+ intent.putExtra("additional_data", additionalDataMap);
201
+ this.getCurrentActivity().startActivityForResult(intent, DIGIO_ACTIVITY);
202
+ } catch (Exception e) {
203
+ // Throws DigioException if WorkflowResponseListener is not implemented/passed, or
204
+ // DigioConfig is not valid (check config parameters)
205
+ // It is mandatory to implemented/add WorkflowResponseListener
206
+ e.printStackTrace();
207
+ resultPromise.reject(e);
208
+ }
209
+ }
210
+ }
@@ -0,0 +1,28 @@
1
+ package com.digioreactnative;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ import com.facebook.react.ReactPackage;
6
+ import com.facebook.react.bridge.NativeModule;
7
+ import com.facebook.react.bridge.ReactApplicationContext;
8
+ import com.facebook.react.uimanager.ViewManager;
9
+
10
+ import java.util.ArrayList;
11
+ import java.util.Collections;
12
+ import java.util.List;
13
+
14
+ public class DigioReactNativePackage implements ReactPackage {
15
+ @NonNull
16
+ @Override
17
+ public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) {
18
+ List<NativeModule> modules = new ArrayList<>();
19
+ modules.add(new DigioReactNativeModule(reactContext));
20
+ return modules;
21
+ }
22
+
23
+ @NonNull
24
+ @Override
25
+ public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) {
26
+ return Collections.emptyList();
27
+ }
28
+ }