Beispiel #1
0
        /// <summary>
        /// The get taxation by product method.
        /// </summary>
        /// <returns>
        /// The <see cref="ITaxationByProductMethod"/>.
        /// </returns>
        /// <exception cref="NullReferenceException">
        /// Throws a null reference exception if a provider cannot be resolved
        /// </exception>
        private ITaxationByProductMethod GetTaxationByProductMethod()
        {
            var taxMethod = GatewayProviderService.GetTaxMethodForProductPricing();

            if (taxMethod == null)
            {
                LogHelper.Debug <TaxationContext>("Product based pricing is set in settings, but a TaxMethod has not been assigned.");
                this._taxMethodNotQueried = true;
                return(null);
            }

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

            if (provider == null)
            {
                var error = new NullReferenceException("Could not reTaxationGatewayProvider for CalculateTaxForProduct could not be resolved");
                LogHelper.Error <TaxationContext>("Resolution failure", error);
                throw error;
            }

            var productProvider = provider as ITaxationByProductProvider;

            if (productProvider != null)
            {
                this._taxMethodNotQueried = false;
                return(productProvider.GetTaxationByProductMethod(taxMethod.Key));
            }

            LogHelper.Debug <TaxationContext>("Resolved provider did not Implement ITaxationByProductProvider returning no tax");
            return(null);
        }
        /// <summary>
        /// Resolves all active shipping gateway providers for a given <see cref="IShipCountry"/>
        /// </summary>
        /// <param name="shipCountry">
        /// The ship Country.
        /// </param>
        /// <returns>
        /// A collection of all active shipping gateway providers
        /// </returns>
        public IEnumerable <ShippingGatewayProviderBase> GetGatewayProvidersByShipCountry(IShipCountry shipCountry)
        {
            var gatewayProviders = GatewayProviderService.GetGatewayProvidersByShipCountry(shipCountry);

            return
                (gatewayProviders.Select(
                     provider => GatewayProviderResolver.GetProviderByKey <ShippingGatewayProviderBase>(provider.Key)));
        }
Beispiel #3
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));
        }