public async Task <IPaymentResponseDto> ProcessPaymentAsync(IPaymentRequestDto paymentRequest, CancellationToken cancellationToken) { var paymentResult = await _acquiringBankProvider.ProcessPaymentAsync(paymentRequest, cancellationToken); var completedPaymentDto = new CompletedPaymentDto(paymentRequest, paymentResult); _paymentRepository.SavePayment(completedPaymentDto); return(paymentResult); }
public CompletedPaymentDto(IPaymentRequestDto paymentRequest, IPaymentResponseDto paymentResponse) { CardNumber = paymentRequest.CardNumber; ExpiryDate = paymentRequest.ExpiryDate; Amount = paymentRequest.Amount; CurrencyCode = paymentRequest.CurrencyCode; Ccv = paymentRequest.Ccv; PaymentId = paymentResponse.PaymentId; IsSuccessful = paymentResponse.IsSuccessful; }
public Task <IPaymentResponseDto> ProcessPaymentAsync(IPaymentRequestDto acquiringBankPaymentRequest, CancellationToken cancellationToken) { var request = _mapper.Map <AcquiringBankPaymentRequestV1>(acquiringBankPaymentRequest); if (request == null) { throw new InvalidOperationException("Mapping to AcquiringBankPaymentRequestV1 is misconfigured."); } return(Task.FromResult((IPaymentResponseDto)_mapper.Map <CompletedPaymentDto>(GeneratePaymentResponse()))); }
public async Task <IPaymentResponseDto> ProcessPaymentAsync(IPaymentRequestDto acquiringBankPaymentRequest, CancellationToken cancellationToken) { var requestUri = new Uri(_configuration.BaseUri, PaymentsUrlPath); var requestBody = _mapper.Map <AcquiringBankPaymentRequestV1>(acquiringBankPaymentRequest); var jsonRequestBody = JsonSerializer.Serialize(requestBody, JsonSerializerOptions); var httpRequest = new HttpRequestMessage(HttpMethod.Post, requestUri) { Content = new StringContent(jsonRequestBody, Encoding.UTF8, MediaTypeNames.Application.Json) }; var httpClient = _httpClientFactory.CreateClient(); var httpResponse = await httpClient.SendAsync(httpRequest, cancellationToken); httpResponse.EnsureSuccessStatusCode(); var jsonResponseBody = await httpResponse.Content.ReadAsStringAsync(); var responseBody = JsonSerializer.Deserialize <AcquiringBankPaymentResponseV1>(jsonResponseBody, JsonSerializerOptions); return(_mapper.Map <CompletedPaymentDto>(responseBody)); }