Example #1
0
        /// <summary>
        /// Calculates taxes for the <see cref="IInvoice"/>
        /// </summary>
        /// <param name="invoice">
        /// The <see cref="IInvoice"/> to tax
        /// </param>
        /// <param name="taxAddress">
        /// The address to base the taxation calculation
        /// </param>
        /// <param name="quoteOnly">
        /// An optional parameter indicating that the tax calculation should be an estimate.
        /// This is useful for some 3rd party tax APIs
        /// </param>
        /// <returns>
        /// The <see cref="ITaxCalculationResult"/>
        /// </returns>
        public ITaxCalculationResult CalculateTaxesForInvoice(IInvoice invoice, IAddress taxAddress, bool quoteOnly = false)
        {
            var providersKey =
                GatewayProviderService.GetTaxMethodsByCountryCode(taxAddress.CountryCode)
                .Select(x => x.ProviderKey).FirstOrDefault();

            if (Guid.Empty.Equals(providersKey))
            {
                return(new TaxCalculationResult(0, 0));
            }

            var provider = GatewayProviderResolver.GetProviderByKey <TaxationGatewayProviderBase>(providersKey);

            var gatewayTaxMethod = provider.GetGatewayTaxMethodByCountryCode(taxAddress.CountryCode);

            return(gatewayTaxMethod.CalculateTaxForInvoice(invoice, taxAddress));
        }
Example #2
0
 /// <summary>
 /// Gets the tax method for country code.
 /// </summary>
 /// <param name="countryCode">
 /// The country code.
 /// </param>
 /// <returns>
 /// The <see cref="ITaxMethod"/>.
 /// </returns>
 public ITaxMethod GetTaxMethodForCountryCode(string countryCode)
 {
     return(GatewayProviderService.GetTaxMethodsByCountryCode(countryCode).FirstOrDefault());
 }