react-native-hyperkyc-sdk 0.1.2-alpha → 0.1.6-alpha1

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.
@@ -57,7 +57,7 @@ dependencies {
57
57
  //noinspection GradleDynamicVersion
58
58
  implementation "com.facebook.react:react-native:+" // From node_modules
59
59
 
60
- implementation('co.hyperverge:hyperkyc:0.0.1-alpha01@aar', {
60
+ implementation('co.hyperverge:hyperkyc:0.0.1-alpha02@aar', {
61
61
  transitive = true
62
62
  })
63
63
  }
@@ -0,0 +1,8 @@
1
+ package com.reactnativehyperkycsdk;
2
+ public class HyperkycConstants {
3
+
4
+ public final static String COUNTRY_ID = "countryId";
5
+ public final static String DOCUMENT_ID = "documentId";
6
+ public final static String USE_FOR_FACE_MATCH = "useForFaceMatch";
7
+
8
+ }
@@ -25,7 +25,8 @@ import java.util.ArrayList;
25
25
  import java.util.List;
26
26
 
27
27
 
28
- import co.hyperverge.hyperkyc.HyperKYC;
28
+ import co.hyperverge.hyperkyc.HyperKyc;
29
+ import co.hyperverge.hyperkyc.data.models.DocFlowConfig;
29
30
  import co.hyperverge.hyperkyc.data.models.HyperKycConfig;
30
31
  import co.hyperverge.hyperkyc.data.models.HyperKycData;
31
32
  import co.hyperverge.hyperkyc.data.models.HyperKycFlow;
@@ -33,8 +34,8 @@ import co.hyperverge.hyperkyc.data.models.HyperKycResult;
33
34
 
34
35
 
35
36
 
36
- public class HyperkycSdkModule extends ReactContextBaseJavaModule {
37
- public static final String NAME = "HyperkycSdk";
37
+ public class HyperkycSdkModule extends ReactContextBaseJavaModule implements ActivityEventListener {
38
+ public static final String NAME = "Hyperkyc";
38
39
 
39
40
  private final ReactApplicationContext reactContext;
40
41
 
@@ -58,94 +59,106 @@ public class HyperkycSdkModule extends ReactContextBaseJavaModule {
58
59
  }
59
60
 
60
61
 
61
- @ReactMethod
62
- public void launch(ReadableMap kycConfig, Callback resultCallback) {
63
- callback = resultCallback;
64
- ReadableArray array = kycConfig.getArray("workflow");
62
+ @ReactMethod
63
+ public void launch(ReadableMap kycConfig, Callback resultCallback ){
64
+ callback = resultCallback;
65
65
 
66
- List<HyperKycFlow> workflow = processWorkFlow((array.toArrayList()));
66
+ ReactActivity currentActivity = (ReactActivity)getCurrentActivity();
67
+ List<HyperKycFlow> workflow = processWorkFlow(kycConfig.getString("workflow"));
68
+ String appId = kycConfig.hasKey("appId") ? kycConfig.getString("appId") : null;
69
+ String appKey = kycConfig.hasKey("appKey") ? kycConfig.getString("appKey") : null;
70
+ String transactionId = kycConfig.hasKey("transactionId") ? kycConfig.getString("transactionId") : null;
71
+ String defaultCountryId = kycConfig.hasKey("defaultCountryId") ? kycConfig.getString("defaultCountryId"): null;
72
+ String accessToken = kycConfig.hasKey("accessToken")? kycConfig.getString("accessToken") : null;
67
73
 
68
- ReactActivity currentActivity = (ReactActivity) getCurrentActivity();
69
- HyperKycConfig config = new HyperKycConfig(kycConfig.getString("appId"), kycConfig.getString("accessToken"), workflow, kycConfig.getString("transactionId"));
74
+ HyperKycConfig config = null;
75
+ if(accessToken != null){
76
+ config = new HyperKycConfig(accessToken, workflow, transactionId, defaultCountryId );
77
+ }else if(appId != null && appKey != null) {
70
78
 
71
- contract = new HyperKYC.Contract();
72
- Intent newIntent = contract.createIntent(currentActivity, config);
73
- if (currentActivity != null)
74
- currentActivity.startActivityIfNeeded(newIntent, HYPERKYC_REQUEST_CODE);
79
+ config = new HyperKycConfig(appId, appKey, workflow, transactionId, defaultCountryId);
80
+ }
81
+ contract = new HyperKyc.Contract();
82
+ Intent newIntent = contract.createIntent(currentActivity, config);
83
+ if(currentActivity != null)
84
+ currentActivity.startActivityIfNeeded(newIntent, HYPERKYC_REQUEST_CODE);
75
85
 
76
- }
86
+ }
87
+
88
+ @Override
89
+ public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
90
+ if(requestCode == HYPERKYC_REQUEST_CODE){
91
+
92
+ HyperKycResult hyperKycResult = contract.parseResult(resultCode, data);
93
+ result = new WritableNativeMap();
94
+ parseKYCResult(hyperKycResult);
95
+ }
77
96
 
78
- @Override
79
- public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
80
- if (requestCode == HYPERKYC_REQUEST_CODE) {
81
97
 
82
- HyperKycResult hyperKycResult = contract.parseResult(resultCode, data);
83
- result = new WritableNativeMap();
84
- parseKYCResult(hyperKycResult);
85
98
  }
86
99
 
100
+ private void parseKYCResult(HyperKycResult hyperKycResult){
87
101
 
88
- }
102
+ String errorMessage="";
103
+ HyperKycData hyperKycData = hyperKycResult.getData();
104
+ WritableMap resultMap = new WritableNativeMap();
105
+ resultMap.putString("result", hyperKycResult.getStatus().toString());
106
+ resultMap.putString("errorMessage", errorMessage);
107
+ try {
108
+ if (hyperKycData != null) {
89
109
 
90
- private void parseKYCResult(HyperKycResult hyperKycResult) {
91
-
92
- HyperKycData hyperKycData = hyperKycResult.getData();
93
- WritableMap resultMap = new WritableNativeMap();
94
- try {
95
- if (hyperKycData != null) {
96
-
97
- gson = new Gson();
98
- String resultJSON = gson.toJson(hyperKycData);
99
- JSONObject result = new JSONObject(resultJSON);
100
- result.remove("config");
101
- resultMap = HyperkycSdkUtils.convertJsonToMap(result);
102
- }
103
-
104
- String type = "";
105
- String errorMessage = "";
106
- if (hyperKycResult instanceof HyperKycResult.Success) {
107
- type = "success";
108
- }
109
- if (hyperKycResult instanceof HyperKycResult.Failure) {
110
- type = "failure";
111
- errorMessage = ((HyperKycResult.Failure) hyperKycResult).getReason();
112
- }
113
- if (hyperKycResult instanceof HyperKycResult.Cancelled) {
114
- type = "cancelled";
115
- }
116
-
117
- resultMap.putString("result", type);
118
- resultMap.putString("errorMessage", errorMessage);
119
- callback.invoke(resultMap);
120
- } catch (Exception e) {
110
+ gson = new Gson();
111
+ String resultJSON = gson.toJson(hyperKycData);
112
+ JSONObject result = new JSONObject(resultJSON);
113
+ result.remove("config");
114
+ WritableMap hyperKycDataMap = RNHyperKYCUtils.convertJsonToMap(result);
115
+ resultMap.putMap("hyperKycData", hyperKycDataMap);
116
+ }
121
117
 
122
- }
123
118
 
124
- }
125
119
 
126
120
 
127
- private List<HyperKycFlow> processWorkFlow(ArrayList<Object> kycFlows) {
128
- List<HyperKycFlow> workflows = new ArrayList<HyperKycFlow>();
129
121
 
130
- for (Object flow : kycFlows) {
131
- if (flow instanceof String) {
132
- String flowStr = (String) flow;
133
- switch (flowStr) {
134
- case "document":
135
- workflows.add(HyperKycFlow.DOCUMENT);
136
122
 
137
- case "face":
138
- workflows.add(HyperKycFlow.FACE);
123
+ callback.invoke(resultMap);
124
+ }catch (Exception e){
139
125
 
140
126
  }
141
- }
127
+
142
128
  }
143
- return workflows;
144
- }
145
129
 
146
- @Override
147
- public void onNewIntent(Intent intent) {
148
130
 
149
- }
131
+ private List<HyperKycFlow> processWorkFlow(String workflowArray){
132
+ List<HyperKycFlow> workflows = new ArrayList<>();
133
+ try {
134
+ JSONArray kycFlows = null;
135
+
136
+ kycFlows = new JSONArray(workflowArray);
137
+
138
+ for(int i = 0; i < kycFlows.length(); i++){
139
+ JSONObject kycFlow = kycFlows.getJSONObject(i);
140
+ if(kycFlow.has("type")){
141
+ String flowStr = kycFlow.getString("type");
142
+ switch (flowStr) {
143
+ case "document":
144
+ String countryId = kycFlow.has(RNHyperKYCConstants.COUNTRY_ID) ? kycFlow.getString(RNHyperKYCConstants.COUNTRY_ID): null;
145
+ String documentId = kycFlow.has(RNHyperKYCConstants.DOCUMENT_ID) ? kycFlow.getString(RNHyperKYCConstants.DOCUMENT_ID): null;
146
+ boolean useForFaceMatch = kycFlow.has(RNHyperKYCConstants.USE_FOR_FACE_MATCH)? kycFlow.getBoolean(RNHyperKYCConstants.USE_FOR_FACE_MATCH): false;
147
+
148
+ workflows.add(new HyperKycFlow.Document(new DocFlowConfig(useForFaceMatch, countryId, documentId )));
149
+ case "face":
150
+ workflows.add(new HyperKycFlow.Face());
151
+
152
+ }
153
+ }
154
+ }
155
+ } catch (Exception e) {
156
+ e.printStackTrace();
157
+ }
158
+ return workflows;
159
+ }
160
+ @Override
161
+ public void onNewIntent(Intent intent) {
150
162
 
151
- }
163
+ }
164
+ }
@@ -23,7 +23,7 @@ public class HyperkycSdkPackage implements ReactPackage {
23
23
  return modules;
24
24
  }
25
25
 
26
- @Override
26
+
27
27
  public List<Class<? extends JavaScriptModule>> createJSModules() {
28
28
  return null;
29
29
  }
package/ios/.DS_Store CHANGED
Binary file
package/ios/HyperkycSdk.m CHANGED
@@ -2,7 +2,7 @@
2
2
  #import <Foundation/Foundation.h>
3
3
  #import <React/RCTUtils.h>
4
4
 
5
- @interface RCT_EXTERN_MODULE(HyperkycSdk, NSObject)
5
+ @interface RCT_EXTERN_MODULE(Hyperkyc, NSObject)
6
6
  RCT_EXTERN_METHOD(launch: (NSDictionary*)config callback:(RCTResponseSenderBlock)callback)
7
7
 
8
8
  + (BOOL) requiresMainQueueSetup {
@@ -3,171 +3,234 @@
3
3
  import Foundation
4
4
  import HyperKYC
5
5
 
6
- @objc(HyperkycSdk)
7
- class HyperkycSdk: NSObject {
8
- @objc static func requiresMainQueueSetup() -> Bool {return true}
9
-
10
- @objc
11
- func launchKYC(_config: NSDictionary, callback: @escaping RCTResponseSenderBlock) {
6
+ @objc(Hyperkyc)
7
+ class Hyperkyc: NSObject {
8
+ @objc static func requiresMainQueueSetup() -> Bool {return true}
9
+
10
+ @objc(launch:callback:)
11
+ func launch(_config: NSDictionary, callback: @escaping RCTResponseSenderBlock) {
12
12
  let appId = _config["appId"] as? String
13
13
  let transactionId = _config["transactionId"] as? String
14
+ let appKey = _config["appKey"] as? String
14
15
  let accessToken = _config["accessToken"] as? String
15
- let kycFlow = _config["workflow"] as? [String]
16
+ let kycFlow = _config["workflow"] as? String
17
+ let defaultCountryId = _config["defaultCountryId"] as? String ?? nil
16
18
 
17
- let workFlow = processKYCFlowStates(flows: kycFlow!)
19
+ let hyperKycWorkflows = processKYCFlowStates(flows: kycFlow!)
18
20
  DispatchQueue.main.async {
19
- let controller = RCTPresentedViewController()
20
-
21
- let hyperKYCConfig = HyperKycConfig(appId: appId!, accessToken: accessToken!, workFlow: workFlow,transactionId: transactionId!)
22
- HyperKyc.launch(controller!, hyperKycConfig: hyperKYCConfig) { hyperKycResult in
23
- // process the result hereDand send it back to JS
21
+ let controller = RCTPresentedViewController()
24
22
 
25
- callback([processHyperKycResult(hyperKycResult: hyperKycResult)])
26
-
23
+ if let accessTokenConfig = accessToken{
24
+ let hyperKYCConfig = HyperKycConfig(accessToken: accessTokenConfig, workFlow: hyperKycWorkflows, transactionId: transactionId!, defaultCountryId: defaultCountryId)
25
+ HyperKyc.launch(controller!, hyperKycConfig: hyperKYCConfig) { hyperKycResult in
26
+
27
+ }
28
+ }
29
+
30
+ if(appKey != nil && appId != nil){
31
+ let hyperKYCConfig = HyperKycConfig(appId: appId!, appKey: appKey!, workFlow: hyperKycWorkflows, transactionId: transactionId!, defaultCountryId: defaultCountryId)
32
+
33
+ HyperKyc.launch(controller!, hyperKycConfig: hyperKYCConfig) { hyperKycResult in
34
+
35
+ let result = self.processHyperKycResult(hyperKycResult: hyperKycResult)
36
+ callback( [result])
37
+ }
38
+ }
27
39
 
28
40
  }
29
- }
41
+ }
42
+
43
+
44
+
45
+
46
+ func processHyperKycResult(hyperKycResult: HyperKycResult) -> [String : Any] {
30
47
 
31
- func processHyperKycResult(hyperKycResult: HyperKycResult) -> [String: Any] {
32
- let encoder = JSONEncoder()
33
- encoder.outputFormatting = .prettyPrinted
34
- // MARK: Add result, kycData, errorMessage
35
- let resultEnum = hyperKycResult.result! as KYCResult
36
- var resultEnumString = ""
37
- var kycData = [
38
- "selectedCountry" : "",
39
- "selectedDocument" : "",
40
-
41
- ] as [String: Any]
42
- var errorMessage = ""
43
- // MARK: Add resultEnum
44
- resultEnumString = String(describing: resultEnum)
45
- // MARK: Add kycData
46
- if let hyperKycData = hyperKycResult.hyperKYCData {
47
- if let country = hyperKycData.selectedCountry {
48
- kycData["selectedCountry"] = country
49
- }
50
- if let document = hyperKycData.selectedDocument {
51
- kycData["selectedDocument"] = document
52
- }
53
- // MARK: Add docData to kycData
48
+ let resultEnum = hyperKycResult.result! as KYCResult
49
+ var resultEnumString = ""
50
+ var kycData = [
51
+ "selectedCountryId" : "",
52
+
53
+ ] as [String: Any]
54
+ var errorMessage = ""
55
+
56
+ resultEnumString = String(describing: resultEnum)
57
+
58
+ if let hyperKycData = hyperKycResult.hyperKYCData {
59
+ if let country = hyperKycData.selectedCountry {
60
+ kycData["selectedCountryId"] = country
61
+ }
62
+
63
+
64
+ var docResultList : [[String: Any]] = []
65
+ for docResult in hyperKycData.docResultList{
66
+
54
67
  var docDataList: [[String: Any]] = []
55
- for docData in hyperKycData.docDataList {
68
+
69
+ for docData in docResult.docDataList {
56
70
  var docDataDictionary = [
57
71
  "side" : docData.side,
58
72
  "docImagePath" : docData.docImagePath,
59
73
  "action" : docData.action,
60
- ]
61
- if let responseHeaders = docData.responseHeaders {
62
- do {
63
- let headersData = try JSONSerialization.data(withJSONObject: responseHeaders , options: JSONSerialization.WritingOptions.prettyPrinted)
64
- docDataDictionary["responseHeaders"] = String(data: headersData, encoding: String.Encoding.utf8)
65
- }catch let parseError{
66
- print("JSON Error DocData ResponseHeaders : \(parseError.localizedDescription)")
67
- }
68
- } else {
69
- docDataDictionary["responseHeaders"] = "{}"
74
+
75
+ ] as [String: Any]
76
+ if let responseHeaders = docData.responseHeaders {
77
+ docDataDictionary["responseHeaders"] = responseHeaders
70
78
  }
71
79
  if let responseResult = docData.responseResult {
72
- do {
73
- let docDataResponseResult = try encoder.encode(responseResult)
74
- docDataDictionary["responseResult"] = String(data: docDataResponseResult, encoding: .utf8)!
75
- } catch let parseError {
76
- print("JSON Error DocData ResponseResult : \(parseError.localizedDescription)")
77
- }
78
- } else {
79
- docDataDictionary["responseResult"] = "{}"
80
+ docDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: responseResult, faceDataResponseResult: nil, faceMatchDataResponseResult: nil )
80
81
  }
81
82
  docDataList.append(docDataDictionary as [String : Any])
82
83
  }
83
- kycData["docDataList"] = docDataList
84
- // MARK: Add faceData to kycData
85
- if let faceData = hyperKycData.faceData {
86
- var faceDataDictionary = [
87
- "croppedFaceImagePath" : faceData.croppedFaceImagePath,
88
- "fullFaceImagePath" : faceData.fullFaceImagePath,
89
- "videoPath" : faceData.videoPath,
90
- "action" : faceData.action,
91
- ]
92
- if let responseHeaders = faceData.responseHeaders {
93
- do {
94
- let headersData = try JSONSerialization.data(withJSONObject: responseHeaders , options: JSONSerialization.WritingOptions.prettyPrinted)
95
- faceDataDictionary["responseHeaders"] = String(data: headersData, encoding: String.Encoding.utf8)
96
- }catch let parseError{
97
- print("JSON Error FaceData ResponseHeaders : \(parseError.localizedDescription)")
98
- }
99
- } else {
100
- faceDataDictionary["responseHeaders"] = "{}"
101
- }
102
- if let responseResult = faceData.responseResult {
103
- do {
104
- let faceDataResponseResult = try encoder.encode(responseResult)
105
- faceDataDictionary["responseResult"] = String(data: faceDataResponseResult, encoding: .utf8)!
106
- } catch let parseError {
107
- print("JSON Error FaceData ResponseResult : \(parseError.localizedDescription)")
108
- }
109
- } else {
110
- faceDataDictionary["responseResult"] = "{}"
111
- }
112
- kycData["faceData"] = faceDataDictionary
84
+ var docResultDictionary = [
85
+ "tag" : docResult.tag,
86
+ "documentId": docResult.documentId,
87
+ "docDataList": docDataList
88
+ ] as [String : Any]
89
+
90
+ docResultList.append(docResultDictionary as [String: Any])
91
+ }
92
+
93
+ kycData["docResultList"] = docResultList
94
+
95
+ // Process face data
96
+ if let faceData = hyperKycData.faceData {
97
+ var faceDataDictionary = [
98
+ "croppedFaceImagePath" : faceData.croppedFaceImagePath,
99
+ "fullFaceImagePath" : faceData.fullFaceImagePath,
100
+ "videoPath" : faceData.videoPath,
101
+ "action" : faceData.action,
102
+ ] as [String:Any]
103
+ if let responseHeaders = faceData.responseHeaders {
104
+ faceDataDictionary["responseHeaders"] = responseHeaders
113
105
  }
114
- // MARK: Add faceMatchData to kycData
115
- if let faceMatchData = hyperKycData.faceMatchData {
106
+ if let responseResult = faceData.responseResult {
107
+ faceDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: nil, faceDataResponseResult: responseResult, faceMatchDataResponseResult: nil )
108
+ }
109
+
110
+
111
+ kycData["faceData"] = faceDataDictionary
112
+
113
+ }
114
+
115
+ //Process face match data
116
+ var faceMatchDataResultList : [[String: Any]] = []
117
+ for faceMatchDataResult in hyperKycData.faceMatchDataResultList{
118
+
116
119
  var faceMatchDataDictionary = [
117
- "action" : faceMatchData.action,
118
- ]
119
- if let responseHeaders = faceMatchData.responseHeaders {
120
- do {
121
- let headersData = try JSONSerialization.data(withJSONObject: responseHeaders , options: JSONSerialization.WritingOptions.prettyPrinted)
122
- faceMatchDataDictionary["responseHeaders"] = String(data: headersData, encoding: String.Encoding.utf8)
123
- }catch let parseError{
124
- print("JSON Error FaceMatchData ResponseHeaders : \(parseError.localizedDescription)")
125
- }
126
- } else {
127
- faceMatchDataDictionary["responseHeaders"] = "{}"
120
+ "action" : faceMatchDataResult.facematchData.action,
121
+ ] as [String:Any]
122
+ if let responseHeaders = faceMatchDataResult.facematchData.responseHeaders {
123
+ faceMatchDataDictionary["responseHeaders"] = responseHeaders
128
124
  }
129
- if let responseResult = faceMatchData.responseResult {
130
- do {
131
- let faceMatchDataResponseResult = try encoder.encode(responseResult)
132
- faceMatchDataDictionary["responseResult"] = String(data: faceMatchDataResponseResult, encoding: .utf8)!
133
- } catch let parseError {
134
- print("JSON Error FaceMatchData ResponseResult : \(parseError.localizedDescription)")
135
- }
136
- } else {
137
- faceMatchDataDictionary["responseResult"] = "{}"
125
+ if let responseResult = faceMatchDataResult.facematchData.responseResult {
126
+ faceMatchDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: nil, faceDataResponseResult: nil, faceMatchDataResponseResult: responseResult)
138
127
  }
139
- kycData["faceMatchData"] = faceMatchDataDictionary
128
+ var faceMatchResultDictionary = [
129
+ "tag": faceMatchDataResult.tag,
130
+ "documentId":faceMatchDataResult.documentId,
131
+ "faceMatchData":faceMatchDataDictionary
132
+ ] as [String: Any]
133
+ faceMatchDataResultList.append(faceMatchResultDictionary)
140
134
  }
141
- }
142
- // MARK: Add errorMessage
143
- if let errorMsg = hyperKycResult.errorMessage {
144
- errorMessage = errorMsg
145
- }
146
- // MARK: Create the final result map which will include resultEnum, kycData and errorMessage
147
- let resultMap = [
148
- "result" : resultEnumString,
149
- "hyperKYCData" : kycData,
150
- "errorMessage" : errorMessage,
151
- ] as [String : Any]
152
- return resultMap
153
- }
135
+
136
+ kycData["faceMatchDataResultList"] = faceMatchDataResultList
137
+
138
+ if let errorMsg = hyperKycResult.errorMessage {
139
+ errorMessage = errorMsg
140
+ }
141
+
142
+ let resultMap = [
143
+ "result" : resultEnumString,
144
+ "hyperKycData" : kycData,
145
+ "errorMessage" : errorMessage,
146
+ ] as [String : Any]
147
+ return resultMap
148
+
149
+
154
150
 
155
- func processKYCFlowStates(flows : [String]) -> [HyperKycFlow]{
156
- var workflows = [HyperKycFlow]()
157
- flows.forEach { flow in
158
- switch (flow){
159
- case "document":
160
- workflows.append(.document)
161
- case "face":
162
- workflows.append(.face)
163
- default:
164
- break
151
+ }
152
+ return [:]
153
+ }
154
+
155
+
156
+ //
157
+ func getResponseResultJsonString(docDataResponseResult: DocCaptureApiDetail?, faceDataResponseResult: FaceCaptureApiDetail?, faceMatchDataResponseResult: FaceMatchApiDetail?) -> [String:Any] {
158
+ let encoder = JSONEncoder()
159
+ encoder.outputFormatting = .prettyPrinted
160
+
161
+ var responseResultJsonString:String = "{}"
162
+ do {
163
+ if let responseResult = docDataResponseResult {
164
+ let responseResultData = try encoder.encode(responseResult)
165
+ responseResultJsonString = String(data: responseResultData, encoding: .utf8) ?? "{}"
166
+ if let data = responseResultJsonString.data(using: .utf8) {
167
+ return try JSONSerialization.jsonObject(with: data, options: []) as? [String:Any] ?? [:]
168
+ }
165
169
 
166
-
170
+
171
+ } else if let responseResult = faceDataResponseResult {
172
+ let responseResultData = try encoder.encode(responseResult)
173
+ responseResultJsonString = String(data: responseResultData, encoding: .utf8) ?? "{}"
174
+ if let data = responseResultJsonString.data(using: .utf8) {
175
+ return try JSONSerialization.jsonObject(with: data, options: []) as? [String:Any] ?? [:]
167
176
  }
177
+ } else if let responseResult = faceMatchDataResponseResult {
178
+ let responseResultData = try encoder.encode(responseResult)
179
+ responseResultJsonString = String(data: responseResultData, encoding: .utf8) ?? "{}"
180
+
181
+ if let data = responseResultJsonString.data(using: .utf8) {
182
+ return try JSONSerialization.jsonObject(with: data, options: []) as? [String:Any] ?? [:]
183
+ }
184
+ } else {
185
+ return [:]
168
186
  }
169
- return workflows
170
- }
187
+ } catch let parseError {
188
+ print("JSON Error DocData ResponseResult : \(parseError.localizedDescription)")
189
+ return [:]
171
190
  }
191
+ return [:]
192
+ }
193
+
194
+
195
+
196
+ func processKYCFlowStates(flows : String) -> [HyperKycFlow] {
197
+ var hyperKycFlows = [HyperKycFlow]()
198
+ let workflows = convertToDictionary(json: flows)
199
+
200
+ workflows?.forEach({ (value: Any) in
201
+ let valueObj = (value as! [String:Any])
202
+ switch(valueObj["type"] as! String){
203
+ case "document":
204
+ let useForFaceMatch = valueObj["useForFaceMatch"] as? Bool ?? false
205
+ let countryId = valueObj["countryId"] as? String ?? nil
206
+ let documentId = valueObj["documentId"] as? String ?? nil
207
+ hyperKycFlows.append(HyperKycFlow.document(config: DocFlowConfig(useForFaceMatch: useForFaceMatch, countryId: countryId, documentId: documentId)))
208
+ case "face":
209
+ hyperKycFlows.append(HyperKycFlow.face())
210
+ default:
211
+ print("Case not handled")
212
+ }
213
+ })
214
+
215
+ return hyperKycFlows
172
216
 
173
217
  }
218
+
219
+ func convertToDictionary(json: String) -> [Any]? {
220
+ if let data = json.data(using: .utf8) {
221
+ do {
222
+ return try JSONSerialization.jsonObject(with: data, options: []) as? [Any]
223
+ } catch {
224
+ print(error.localizedDescription)
225
+ }
226
+ }
227
+ return nil
228
+ }
229
+
230
+ }
231
+
232
+
233
+
234
+
235
+
236
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-hyperkyc-sdk",
3
- "version": "0.1.2-alpha",
3
+ "version": "0.1.6-alpha1",
4
4
  "description": "React Native wrapper for HyperKYC SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",