checkSession method

Future<RemoteResponse<SessionResultDTO>> checkSession({
  1. required String sessionId,
  2. required String accessToken,
})

Implementation

Future<RemoteResponse<SessionResultDTO>> checkSession({
  required String sessionId,
  required String accessToken,
}) async {
  try {
    Dio dio = getDio(accessToken);

    bool isContinueChecking = true;
    while(isContinueChecking){
      log('POST: ${dio.options.baseUrl}${checkSessionPath(sessionId)}, header: ${dio.options.headers}');
      final response = await dio.get<Map<String, dynamic>>(
        checkSessionPath(sessionId),
      );
      final Map<String, dynamic>? data = response.data;
      log('DATA: $data');
      if (response.statusCode == 200) {
        final Map<String, dynamic> payload =
        data?['payload'] as Map<String, dynamic>;
        if (payload['status']=='review') {
          isContinueChecking = false;
          final Map<String, dynamic> identityDocMap =
          payload['identity_document'] as Map<String, dynamic>;
          final Map<String, dynamic> systemResultMap =
          identityDocMap['system_result'] as Map<String, dynamic>;

          Map<String, dynamic> sessionResultMap = {
            'country': systemResultMap['country'],
            'id_number': systemResultMap['id_number'],
            'name': systemResultMap['name'],
            'doc_type': systemResultMap['doc_type'],
            'date_of_birth': systemResultMap['id_result']['date_of_birth'],
            'filepaths': systemResultMap['filepaths'],
            'address': systemResultMap['id_result']['address'],
          };

          return RemoteResponse.withNewData(
            SessionResultDTO.fromJson(sessionResultMap),
          );
        } else if (payload['status']=='approved') {
          isContinueChecking = false;
          return RemoteResponse.withNewData(
            SessionResultDTO.fromJson(payload),
          );
        } else {
          await Future.delayed(const Duration(seconds: 5));
          continue;
        }
      } else {
        throw EkycApiException.fromJson(response.data!);
      }
    }

    throw DioError;
  } on DioError catch (e) {
    return handleDioError(e);
  }
}