public double Total(double subTotal = 0, TaxAmount taxes = null) { if (taxes == null) { taxes = Taxes(); } if (subTotal.Equals(0)) { subTotal = Subtotal(); } if (taxes == null || taxes.Amount <= 0) { if (ShippingOption == null) { return(subTotal); } return(subTotal + ShippingOption.Price); } if (ShippingOption == null) { return(subTotal + taxes.Amount); } return(subTotal + taxes.Amount + ShippingOption.Price); }
public void Build( ICharge charge, IEnumerable <CheckoutItem> items, decimal subTotal, decimal total, TaxAmount taxes, ShippingOption shippingOption, Address shippingAddress, Address billingAddress, string customerEmail, string customerPhone, string specialInstructions, string currencyCode, decimal amountPaid = default(decimal), string purchaseOrder = "") { _contentDocument = new XElement(ContentName) .Attr(SubtotalName, subTotal) .Attr(TotalName, total) .Attr(AmountName, amountPaid == default(decimal) ? total : amountPaid) .Attr(PurchaseOrderName, purchaseOrder) .Attr(CurrencyCodeName, currencyCode) .AddEl(new XElement(ChargeName).With(charge) .ToAttr(c => c.TransactionId) .ToAttr(c => c.ChargeText) .Element) .AddEl(new XElement(ItemsName, items.Select(it => new XElement(ItemName).With(it) .ToAttr(i => i.ProductId) .ToAttr(i => i.Quantity) .ToAttr(i => i.Title) .ToAttr(i => i.Price) .ToAttr(i => i.OriginalPrice) .ToAttr(i => i.LinePriceAdjustment) .ToAttr(i => i.PromotionId) .Element .AddEl(new XElement(AttributesName, it.Attributes != null ? it.Attributes.Select(at => { var attrEl = new XElement(AttributeName); attrEl.SetAttributeValue("Key", at.Key); attrEl.SetAttributeValue("Value", at.Value.Value); attrEl.SetAttributeValue("Extra", at.Value.ExtendedValue); attrEl.SetAttributeValue("ExtensionProvider", at.Value.ExtensionProvider); return(attrEl); }) : null))))) .AddEl(new XElement(TaxesName).With(taxes) .ToAttr(t => t.Name) .ToAttr(t => t.Amount) .Element) .AddEl(new XElement(ShippingName).With(shippingOption) .ToAttr(s => s.Description) .ToAttr(s => s.ShippingCompany) .ToAttr(s => s.Price) .Element); var shippingAddressElement = Address.Set(new XElement(ShippingAddressName), shippingAddress); var billingAddressElement = Address.Set(new XElement(BillingAddressName), billingAddress); _customerDocument = new XElement(CustomerName) .AddEl(shippingAddressElement) .AddEl(billingAddressElement) .Attr(EmailName, customerEmail) .Attr(PhoneName, customerPhone) .Attr(InstructionsName, specialInstructions); PersistContents(); PersistCustomer(); }