getUserQrCode method

Future<AnybillResult<UserQrCodeDto>> getUserQrCode(
  1. {int requestCount = 2}
)

Retrieve an UserQrCodeDto from the current authenticated user. Use this qr code data to display a qr code which can be scanned by the POS.

  • requestCount can be used to determine the number of repeated requests before a failure is returned if the call is not successful.

Returns a AnybillResult.success that contains the status code and the qr code data in its data parameter.

Throws a AnybillResult.failure with the specified information gained from the API. This could be a DioException when a generic errors occurred or a different Exception for critical errors that couldn't be caught.

Implementation

Future<AnybillResult<UserQrCodeDto>> getUserQrCode({
  int requestCount = 2,
}) async {
  AnybillLogger.info("Tried to get user qr code data");
  try {
    final token = await _tokenProvider.getToken();
    if (token == null) {
      return AnybillResult.failure(
        type: AnybillErrorType.noUserError,
      );
    }

    final userQrCode = await _userService.getUserSelfQr(token: token);

    await _userStore.putQrCodeData(userQrCode);

    return AnybillResult.success(
      HttpStatus.ok,
      data: userQrCode,
    );
  }
// ----------------------------------------------------------------
  catch (error, stacktrace) {
    return ErrorHandler.handleError(
      error,
      stacktrace,
      requestCount: requestCount,
      request: () => getUserQrCode(requestCount: requestCount - 1),
      event: "getUserQrCode",
      library: runtimeType.toString(),
    );
  }
}