react-native-hyperkyc-sdk 0.1.5-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;
@@ -34,7 +35,7 @@ import co.hyperverge.hyperkyc.data.models.HyperKycResult;
34
35
 
35
36
 
36
37
  public class HyperkycSdkModule extends ReactContextBaseJavaModule implements ActivityEventListener {
37
- public static final String NAME = "HyperkycSdk";
38
+ public static final String NAME = "Hyperkyc";
38
39
 
39
40
  private final ReactApplicationContext reactContext;
40
41
 
@@ -58,95 +59,106 @@ public class HyperkycSdkModule extends ReactContextBaseJavaModule implements Act
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
-
149
- }
150
130
 
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) {
151
162
 
152
- }
163
+ }
164
+ }
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,169 +3,234 @@
3
3
  import Foundation
4
4
  import HyperKYC
5
5
 
6
- @objc(HyperkycSdk)
7
- class HyperkycSdk: NSObject {
6
+ @objc(Hyperkyc)
7
+ class Hyperkyc: NSObject {
8
8
  @objc static func requiresMainQueueSetup() -> Bool {return true}
9
-
9
+
10
10
  @objc(launch:callback:)
11
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
24
- callback( [self.processHyperKycResult(hyperKycResult: hyperKycResult)])
21
+ let controller = RCTPresentedViewController()
22
+
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
+ }
25
39
 
26
40
  }
27
- }
28
-
29
41
  }
30
-
31
- func processHyperKycResult(hyperKycResult: HyperKycResult) -> [String: Any] {
32
-
33
- let resultEnum = hyperKycResult.result! as KYCResult
34
- var resultEnumString = ""
35
- var kycData = [
36
- "selectedCountry" : "",
37
- "selectedDocument" : "",
38
-
39
- ] as [String: Any]
40
- var errorMessage = ""
42
+
43
+
44
+
45
+
46
+ func processHyperKycResult(hyperKycResult: HyperKycResult) -> [String : Any] {
47
+
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{
41
66
 
42
- resultEnumString = String(describing: resultEnum)
67
+ var docDataList: [[String: Any]] = []
43
68
 
44
- if let hyperKycData = hyperKycResult.hyperKYCData {
45
- if let country = hyperKycData.selectedCountry {
46
- kycData["selectedCountry"] = country
69
+ for docData in docResult.docDataList {
70
+ var docDataDictionary = [
71
+ "side" : docData.side,
72
+ "docImagePath" : docData.docImagePath,
73
+ "action" : docData.action,
74
+
75
+ ] as [String: Any]
76
+ if let responseHeaders = docData.responseHeaders {
77
+ docDataDictionary["responseHeaders"] = responseHeaders
47
78
  }
48
- if let document = hyperKycData.selectedDocument {
49
- kycData["selectedDocument"] = document
79
+ if let responseResult = docData.responseResult {
80
+ docDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: responseResult, faceDataResponseResult: nil, faceMatchDataResponseResult: nil )
50
81
  }
82
+ docDataList.append(docDataDictionary as [String : Any])
83
+ }
84
+ var docResultDictionary = [
85
+ "tag" : docResult.tag,
86
+ "documentId": docResult.documentId,
87
+ "docDataList": docDataList
88
+ ] as [String : Any]
51
89
 
52
- var docDataList: [[String: Any]] = []
53
- for docData in hyperKycData.docDataList {
54
- var docDataDictionary = [
55
- "side" : docData.side,
56
- "docImagePath" : docData.docImagePath,
57
- "action" : docData.action,
58
- ]
59
- if let responseHeaders = docData.responseHeaders {
60
- docDataDictionary["responseHeaders"] = getResponseHeadersJsonString(responseHeaders: responseHeaders)
61
- }
62
- if let responseResult = docData.responseResult {
63
- docDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: responseResult, faceDataResponseResult: nil, faceMatchDataResponseResult: nil )
64
- }
65
- docDataList.append(docDataDictionary as [String : Any])
66
- }
67
- kycData["docDataList"] = docDataList
68
- // MARK: Add faceData to kycData
69
- if let faceData = hyperKycData.faceData {
70
- var faceDataDictionary = [
71
- "croppedFaceImagePath" : faceData.croppedFaceImagePath,
72
- "fullFaceImagePath" : faceData.fullFaceImagePath,
73
- "videoPath" : faceData.videoPath,
74
- "action" : faceData.action,
75
- ]
76
- if let responseHeaders = faceData.responseHeaders {
77
- faceDataDictionary["responseHeaders"] = getResponseHeadersJsonString(responseHeaders: responseHeaders)
78
- }
79
- if let responseResult = faceData.responseResult {
80
- faceDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: nil, faceDataResponseResult: responseResult, faceMatchDataResponseResult: nil )
81
- }
82
-
83
- kycData["faceData"] = faceDataDictionary
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
105
+ }
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
+
119
+ var faceMatchDataDictionary = [
120
+ "action" : faceMatchDataResult.facematchData.action,
121
+ ] as [String:Any]
122
+ if let responseHeaders = faceMatchDataResult.facematchData.responseHeaders {
123
+ faceMatchDataDictionary["responseHeaders"] = responseHeaders
84
124
  }
85
-
86
- if let faceMatchData = hyperKycData.faceMatchData {
87
- var faceMatchDataDictionary = [
88
- "action" : faceMatchData.action,
89
- ]
90
- if let responseHeaders = faceMatchData.responseHeaders {
91
- faceMatchDataDictionary["responseHeaders"] = getResponseHeadersJsonString(responseHeaders: responseHeaders)
92
- }
93
- if let responseResult = faceMatchData.responseResult {
94
- faceMatchDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: nil, faceDataResponseResult: nil, faceMatchDataResponseResult: responseResult)
95
- }
96
-
97
- kycData["faceMatchData"] = faceMatchDataDictionary
125
+ if let responseResult = faceMatchDataResult.facematchData.responseResult {
126
+ faceMatchDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: nil, faceDataResponseResult: nil, faceMatchDataResponseResult: responseResult)
98
127
  }
128
+ var faceMatchResultDictionary = [
129
+ "tag": faceMatchDataResult.tag,
130
+ "documentId":faceMatchDataResult.documentId,
131
+ "faceMatchData":faceMatchDataDictionary
132
+ ] as [String: Any]
133
+ faceMatchDataResultList.append(faceMatchResultDictionary)
99
134
  }
100
-
101
- if let errorMsg = hyperKycResult.errorMessage {
102
- errorMessage = errorMsg
103
- }
104
-
105
- let resultMap = [
106
- "result" : resultEnumString,
107
- "hyperKYCData" : kycData,
108
- "errorMessage" : errorMessage,
109
- ] as [String : Any]
110
- return resultMap
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
+
150
+
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] ?? [:]
111
168
  }
