Last updated: Mar 09 2018

Area: Episerver Commerce Applies to versions: 12 and higher
Other versions:

Tax calculator

The TaxCalculator calculates the tax value of a line item and the tax amount, based on tax value.

  • Tax value. Gets a line item's tax value, based on market and shipping address.
    public void GetTaxValues(ILineItem lineItem, IMarket market, IOrderAddress shippingAddress, ITaxCalculator taxCalculator)
    {
        var taxValues = taxCalculator.GetTaxValues(lineItem, market, shippingAddress);
    
        foreach (var taxValue in taxValues)
        {
            Debug.WriteLine("Tax value for line item '{0}': Tax name: {1}, Percentage: {2}", lineItem.LineItemId, taxValue.DisplayName, taxValue.Percentage);
        }
    }
  • Calculate tax. Calculates the tax amount based on tax values, tax type, base price, and currency.
    public void CalculateTax(IEnumerable<ITaxValue> taxes, TaxType taxType, decimal basePrice, Currency currency, ITaxCalculator taxCalculator)
    {
        var taxAmount = taxCalculator.CalculateTax(taxes, taxType, basePrice, currency);
        Debug.WriteLine("Tax amount for tax type '{0}': {1}", taxType.ToString(), taxAmount);
    }

Changing the default calculation

By inheriting from the default implementation of the interface, DefaultTaxCalculator, you can override the calculation of get tax value and get tax category name. Just override one or several methods in the DefaultTaxCalculator.

Comments