private static decimal GetShippingCost(CustomerBase customer, IShippingMethod shippingMethod) { if (customer is PrimeCustomer) { return 0; } else { return shippingMethod.CalculatePrice(); } }
/// <summary> /// Check out a shopping cart /// </summary> /// <param name="purchaseItemList"></param> /// <param name="customer"></param> /// <param name="payment"></param> /// <param name="shippingMethod"></param> public static CustomerOrder Checkout(IPurchaseItemList purchaseItemList, CustomerBase customer, IPaymentMethod payment, IShippingMethod shippingMethod) { var customerOrder = new CustomerOrder(); customerOrder.OrderDateTime = DateTime.Now; purchaseItemList.Items.ForEach(i => customerOrder.Items.Add(i.Clone())); customerOrder.Customer = customer; customerOrder.Status = EOrderStatus.Processing; customerOrder.ShippingMethod = shippingMethod.MethodName(); customerOrder.PaymentMethod = payment.PaymentName(); customerOrder.ProductCost = purchaseItemList.GetTotalPrice(); customerOrder.ShippingCost = GetShippingCost(customer, shippingMethod); customerOrder.TotalCost = customerOrder.ProductCost + customerOrder.ShippingCost; payment.Charge(customerOrder.TotalCost); //todo : persist order return customerOrder; }