public async Task <IActionResult> ProcessPayment(PaymentRequest request) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var processPayment = request.ToServicePaymentRequest(); var serviceResponse = await _paymentProcessingService.Process(processPayment); var paymentResponse = serviceResponse.ToPaymentResponse(request); var paymentRequest = serviceResponse.ToDomainServicePaymentRequest(request); _paymentRequestService.AddAsync(paymentRequest); _log.LogInformation("Payment processed", paymentRequest.Id); return(Created($"https://localhost:44365/api/payment/{paymentResponse.Id}", paymentResponse)); } catch (Exception e) { _log.LogError("Error during payment processing", e); throw; } }
public void PaymentRequestConverter_ToServicePaymentRequest_FieldsAreEqual() { // Arrange var paymentRequest = new PaymentRequest { Number = "1111111111111111", Name = "Test", ExpiryYear = 2021, ExpiryMonth = 12, Currency = "EUR", CVV = 123, Amount = 20 }; // Act var servicePaymentRequest = paymentRequest.ToServicePaymentRequest(); // Assert Assert.IsNotNull(servicePaymentRequest); Assert.IsTrue(AreFieldsEqual(paymentRequest, servicePaymentRequest)); }