public static PayExAddress OrderAddress(Cart cart, PaymentInformation payment, InitializeResult result)
        {
            PayExAddress payexAddress = new PayExAddress(result.OrderRef.ToString());

            if (cart == null || cart.OrderForms == null || cart.OrderForms.Count == 0)
                return payexAddress;

            OrderForm orderForm = cart.OrderForms[0];

            OrderAddress billingAddress = cart.OrderAddresses.ToArray().FirstOrDefault(x => x.Name == orderForm.BillingAddressId);
            if (billingAddress != null)
                payexAddress.BillingAddress.Populate(billingAddress);

            if (orderForm.Shipments != null && orderForm.Shipments.Count > 0 && orderForm.Shipments[0] != null)
            {
                OrderAddress shippingAddress = cart.OrderAddresses.ToArray().FirstOrDefault(x => x.Name == orderForm.Shipments[0].ShippingAddressId);
                if (shippingAddress != null)
                    payexAddress.ShippingAddress.Populate(shippingAddress);
            }

            return payexAddress;
        }
        private void AddOrderLineItems(Cart cart, PaymentInformation payment, InitializeResult initializeResult)
        {
            Log.InfoFormat("Calling AddOrderLineItems for cart with ID:{0}. PaymentInformation:{1}. InitializeResult:{2}", cart.Id, payment, initializeResult);

            List<OrderLine> orderlines = CartHelper.OrderLines(cart, payment, initializeResult);
            foreach (OrderLine orderline in orderlines)
            {
                string hash = _hasher.Create(_payExSettings.AccountNumber, orderline, _payExSettings.EncryptionKey);
                string result = _orderFacade.AddOrderLine(_payExSettings.AccountNumber, orderline, hash);

                Log.InfoFormat("Added OrderLineItem for cart with ID:{0}. OrderLine:{1}. Result:{2}",
                    cart.Id, orderline, result);
            }
        }
        private void AddOrderAddress(Cart cart, PaymentInformation payment, InitializeResult initializeResult)
        {
            Log.InfoFormat("Calling AddOrderAddress for cart with ID:{0}. PaymentInformation:{1}. InitializeResult:{2}", cart.Id, payment, initializeResult);

            PayExAddress address = CartHelper.OrderAddress(cart, payment, initializeResult);
            string hash = _hasher.Create(_payExSettings.AccountNumber, address, _payExSettings.EncryptionKey);
            string xmlResult = _orderFacade.AddOrderAddress(_payExSettings.AccountNumber, address, hash);

            Log.InfoFormat("Finished calling AddOrderAddress for cart with ID:{0}. PaymentInformation:{1}. InitializeResult:{2}. Result:{3}",
                cart.Id, payment, initializeResult, xmlResult);
        }
        public static List<OrderLine> OrderLines(Cart cart, PaymentInformation payment, InitializeResult result)
        {
            List<OrderLine> orderLines = new List<OrderLine>();
            if (cart == null || cart.OrderForms == null || cart.OrderForms.Count == 0)
                return orderLines;

            OrderForm orderForm = cart.OrderForms[0];
            if (orderForm == null || orderForm.LineItems == null || orderForm.LineItems.Count == 0)
                return orderLines;

            foreach (LineItem lineItem in orderForm.LineItems)
            {
                orderLines.Add(new OrderLine(result.OrderRef.ToString(), lineItem.CatalogEntryId, lineItem.DisplayName, (int)lineItem.Quantity,
                    lineItem.ExtendedPrice.RoundToInt(), GetVatAmount(lineItem), GetVatPercentage(lineItem)));
            }

            decimal shippingVatPercentage = GetShippingVatPercentage();
            foreach (Shipment shipment in orderForm.Shipments)
            {
                decimal shippingVatAmount = cart.ShippingTotal * (shippingVatPercentage / 100);
                orderLines.Add(new OrderLine(result.OrderRef.ToString(), string.Empty, GetShippingMethodName(shipment), 1,
                    cart.ShippingTotal.RoundToInt(), shippingVatAmount, shippingVatPercentage));
            }
            return orderLines;
        }