Example #1
0
        public async Task <IActionResult> ProcessOrder(IncommingOrderDto order)
        {
            try
            {
                var validationResult = PayloadValidator.ValidateOrderDetails(order);
                if (!validationResult.Item1)
                {
                    return(BadRequest(string.Join(", ", validationResult.Item2)));
                }

                var paymentResult = await PaymentProcessor.ProcessPayment(_clientFactory, order);

                if (!paymentResult.Item1)
                {
                    return(BadRequest(paymentResult.Item2));
                }

                var result = await _orders.AddNewOrderDetails(order);

                if (!result.Success)
                {
                    BadRequest(result.Message);
                }

                var uri = $"https://localhost:44327/api/billing/order/{result.SingleOrder.OrderNumber}";
                return(Created(uri, DtoMapper.MapResultDtoToCreatedOrderDto(result)));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }