react-native-hyperkyc-sdk 0.1.5-alpha → 0.1.6-alpha3
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.
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/reactnativehyperkycsdk/HyperkycConstants.java +8 -0
- package/android/src/main/java/com/reactnativehyperkycsdk/HyperkycSdkModule.java +85 -73
- package/android/src/main/java/com/reactnativehyperkycsdk/HyperkycSdkPackage.java +0 -1
- package/ios/HyperkycSdk.m +1 -1
- package/ios/HyperkycSdk.swift +189 -138
- package/package.json +1 -1
package/android/build.gradle
CHANGED
|
@@ -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.
|
|
60
|
+
implementation('co.hyperverge:hyperkyc:0.0.2-alpha02@aar', {
|
|
61
61
|
transitive = true
|
|
62
62
|
})
|
|
63
63
|
}
|
|
@@ -3,7 +3,7 @@ package com.reactnativehyperkycsdk;
|
|
|
3
3
|
|
|
4
4
|
import android.app.Activity;
|
|
5
5
|
import android.content.Intent;
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
import com.facebook.react.ReactActivity;
|
|
@@ -25,7 +25,8 @@ import java.util.ArrayList;
|
|
|
25
25
|
import java.util.List;
|
|
26
26
|
|
|
27
27
|
|
|
28
|
-
import co.hyperverge.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 = "
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
ReadableArray array = kycConfig.getArray("workflow");
|
|
62
|
+
@ReactMethod
|
|
63
|
+
public void launch(ReadableMap kycConfig, Callback resultCallback ){
|
|
64
|
+
callback = resultCallback;
|
|
65
65
|
|
|
66
|
-
|
|
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
|
-
|
|
69
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
138
|
-
|
|
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(
|
|
5
|
+
@interface RCT_EXTERN_MODULE(Hyperkyc, NSObject)
|
|
6
6
|
RCT_EXTERN_METHOD(launch: (NSDictionary*)config callback:(RCTResponseSenderBlock)callback)
|
|
7
7
|
|
|
8
8
|
+ (BOOL) requiresMainQueueSetup {
|
package/ios/HyperkycSdk.swift
CHANGED
|
@@ -3,169 +3,220 @@
|
|
|
3
3
|
import Foundation
|
|
4
4
|
import HyperKYC
|
|
5
5
|
|
|
6
|
-
@objc(
|
|
7
|
-
class
|
|
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?
|
|
16
|
+
let kycFlow = _config["workflow"] as? String
|
|
17
|
+
let defaultCountryId = _config["defaultCountryId"] as? String ?? nil
|
|
16
18
|
|
|
17
|
-
let
|
|
19
|
+
let hyperKycWorkflows = processKYCFlowStates(flows: kycFlow!)
|
|
18
20
|
DispatchQueue.main.async {
|
|
19
|
-
|
|
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()
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
func processHyperKycResult(hyperKycResult: HyperKycResult) -> [String: Any] {
|
|
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
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
] as [String: Any]
|
|
40
|
-
var errorMessage = ""
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if(appKey != nil && appId != nil){
|
|
31
|
+
let hyperKYCConfig = HyperKycConfig(appId: appId!, appKey: appKey!, workFlow: hyperKycWorkflows, transactionId: transactionId!, defaultCountryId: defaultCountryId)
|
|
41
32
|
|
|
42
|
-
|
|
33
|
+
HyperKyc.launch(controller!, hyperKycConfig: hyperKYCConfig) { hyperKycResult in
|
|
43
34
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
let result = self.processHyperKycResult(hyperKycResult: hyperKycResult)
|
|
36
|
+
callback( [result])
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
}
|
|
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{
|
|
51
66
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
67
|
+
var docDataList: [[String: Any]] = []
|
|
68
|
+
|
|
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
|
|
84
78
|
}
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|
79
|
+
if let responseResult = docData.responseResult {
|
|
80
|
+
docDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: responseResult, faceDataResponseResult: nil, faceMatchDataResponseResult: nil )
|
|
98
81
|
}
|
|
82
|
+
docDataList.append(docDataDictionary as [String : Any])
|
|
99
83
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
let resultMap = [
|
|
106
|
-
"result" : resultEnumString,
|
|
107
|
-
"hyperKYCData" : kycData,
|
|
108
|
-
"errorMessage" : errorMessage,
|
|
84
|
+
var docResultDictionary = [
|
|
85
|
+
"tag" : docResult.tag,
|
|
86
|
+
"documentId": docResult.documentId,
|
|
87
|
+
"docDataList": docDataList
|
|
109
88
|
] as [String : Any]
|
|
110
|
-
|
|
89
|
+
|
|
90
|
+
docResultList.append(docResultDictionary as [String: Any])
|
|
111
91
|
}
|
|
112
92
|
|
|
113
|
-
|
|
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
|
-
}
|
|
123
|
-
}
|
|
93
|
+
kycData["docResultList"] = docResultList
|
|
124
94
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
return responseResultJsonString
|
|
144
|
-
}
|
|
145
|
-
} catch let parseError {
|
|
146
|
-
print("JSON Error DocData ResponseResult : \(parseError.localizedDescription)")
|
|
147
|
-
return responseResultJsonString
|
|
148
|
-
}
|
|
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
|
+
|
|
149
113
|
}
|
|
150
|
-
|
|
151
|
-
|
|
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
|
|
124
|
+
}
|
|
125
|
+
if let responseResult = faceMatchDataResult.facematchData.responseResult {
|
|
126
|
+
faceMatchDataDictionary["responseResult"] = getResponseResultJsonString(docDataResponseResult: nil, faceDataResponseResult: nil, faceMatchDataResponseResult: responseResult)
|
|
127
|
+
}
|
|
128
|
+
var faceMatchResultDictionary = [
|
|
129
|
+
"tag": faceMatchDataResult.tag,
|
|
130
|
+
"documentId":faceMatchDataResult.documentId,
|
|
131
|
+
"faceMatchData":faceMatchDataDictionary
|
|
132
|
+
] as [String: Any]
|
|
133
|
+
faceMatchDataResultList.append(faceMatchResultDictionary)
|
|
134
|
+
}
|
|
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
|
+
|
|
152
150
|
|
|
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
151
|
}
|
|
167
|
-
return
|
|
152
|
+
return [:]
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
//
|
|
157
|
+
func getResponseResultJsonString(docDataResponseResult: DocCaptureApiDetail?, faceDataResponseResult: FaceCaptureApiDetail?, faceMatchDataResponseResult: FaceMatchApiDetail?) -> [String:Any] {
|
|
158
|
+
let encoder = JSONEncoder()
|
|
159
|
+
|
|
160
|
+
do {
|
|
161
|
+
if let responseResult = docDataResponseResult {
|
|
162
|
+
let responseResultData = try encoder.encode(responseResult)
|
|
163
|
+
return try JSONSerialization.jsonObject(with: responseResultData, options: []) as? [String:Any] ?? [:]
|
|
164
|
+
} else if let responseResult = faceDataResponseResult {
|
|
165
|
+
let responseResultData = try encoder.encode(responseResult)
|
|
166
|
+
return try JSONSerialization.jsonObject(with: responseResultData, options: []) as? [String:Any] ?? [:]
|
|
167
|
+
} else if let responseResult = faceMatchDataResponseResult {
|
|
168
|
+
let responseResultData = try encoder.encode(responseResult)
|
|
169
|
+
return try JSONSerialization.jsonObject(with: responseResultData, options: []) as? [String:Any] ?? [:]
|
|
170
|
+
} else {
|
|
171
|
+
return [:]
|
|
168
172
|
}
|
|
173
|
+
} catch let parseError {
|
|
174
|
+
print("JSON Error DocData ResponseResult : \(parseError.localizedDescription)")
|
|
175
|
+
return [:]
|
|
176
|
+
}
|
|
177
|
+
return [:]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
func processKYCFlowStates(flows : String) -> [HyperKycFlow] {
|
|
183
|
+
var hyperKycFlows = [HyperKycFlow]()
|
|
184
|
+
let workflows = convertToDictionary(json: flows)
|
|
169
185
|
|
|
186
|
+
workflows?.forEach({ (value: Any) in
|
|
187
|
+
let valueObj = (value as! [String:Any])
|
|
188
|
+
switch(valueObj["type"] as! String){
|
|
189
|
+
case "document":
|
|
190
|
+
let useForFaceMatch = valueObj["useForFaceMatch"] as? Bool ?? false
|
|
191
|
+
let countryId = valueObj["countryId"] as? String ?? nil
|
|
192
|
+
let documentId = valueObj["documentId"] as? String ?? nil
|
|
193
|
+
hyperKycFlows.append(HyperKycFlow.document(config: DocFlowConfig(useForFaceMatch: useForFaceMatch, countryId: countryId, documentId: documentId)))
|
|
194
|
+
case "face":
|
|
195
|
+
hyperKycFlows.append(HyperKycFlow.face())
|
|
196
|
+
default:
|
|
197
|
+
print("Case not handled")
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
return hyperKycFlows
|
|
170
202
|
|
|
171
203
|
}
|
|
204
|
+
|
|
205
|
+
func convertToDictionary(json: String) -> [Any]? {
|
|
206
|
+
if let data = json.data(using: .utf8) {
|
|
207
|
+
do {
|
|
208
|
+
return try JSONSerialization.jsonObject(with: data, options: []) as? [Any]
|
|
209
|
+
} catch {
|
|
210
|
+
print(error.localizedDescription)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return nil
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|