Beispiel #1
0
        private async Task <OrderTaxCalculation> CalculateTaxAsync(OrderWorksheet orderWorksheet, List <OrderPromotion> promotions, VertexSaleMessageType type)
        {
            var request  = orderWorksheet.ToVertexCalculateTaxRequest(promotions, _config.CompanyName, type);
            var response = await _client.CalculateTax(request);

            var orderTaxCalculation = response.ToOrderTaxCalculation();

            return(orderTaxCalculation);
        }
        public static VertexCalculateTaxRequest ToVertexCalculateTaxRequest(this OrderWorksheet order, List <OrderPromotion> promosOnOrder, string companyCode, VertexSaleMessageType type)
        {
            var itemLines     = order.LineItems.Select(li => ToVertexLineItem(li));
            var shippingLines = order.ShipEstimateResponse.ShipEstimates.Select(se =>
            {
                var firstLi = order.LineItems.First(li => li.ID == se.ShipEstimateItems.First().LineItemID);
                return(ToVertexLineItem(se, firstLi.ShippingAddress));
            });

            return(new VertexCalculateTaxRequest()
            {
                postingDate = DateTime.Now.ToString("yyyy-MM-dd"),
                saleMessageType = type,
                transactionType = VertexTransactionType.SALE,
                transactionId = order.Order.ID,
                seller = new VertexSeller()
                {
                    company = companyCode
                },
                customer = new VertexCustomer()
                {
                    customerCode = new VertexCustomerCode()
                    {
                        classCode = order.Order.FromUserID,
                        value = order.Order.FromUser.Email
                    },
                },
                lineItems = itemLines.Concat(shippingLines).ToList()
            });
        }