submitKycRequest function
Implementation
Future<Either<VerificationFailure, Map<String, dynamic>>> submitKycRequest({
required Map<String, dynamic> userData,
required Map<String, dynamic> idData,
required String verificationSessionId,
required String accessToken,
required String apiKey,
}) async {
try {
final String timeStamp = getCurrentDateTimeInISO8601();
var requestBody = KycRequestDto().toJson(
userData,
idData,
verificationSessionId,
timeStamp,
);
var tempBody = requestBody;
tempBody["timestamp"] = timeStamp;
final signature = createJWT(tempBody, jwtSecret);
final http.Response response = await http.post(
Uri.parse('${apiBaseUrl}request/'),
headers: <String, String>{
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-api-key': apiKey,
'x-signature': signature,
'x-timestamp': timeStamp,
'Authorization': 'Bearer $accessToken',
},
body: jsonEncode(requestBody),
);
var result = jsonDecode(response.body);
if (kDebugMode) {
print(result);
}
if (!result.containsKey('error')) {
var data = await KycRequestDto().fromJson(
userData,
idData,
result['frontImage'],
result['backImage'],
result['sideImage'],
result['faceImage'],
apiKey,
verificationSessionId,
accessToken);
return right(data);
} else {
if (kDebugMode) {
print(result);
}
return left(VerificationFailure.serverError(result['error']));
}
} catch (e) {
if (kDebugMode) {
print(e);
}
return left(VerificationFailure.serverError(e.toString()));
}
}