initTransactionSession method

Future<ResponseDto<TransactionSessionResponseDto>> initTransactionSession(
  1. int customerId,
  2. String successUrl,
  3. String failureUrl,
  4. double paidAmount,
  5. String transactionReference,
  6. String authToken,
)

Implementation

Future<ResponseDto<TransactionSessionResponseDto>> initTransactionSession(
    int customerId, String successUrl, String failureUrl,
    double paidAmount, String transactionReference, String authToken) async {
  final InitTransactionSessionRequestDto sessionDto = InitTransactionSessionRequestDto(
      customerId: customerId,
      successUrl: successUrl,
      failureUrl: failureUrl,
      paidAmount: paidAmount,
      transactionReference: transactionReference);

  final RequestDto<InitTransactionSessionRequestDto> requestDto = RequestDto<
      InitTransactionSessionRequestDto>(body: sessionDto);

  final String requestJson = json.encode(requestDto.toJson());
  final String requestHash = HttpUtils.computeHash(
      requestJson, _requestHashKey);

  final Map<String, dynamic> response = await ApiGatewayClient(_stage)
      .postAndParseJson(
      _initTransactionSessionInfoPath, requestJson, _apiKey,
      authToken: authToken,
      requestHash: requestHash);

  final ResponseDto<TransactionSessionResponseDto> responseDto = ResponseDto<
      TransactionSessionResponseDto>
      .fromJson(response, TransactionSessionResponseDto.fromJson);

  responseDto.throwApiExceptionIfError();
  return responseDto;
}