private Money?GetDiscountedPrice(ICart cart, ILineItem lineItem) { var marketId = _currentMarket.GetCurrentMarket().MarketId; var currency = _currencyService.GetCurrentCurrency(); if (cart.Name.Equals(_cartService.DefaultWishListName)) { var discountedPrice = _promotionService.GetDiscountPrice(new CatalogKey(_appContext.ApplicationId, lineItem.Code), marketId, currency); return(discountedPrice != null ? discountedPrice.UnitPrice : (Money?)null); } return(lineItem.GetDiscountedPrice(cart.Currency, _lineItemCalculator)); }
public Money?GetDiscountedPrice(ICart cart, ILineItem lineItem) { var marketId = _currentMarket.GetCurrentMarket().MarketId; var currency = _currencyService.GetCurrentCurrency(); if (cart.Name.Equals(DefaultWishListName)) { var discountedPrice = _promotionService.GetDiscountPrice(new CatalogKey(lineItem.Code), marketId, currency); return(discountedPrice?.UnitPrice); } return(lineItem.GetDiscountedPrice(cart.Currency, _lineItemCalculator)); }
public static Prices GetPrices(ILineItem lineItem, IMarket market, IShipment shipment, Currency currency) { /* * unit_price integer required * Minor units. Includes tax, excludes discount. (max value: 100000000) * tax_rate integer required * Non-negative. In percent, two implicit decimals. I.e 2500 = 25%. * total_amount integer required * Includes tax and discount. Must match (quantity * unit_price) - total_discount_amount within �quantity. (max value: 100000000) * total_tax_amount integer required * Must be within �1 of total_amount - total_amount * 10000 / (10000 + tax_rate). Negative when type is discount. * total_discount_amount integer * Non - negative minor units. Includes tax. */ var taxType = TaxType.SalesTax; // All excluding tax var unitPrice = lineItem.PlacedPrice; var totalPriceWithoutDiscount = lineItem.PlacedPrice * lineItem.Quantity; var extendedPrice = lineItem.GetDiscountedPrice(currency); var discountAmount = (totalPriceWithoutDiscount - extendedPrice); // Tax value var taxValues = _lineItemTaxCalculator.Service.GetTaxValuesForLineItem(lineItem, market, shipment); var taxPercentage = taxValues .Where(x => x.TaxType == taxType) .Sum(x => (decimal)x.Percentage); // Using ITaxCalculator instead of ILineItemCalculator because ILineItemCalculator // calculates tax from the price which includes order discount amount and line item discount amount // but should use only line item discount amount var salesTax = _taxCalculator.Service.GetSalesTax(lineItem, market, shipment.ShippingAddress, extendedPrice); // Includes tax, excludes discount. (max value: 100000000) var unitPriceIncludingTax = AmountHelper.GetAmount( _lineItemTaxCalculator.Service.PriceIncludingTaxPercent(unitPrice, taxPercentage, market)); // Non - negative minor units. Includes tax var totalDiscountAmount = AmountHelper.GetAmount( _lineItemTaxCalculator.Service.PriceIncludingTaxPercent(discountAmount, taxPercentage, market)); // Includes tax and discount. Must match (quantity * unit_price) - total_discount_amount within quantity. (max value: 100000000) var totalAmount = AmountHelper.GetAmount( _lineItemTaxCalculator.Service.PriceIncludingTaxAmount(extendedPrice, salesTax.Amount, market)); // Non-negative. In percent, two implicit decimals. I.e 2500 = 25%. var taxRate = AmountHelper.GetAmount(taxPercentage); // Must be within 1 of total_amount - total_amount * 10000 / (10000 + tax_rate). Negative when type is discount. var totalTaxAmount = AmountHelper.GetAmount(salesTax.Amount); return(new Prices(unitPriceIncludingTax, taxRate, totalDiscountAmount, totalAmount, totalTaxAmount)); }
private static Models.LineItem ConvertToLineItem(ILineItem lineItem) { var defaultCurrency = Currency.USD; // Using USD as currency doesn't matter - calculation result will not use currency only amount. return(new Models.LineItem { LineItemId = lineItem.LineItemId, Code = lineItem.Code, DisplayName = lineItem.DisplayName, PlacedPrice = lineItem.PlacedPrice, ExtendedPrice = lineItem.GetExtendedPrice(defaultCurrency).Amount, DiscountedPrice = lineItem.GetDiscountedPrice(defaultCurrency).Amount, Quantity = lineItem.Quantity, ReturnQuantity = lineItem.ReturnQuantity, InventoryTrackingStatus = lineItem.InventoryTrackingStatus, IsInventoryAllocated = lineItem.IsInventoryAllocated, IsGift = lineItem.IsGift, Properties = lineItem.ToPropertyList() }); }
public static (int unitPrice, int taxRate, int totalDiscountAmount, int totalAmount, int totalTaxAmount) GetPrices(ILineItem lineItem, IMarket market, IShipment shipment, Currency currency) { /* * unit_price integer required * Minor units. Includes tax, excludes discount. (max value: 100000000) * tax_rate integer required * Non-negative. In percent, two implicit decimals. I.e 2500 = 25%. * total_amount integer required * Includes tax and discount. Must match (quantity * unit_price) - total_discount_amount within �quantity. (max value: 100000000) * total_tax_amount integer required * Must be within �1 of total_amount - total_amount * 10000 / (10000 + tax_rate). Negative when type is discount. * total_discount_amount integer * Non - negative minor units. Includes tax. */ var taxType = TaxType.SalesTax; // All excluding tax var unitPrice = lineItem.PlacedPrice; var totalPriceWithoutDiscount = lineItem.PlacedPrice * lineItem.Quantity; var extendedPrice = lineItem.GetDiscountedPrice(currency).Amount; var discountAmount = (totalPriceWithoutDiscount - extendedPrice); // Tax value var taxValues = _lineItemTaxCalculator.Service.GetTaxValuesForLineItem(lineItem, market, shipment); var taxPercentage = taxValues .Where(x => x.TaxType == taxType) .Sum(x => (decimal)x.Percentage); // Includes tax, excludes discount. (max value: 100000000) var unitPriceIncludingTax = AmountHelper.GetAmount(_lineItemTaxCalculator.Service.PriceIncludingTax(unitPrice, taxValues, taxType)); // Non - negative minor units. Includes tax int totalDiscountAmount = AmountHelper.GetAmount(_lineItemTaxCalculator.Service.PriceIncludingTax(discountAmount, taxValues, taxType)); // Includes tax and discount. Must match (quantity * unit_price) - total_discount_amount within quantity. (max value: 100000000) var totalAmount = AmountHelper.GetAmount(_lineItemTaxCalculator.Service.PriceIncludingTax(extendedPrice, taxValues, taxType)); // Non-negative. In percent, two implicit decimals. I.e 2500 = 25%. var taxRate = AmountHelper.GetAmount(taxPercentage); // Must be within 1 of total_amount - total_amount * 10000 / (10000 + tax_rate). Negative when type is discount. var totalTaxAmount = AmountHelper.GetAmount(_lineItemTaxCalculator.Service.GetTaxes(extendedPrice, taxValues, taxType)); return(unitPriceIncludingTax, taxRate, totalDiscountAmount, totalAmount, totalTaxAmount); }
public Money GetDiscountedPrice(ILineItem lineItem, Currency currency) { return(lineItem.GetDiscountedPrice(currency, _lineItemCalculator)); }
private Money? GetDiscountedPrice(ICart cart, ILineItem lineItem) { var marketId = _currentMarket.GetCurrentMarket().MarketId; var currency = _currencyService.GetCurrentCurrency(); if (cart.Name.Equals(_cartService.DefaultWishListName)) { var discountedPrice = _promotionService.GetDiscountPrice(new CatalogKey(_appContext.ApplicationId, lineItem.Code), marketId, currency); return discountedPrice != null ? discountedPrice.UnitPrice : (Money?)null; } return lineItem.GetDiscountedPrice(cart.Currency, _lineItemCalculator); }