/// <summary>
        /// Gets tax rate
        /// </summary>
        /// <param name="calculateTaxRequest">Tax calculation request</param>
        /// <returns>Tax</returns>
        public CalculateTaxResult GetTaxRate(CalculateTaxRequest calculateTaxRequest)
        {
            var result = new CalculateTaxResult();

            var address = calculateTaxRequest.Address;

            if (address == null)
            {
                result.AddError("Address is not set");
                return(result);
            }
            if (address.Country == null)
            {
                result.AddError("Country is not set");
                return(result);
            }

            //**************************************************************************************************************
            // As a Registered StrikeIron user, you can authenticate to a StrikeIron web service with either a
            // UserID/Password combination or a License Key.  If you wish to use a License Key,
            // assign this value to the UserID field and set the Password field to null.
            //**************************************************************************************************************
            string userId   = _strikeIronTaxSettings.UserId;
            string password = _strikeIronTaxSettings.Password;

            decimal taxRate = decimal.Zero;

            if (address.Country.TwoLetterIsoCode.ToLower() == "us")
            {
                if (String.IsNullOrEmpty(address.ZipPostalCode))
                {
                    result.AddError("Zip is not provided");
                    return(result);
                }
                string error = "";
                taxRate = GetTaxRateUsa(address.ZipPostalCode, userId, password, ref error);
                if (!String.IsNullOrEmpty(error))
                {
                    result.AddError(error);
                    return(result);
                }
            }
            else if (address.Country.TwoLetterIsoCode.ToLower() == "ca")
            {
                if (address.StateProvince == null)
                {
                    result.AddError("Province is not set");
                    return(result);
                }
                string error = "";
                taxRate = GetTaxRateCanada(address.StateProvince.Abbreviation, userId, password, ref error);
                if (!String.IsNullOrEmpty(error))
                {
                    result.AddError(error);
                    return(result);
                }
            }
            else
            {
                result.AddError("Tax can be calculated only for USA zip or Canada province");
                return(result);
            }

            result.TaxRate = taxRate * 100;
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Gets tax rate
        /// </summary>
        /// <param name="calculateTaxRequest">Tax calculation request</param>
        /// <returns>Tax</returns>
        public CalculateTaxResult GetTaxRate(CalculateTaxRequest calculateTaxRequest)
        {
            var result  = new CalculateTaxResult();
            var address = calculateTaxRequest.Address;

            if (address == null)
            {
                result.AddError("Address is not set");
                return(result);
            }
            if (address.Country == null)
            {
                result.AddError("Country is not set");
                return(result);
            }

            string  licenseKey = _strikeIronTaxSettings.LicenseKey;
            decimal taxRate;

            if (address.Country.TwoLetterIsoCode.ToLower() == "us")
            {
                if (String.IsNullOrEmpty(address.ZipPostalCode))
                {
                    result.AddError("Zip is not provided");

                    return(result);
                }

                string error = "";

                taxRate = GetTaxRateUsa(address.ZipPostalCode, licenseKey, ref error);

                if (!String.IsNullOrEmpty(error))
                {
                    result.AddError(error);

                    return(result);
                }
            }
            else if (address.Country.TwoLetterIsoCode.ToLower() == "ca")
            {
                if (address.StateProvince == null)
                {
                    result.AddError("Province is not set");

                    return(result);
                }

                string error = "";

                taxRate = GetTaxRateCanada(address.StateProvince.Abbreviation, licenseKey, ref error);

                if (!String.IsNullOrEmpty(error))
                {
                    result.AddError(error);

                    return(result);
                }
            }
            else
            {
                result.AddError("Tax can be calculated only for USA zip or Canada province");

                return(result);
            }

            result.TaxRate = taxRate * 100;

            return(result);
        }