react-native-hyperkyc-sdk 0.16.0 → 0.17.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.
@@ -56,7 +56,7 @@ repositories {
56
56
  dependencies {
57
57
  //noinspection GradleDynamicVersion
58
58
  implementation "com.facebook.react:react-native:+" // From node_modules
59
- implementation('co.hyperverge:hyperkyc:0.16.0@aar', {
59
+ implementation('co.hyperverge:hyperkyc:0.17.2@aar', {
60
60
  transitive = true
61
61
  })
62
62
 
@@ -1,62 +1,41 @@
1
1
  package com.reactnativehyperkycsdk;
2
2
 
3
-
4
3
  import android.app.Activity;
5
4
  import android.content.Intent;
6
5
  import android.util.Log;
7
6
 
8
-
9
-
10
7
  import com.facebook.react.ReactActivity;
11
8
  import com.facebook.react.bridge.ActivityEventListener;
12
-
13
9
  import com.facebook.react.bridge.ReactApplicationContext;
14
10
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
15
11
  import com.facebook.react.bridge.ReactMethod;
16
12
  import com.facebook.react.bridge.Callback;
17
- import com.facebook.react.bridge.ReadableArray;
18
13
  import com.facebook.react.bridge.ReadableMap;
19
14
  import com.facebook.react.bridge.ReadableMapKeySetIterator;
15
+ import com.facebook.react.bridge.ReadableNativeMap;
20
16
  import com.facebook.react.bridge.WritableMap;
21
17
  import com.facebook.react.bridge.WritableNativeMap;
22
18
  import com.google.gson.Gson;
23
19
 
24
-
25
-
26
- import java.util.ArrayList;
27
20
  import java.util.HashMap;
28
- import java.util.List;
29
21
  import java.util.Map;
30
22
 
31
- import org.json.JSONArray;
32
- import org.json.JSONException;
33
23
  import org.json.JSONObject;
34
24
 
35
25
  import co.hyperverge.hyperkyc.HyperKyc;
36
-
37
26
  import co.hyperverge.hyperkyc.data.models.HyperKycConfig;
38
-
39
- import co.hyperverge.hyperkyc.data.models.result.HyperKycData;
40
27
  import co.hyperverge.hyperkyc.data.models.result.HyperKycResult;
41
- import androidx.annotation.NonNull;
42
28
 
29
+ import androidx.annotation.NonNull;
43
30
 
44
- public class HyperkycSdkModule extends ReactContextBaseJavaModule implements ActivityEventListener {
31
+ public class HyperkycSdkModule extends ReactContextBaseJavaModule {
45
32
  public static final String NAME = "Hyperkyc";
46
-
47
33
  private final ReactApplicationContext reactContext;
48
-
49
34
  private final int HYPERKYC_REQUEST_CODE = 56455;
50
- Callback callback;
51
- HyperKyc.Contract contract;
52
- Gson gson;
53
- WritableMap result;
54
-
55
35
 
56
36
  public HyperkycSdkModule(ReactApplicationContext reactContext) {
57
37
  super(reactContext);
58
38
  this.reactContext = reactContext;
59
- this.reactContext.addActivityEventListener(this);
60
39
  }
61
40
 
62
41
  @Override
@@ -65,94 +44,118 @@ public class HyperkycSdkModule extends ReactContextBaseJavaModule implements Act
65
44
  return NAME;
66
45
  }
67
46
 
68
-
69
47
  @ReactMethod
70
- public void launch(ReadableMap kycConfig, Callback resultCallback ){
71
- callback = resultCallback;
72
-
73
-
74
-
75
-
76
- ReactActivity currentActivity = (ReactActivity)getCurrentActivity();
77
- String workflowId = kycConfig.getString("workflowId");
78
- String appId = kycConfig.hasKey("appId") ? kycConfig.getString("appId") : null;
79
- String appKey = kycConfig.hasKey("appKey") ? kycConfig.getString("appKey") : null;
80
- String transactionId = kycConfig.hasKey("transactionId") ? kycConfig.getString("transactionId") : null;
81
- String accessToken = kycConfig.hasKey("accessToken")? kycConfig.getString("accessToken") : null;
82
- String defaultLangCode = kycConfig.hasKey("defaultLangCode")? kycConfig.getString("defaultLangCode") : null;
83
- Boolean useLocation = kycConfig.hasKey("useLocation")? kycConfig.getBoolean("useLocation") : false;
84
- ReadableMap inputsMap = kycConfig.hasKey("inputs")?kycConfig.getMap("inputs"): null;
85
-
86
- HyperKycConfig config = null;
87
- if(accessToken != null){
88
- config = new HyperKycConfig(accessToken, workflowId, transactionId);
89
- }else if(appId != null && appKey != null) {
90
-
91
- config = new HyperKycConfig(appId, appKey, workflowId, transactionId);
92
- }
93
- if(inputsMap != null){
94
- config.setInputs(processInputsArray(inputsMap));
95
- }
96
- if(defaultLangCode != null ){
97
- config.setDefaultLangCode(defaultLangCode);
98
- }
99
-
100
- config.setUseLocation(useLocation);
101
- contract = new HyperKyc.Contract();
102
- Intent newIntent = contract.createIntent(currentActivity, config);
103
- if(currentActivity != null)
48
+ public void launch(ReadableMap kycConfig, Callback resultCallback) {
49
+ ReactActivity currentActivity = (ReactActivity) getCurrentActivity();
50
+ assert kycConfig != null;
51
+ HyperKycConfig config = getHyperKycConfigFromMap(kycConfig);
52
+ HyperKyc.Contract contract = new HyperKyc.Contract();
53
+
54
+ reactContext.addActivityEventListener(new ActivityEventListener() {
55
+ @Override
56
+ public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
57
+ if (requestCode == HYPERKYC_REQUEST_CODE) {
58
+ HyperKycResult hyperKycResult = contract.parseResult(resultCode, data);
59
+ parseKYCResult(hyperKycResult, resultCallback);
60
+ } else {
61
+ resultCallback.invoke(getDummyResultMap());
62
+ }
63
+ reactContext.removeActivityEventListener(this);
64
+ }
65
+
66
+ @Override
67
+ public void onNewIntent(Intent intent) {
68
+ }
69
+ });
70
+
71
+ if (currentActivity != null) {
72
+ Intent newIntent = contract.createIntent(currentActivity, config);
104
73
  currentActivity.startActivityIfNeeded(newIntent, HYPERKYC_REQUEST_CODE);
105
-
106
- }
107
-
108
- @Override
109
- public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
110
- if(requestCode == HYPERKYC_REQUEST_CODE){
111
-
112
- HyperKycResult hyperKycResult = contract.parseResult(resultCode, data);
113
- result = new WritableNativeMap();
114
- parseKYCResult(hyperKycResult);
74
+ } else {
75
+ resultCallback.invoke(getDummyResultMap());
115
76
  }
116
-
117
-
118
77
  }
119
78
 
120
- private void parseKYCResult(HyperKycResult hyperKycResult){
121
-
122
- WritableMap resultMap = new WritableNativeMap();
123
-
79
+ private void parseKYCResult(HyperKycResult hyperKycResult, Callback callback) {
124
80
  try {
125
-
126
-
127
- gson = new Gson();
81
+ Gson gson = new Gson();
128
82
  String resultJSON = gson.toJson(hyperKycResult);
129
83
  JSONObject result = new JSONObject(resultJSON);
130
- resultMap = HyperkycSdkUtils.convertJsonToMap(result);
84
+ WritableMap resultMap = HyperkycSdkUtils.convertJsonToMap(result);
131
85
  callback.invoke(resultMap);
132
- }catch (Exception e){
133
-
86
+ } catch (Exception e) {
87
+ if (e.getLocalizedMessage() != null) {
88
+ Log.e(NAME, e.getLocalizedMessage());
89
+ } else {
90
+ Log.e(NAME, "error parsing hyperKycResult");
91
+ }
92
+ callback.invoke(getDummyResultMap());
134
93
  }
135
-
136
94
  }
137
95
 
138
-
139
-
140
- private Map<String, String> processInputsArray(ReadableMap inputs){
96
+ private Map<String, String> processInputsArray(ReadableMap inputs) {
141
97
  Map<String, String> inputsMap = new HashMap<>();
142
-
143
98
  ReadableMapKeySetIterator iterator = inputs.keySetIterator();
144
- while(iterator.hasNextKey()){
99
+ while (iterator.hasNextKey()) {
145
100
  String key = iterator.nextKey();
146
101
  String value = inputs.getString(key);
147
102
  inputsMap.put(key, value);
148
103
  }
149
-
150
104
  return inputsMap;
151
-
152
105
  }
153
106
 
154
- @Override
155
- public void onNewIntent(Intent intent) {
107
+ private HyperKycConfig getHyperKycConfigFromMap(ReadableMap kycConfig) {
108
+
109
+ String appId = kycConfig.hasKey("appId") ? kycConfig.getString("appId") : null;
110
+ String appKey = kycConfig.hasKey("appKey") ? kycConfig.getString("appKey") : null;
111
+ String accessToken = kycConfig.hasKey("accessToken") ? kycConfig.getString("accessToken") : null;
112
+ String workflowId = kycConfig.hasKey("workflowId") ? kycConfig.getString("workflowId") : null;
113
+ String transactionId = kycConfig.hasKey("transactionId") ? kycConfig.getString("transactionId") : null;
114
+ ReadableMap inputs = kycConfig.hasKey("inputs") ? kycConfig.getMap("inputs") : null;
115
+ String defaultLangCode = kycConfig.hasKey("defaultLangCode") ? kycConfig.getString("defaultLangCode") : null;
116
+ Boolean useLocation = kycConfig.hasKey("useLocation") ? kycConfig.getBoolean("useLocation") : null;
117
+
118
+ if (accessToken == null) {
119
+ assert appId != null;
120
+ assert appKey != null;
121
+ assert workflowId != null;
122
+ assert transactionId != null;
123
+ HyperKycConfig hyperKycConfig = new HyperKycConfig(appId, appKey, workflowId, transactionId);
124
+ if (inputs != null) {
125
+ hyperKycConfig.setInputs(processInputsArray(inputs));
126
+ }
127
+ if (defaultLangCode != null) {
128
+ hyperKycConfig.setDefaultLangCode(defaultLangCode);
129
+ }
130
+ if (useLocation != null) {
131
+ hyperKycConfig.setUseLocation(useLocation);
132
+ }
133
+ return hyperKycConfig;
134
+ } else {
135
+ assert workflowId != null;
136
+ assert transactionId != null;
137
+ HyperKycConfig hyperKycConfig = new HyperKycConfig(accessToken, workflowId, transactionId);
138
+ if (inputs != null) {
139
+ hyperKycConfig.setInputs(processInputsArray(inputs));
140
+ }
141
+ if (defaultLangCode != null) {
142
+ hyperKycConfig.setDefaultLangCode(defaultLangCode);
143
+ }
144
+ if (useLocation != null) {
145
+ hyperKycConfig.setUseLocation(useLocation);
146
+ }
147
+ return hyperKycConfig;
148
+ }
149
+ }
156
150
 
151
+ private WritableMap getDummyResultMap() {
152
+ WritableMap dummyResult = new WritableNativeMap();
153
+ dummyResult.putString("status", "");
154
+ dummyResult.putString("transactionId", "");
155
+ dummyResult.putInt("errorCode", 0);
156
+ dummyResult.putString("errorMessage", "");
157
+ dummyResult.putString("latestModule", "");
158
+ dummyResult.putMap("details", new WritableNativeMap());
159
+ return dummyResult;
157
160
  }
158
161
  }
@@ -6,7 +6,7 @@ import HyperKYC
6
6
  @objc(Hyperkyc)
7
7
  class Hyperkyc: NSObject {
8
8
  @objc static func requiresMainQueueSetup() -> Bool {return true}
9
-
9
+
10
10
  internal var skipKeysArray : [String] = ["responseResult", "variables", "moduleId"]
11
11
  @objc(launch:callback:)
12
12
  func launch(_config: NSDictionary, callback: @escaping RCTResponseSenderBlock) {
@@ -18,53 +18,43 @@ class Hyperkyc: NSObject {
18
18
  let defaultLangCode = _config["defaultLangCode"] as? String
19
19
  let inputs = _config["inputs"] as? [String: String]
20
20
  let useLocation = _config["useLocation"] as? Bool
21
-
22
-
23
-
21
+
24
22
  DispatchQueue.main.async {
25
23
  let controller = RCTPresentedViewController()
26
-
27
- var hyperKYCConfig: HyperKycConfig?
28
-
29
24
 
30
- // Launch HyperKyc if accessTokenConfig is available
25
+ var hyperKYCConfig: HyperKycConfig
26
+
31
27
  if let accessToken = accessToken {
32
28
  hyperKYCConfig = HyperKycConfig(accessToken: accessToken, workflowId: workflowId!, transactionId: transactionId!)
33
29
  }
30
+ else {
31
+ hyperKYCConfig = HyperKycConfig(appId: appId!, appKey: appKey!, workflowId: workflowId!, transactionId: transactionId!)
32
+ }
34
33
 
35
- // Launch HyperKyc if appKey and appId are available
36
- if let appKey = appKey, let appId = appId {
37
- hyperKYCConfig = HyperKycConfig(appId: appId, appKey: appKey, workflowId: workflowId!, transactionId: transactionId!)
34
+ if let inputs = inputs {
35
+ hyperKYCConfig.setInputs(inputs: inputs)
36
+ }
37
+ if let defaultLangCode = defaultLangCode {
38
+ hyperKYCConfig.setDefaultLangCode(language: defaultLangCode)
39
+ }
40
+ if let useLocation = useLocation {
41
+ hyperKYCConfig.setUseLocation(shouldUse: useLocation)
38
42
  }
39
43
 
40
- // Launch HyperKyc with hyperKYCConfig if available
41
- if let hyperKYCConfig = hyperKYCConfig {
42
- if let inputs = inputs {
43
- hyperKYCConfig.setInputs(inputs: inputs)
44
- }
45
- if let defaultLangCode = defaultLangCode {
46
- hyperKYCConfig.setDefaultLangCode(language: defaultLangCode)
47
- }
48
- if let useLocation = useLocation {
49
- hyperKYCConfig.setUseLocation(shouldUse: useLocation)
50
- }
51
- HyperKyc.launch(controller!, hyperKycConfig: hyperKYCConfig) { hyperKycResult in
52
- let result = self.processHyperKycResponse(hyperKycResult: hyperKycResult)
53
- callback([result])
54
- }
44
+ //launch HyperKyc
45
+ HyperKyc.launch(controller!, hyperKycConfig: hyperKYCConfig) { hyperKycResult in
46
+ let result = self.processHyperKycResponse(hyperKycResult: hyperKycResult)
47
+ callback([result])
55
48
  }
56
-
57
-
58
-
59
49
  }
60
50
  }
61
-
51
+
62
52
  func processHyperKycResponse(hyperKycResult: HyperKycResult) -> [String : Any] {
63
53
  var kycData = [:] as [String: Any]
64
-
54
+
65
55
  kycData["status"] = hyperKycResult.status
66
56
  kycData["transactionId"] = hyperKycResult.transactionId
67
-
57
+
68
58
  kycData["details"] = hyperKycResult.details
69
59
  if let errorCode = hyperKycResult.errorCode{
70
60
  kycData["errorCode"] = errorCode
@@ -72,22 +62,11 @@ class Hyperkyc: NSObject {
72
62
  if let errorMessage = hyperKycResult.errorMessage{
73
63
  kycData["errorMessage"] = errorMessage
74
64
  }
75
-
65
+
76
66
  if let moduleId = hyperKycResult.latestModule {
77
67
  kycData["latestModule"] = moduleId
78
68
  }
79
-
69
+
80
70
  return kycData
81
71
  }
82
-
83
-
84
-
85
-
86
-
87
72
  }
88
-
89
-
90
-
91
-
92
-
93
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-hyperkyc-sdk",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "description": "React Native wrapper for HyperKYC SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
16
16
  s.source_files = "ios/**/*.{h,m,mm,swift}"
17
17
  s.static_framework = true
18
18
  s.dependency "React-Core"
19
- s.dependency "HyperKYC", "0.16.0"
19
+ s.dependency "HyperKYC", "0.17.0"
20
20
  # Need these lines to support HyperKYC framework
21
21
  s.preserve_paths = 'HyperKYC.framework'
22
22
  s.xcconfig = { 'OTHER_LDFLAGS' => '-framework HyperKYC' }