Esempio n. 1
0
        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 async Task Process_AnyPaymentRequest_ReturnsSomeStatus()
        {
            // Arrange
            var paymentRequest = new PaymentProcessingRequest("Test", "1111111111111111", 12, 2025, 20, "EUR", 132);

            // Act
            var result = await _target.Process(paymentRequest);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsFalse(string.IsNullOrEmpty(result.Status));
        }