Tax provider

Tax providers allow you to calculate tax for products.

Firstly  you  must create a class that will implement the ITaxProvider interface :


public partial interface ITaxProvider : IProvider
    {
        Task GetTaxRate(TaxRequest calculateTaxRequest);
    }
	

This interface has one significant method. GetTaxRate method that receives calculateRequest that contain Product object, CategoryTaxId, and others properties and return an object with our calculated rate.

In example belove you can see an implementation that calculates tax base on taxCategoryId 


  public class FixedRateTaxProvider : ITaxProvider
    {
        private readonly ISettingService _settingService;
        private readonly ITranslationService _translationService;

        public FixedRateTaxProvider(ISettingService settingService, ITranslationService translationService)
        {
            _settingService = settingService;
            _translationService = translationService;
        }

        public string ConfigurationUrl => FixedRateTaxDefaults.ConfigurationUrl;
        public string SystemName => FixedRateTaxDefaults.ProviderSystemName;
        public string FriendlyName => _translationService.GetResource(FixedRateTaxDefaults.FriendlyName);
        public int Priority => 0;

        public IList LimitedToStores => new List();
        public IList LimitedToGroups => new List();
        public Task GetTaxRate(TaxRequest calculateTaxRequest)
        {
            var result = new TaxResult
            {
                TaxRate = GetTaxRate(calculateTaxRequest.TaxCategoryId)
            };
            return Task.FromResult(result);
        }

        protected double GetTaxRate(string taxCategoryId)
        {
            var rate = _settingService.GetSettingByKey(string.Format("Tax.TaxProvider.FixedRate.TaxCategoryId{0}", taxCategoryId))?.Rate;
            return rate ?? 0;
        }
    }
	

See the plugin example.