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;
            }
        }