169
+
112
170
 
113
- func getResponseHeadersJsonString(responseHeaders: [String: String]) -> String {
114
- var responseHeadersJsonString :String = "{}"
115
- do {
116
- let headersData = try JSONSerialization.data(withJSONObject: responseHeaders , options: JSONSerialization.WritingOptions.prettyPrinted)
117
- responseHeadersJsonString = String(data: headersData, encoding: String.Encoding.utf8) ?? "{}"
118
- return responseHeadersJsonString
119
- } catch let parseError{
120
- print("JSON Error Parsing ResponseHeaders : \(parseError.localizedDescription)")
121
- return responseHeadersJsonString
122
- }
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] ?? [:]
123
176
  }
177
+ } else if let responseResult = faceMatchDataResponseResult {
178
+ let responseResultData = try encoder.encode(responseResult)
179
+ responseResultJsonString = String(data: responseResultData, encoding: .utf8) ?? "{}"
124
180
 
125
- func getResponseResultJsonString(docDataResponseResult: DocCaptureApiDetail?, faceDataResponseResult: FaceCaptureApiDetail?, faceMatchDataResponseResult: FaceMatchApiDetail?) -> String {
126
- let encoder = JSONEncoder()
127
- encoder.outputFormatting = .prettyPrinted
128
- var responseResultJsonString:String = "{}"
129
- do {
130
- if let responseResult = docDataResponseResult {
131
- let responseResultData = try encoder.encode(responseResult)
132
- responseResultJsonString = String(data: responseResultData, encoding: .utf8) ?? "{}"
133
- return responseResultJsonString
134
- } else if let responseResult = faceDataResponseResult {
135
- let responseResultData = try encoder.encode(responseResult)
136
- responseResultJsonString = String(data: responseResultData, encoding: .utf8) ?? "{}"
137
- return responseResultJsonString
138
- } else if let responseResult = faceMatchDataResponseResult {
139
- let responseResultData = try encoder.encode(responseResult)
140
- responseResultJsonString = String(data: responseResultData, encoding: .utf8) ?? "{}"
141
- return responseResultJsonString
142
- } else {
143
- return responseResultJsonString
144
- }
145
- } catch let parseError {
146
- print("JSON Error DocData ResponseResult : \(parseError.localizedDescription)")
147
- return responseResultJsonString
148
- }
181
+ if let data = responseResultJsonString.data(using: .utf8) {
182
+ return try JSONSerialization.jsonObject(with: data, options: []) as? [String:Any] ?? [:]
149
183
  }
184
+ } else {
185
+ return [:]
186
+ }
187
+ } catch let parseError {
188
+ print("JSON Error DocData ResponseResult : \(parseError.localizedDescription)")
189
+ return [:]
190
+ }
191
+ return [:]
192
+ }
150
193
 
151
194
 
152
-
153
- func processKYCFlowStates(flows : [String]) -> [HyperKycFlow]{
154
- var workflows = [HyperKycFlow]()
155
- flows.forEach { flow in
156
- switch (flow){
157
- case "document":
158
- workflows.append(.document)
159
- case "face":
160
- workflows.append(.face)
161
- default:
162
- break
163
-
164
-
165
- }
166
- }
167
- return workflows
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")
168
212
  }
213
+ })
169
214
 
215
+ return hyperKycFlows
170
216
 
171
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.5-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",