Пример #1
0
        public async Task <bool> ProcessOrderAsync(Order order)
        {
            //Recupera o ID da loja e os dados de cada produto
            StoreTable storeTable = await _storeTableQueryService.GetStoreTableAsync(order.TableId);

            order.StoreId = storeTable.StoreId;

            foreach (var item in order.OrderItems)
            {
                Product prod = await _productQueryService.GetProductAsync(item.ProductId);

                item.Price       = prod.Price;
                item.ProductName = prod.Name;
            }

            _uow.BeginTransaction();
            await _orderRepository.CreateAsync(order);

            _orderStatusService.AddTracking(order.Id, order.OrderStatus);
            await _uow.SaveChangesAsync();

            var paidInvoiceId = await _paymentService.ExecutePayment(order.Id, order.CustomerId, getOrderTotal(order));

            if (paidInvoiceId != null)
            {
                //Invoice paid. Lets change order status
                order.PaymentApproved = true;
                order.PaymentId       = paidInvoiceId.ToString();
                _orderRepository.Update(order);
                await _uow.SaveChangesAsync();
                await SetOrderStatus(order.StoreId, order.Id, OrderStatus.PaymentConfirmed);

                return(true);
            }
            return(false);
        }