uploadSessionSelfie method

Future<RemoteResponse<UploadDTO>> uploadSessionSelfie({
  1. required String sessionId,
  2. required String accessToken,
  3. String? selfieDocUri,
  4. String? selfieDocBase64,
  5. Map? metadata,
})

Implementation

Future<RemoteResponse<UploadDTO>> uploadSessionSelfie({
  required String sessionId,
  required String accessToken,
  String? selfieDocUri,
  String? selfieDocBase64,
  Map? metadata,
}) async {
  try {
    Dio dio = getDio(accessToken);

    final body = {
      if(selfieDocUri!=null)"selfie_uri": selfieDocUri,
      if(selfieDocBase64!=null)"selfie_base64": selfieDocBase64,
      "metadata": metadata ?? {"confidence_level": "99.12"},
    };
    log('POST: ${dio.options.baseUrl}${uploadSelfiePath(sessionId)}, '
        'body: $body'
    );
    final response = await dio.post<Map<String, dynamic>>(
      uploadSelfiePath(sessionId),
      data: body,
    );
    final Map<String, dynamic>? data = response.data;
    log('STATUS: ${response.statusCode}, DATA: $data');
    if (response.statusCode == 200) {
      final Map<String, dynamic> payload =
      data?['payload'] as Map<String, dynamic>;
      if (isSuccessResponse(data)) {
        return RemoteResponse.withNewData(
          UploadDTO.fromJson(payload),
        );
      } else {
        throw EkycApiException.fromJson(payload);
      }
    } else {
      throw EkycApiException.fromJson(response.data!);
    }
  } on DioError catch (e) {
    return handleDioError(e);
  }
}