uploadSessionDoc method

Future<RemoteResponse<UploadDTO>> uploadSessionDoc({
  1. required DocTypes docTypes,
  2. required String issuingCountry,
  3. required String sessionId,
  4. required String accessToken,
  5. String? frontDocUri,
  6. String? backDocUri,
  7. String? frontDocBase64,
  8. String? backDocBase64,
})

CALL API

Implementation

/// CALL API
Future<RemoteResponse<UploadDTO>> uploadSessionDoc({
  required DocTypes docTypes,
  required String issuingCountry,
  required String sessionId,
  required String accessToken,
  String? frontDocUri,
  String? backDocUri,
  String? frontDocBase64,
  String? backDocBase64,
}) async {
  try {
    Dio dio = getDio(accessToken);

    debugPrint(frontDocBase64??'');
    final body = {
      "doc_type": docTypes.value,
      "issuing_country": issuingCountry,
      if(frontDocUri!=null)"front_doc_uri": frontDocUri,
      if(backDocUri!=null)"back_doc_uri": backDocUri,
      if(frontDocBase64!=null)"front_doc_base64": frontDocBase64,
      if(backDocBase64!=null)"back_doc_base64": backDocBase64,
    };
    print('POST: ${dio.options.baseUrl}${uploadDocPath(sessionId)}, body: $body');
    final response = await dio.post<Map<String, dynamic>>(
      uploadDocPath(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);
  }
}