/// <summary>
        /// Gets a tax rate
        /// </summary>
        /// <param name="zipCode">zip</param>
        /// <param name="userId">User ID</param>
        /// <param name="password">Password</param>
        /// <param name="error">Error</param>
        /// <returns>Tax rate</returns>
        public decimal GetTaxRateUsa(string zipCode, string userId,
                                     string password, ref string error)
        {
            decimal result = decimal.Zero;
            string  key    = string.Format(TAXRATEUSA_KEY, zipCode);

            if (CacheManager.IsSet(key))
            {
                return(CacheManager.Get <decimal>(key));
            }

            try
            {
                var taxService = new Nop.Plugin.Tax.StrikeIron.TaxDataBasic.TaxDataBasic();
                taxService.LicenseInfoValue = new LicenseInfo();
                taxService.LicenseInfoValue.RegisteredUser          = new RegisteredUser();
                taxService.LicenseInfoValue.RegisteredUser.UserID   = userId;
                taxService.LicenseInfoValue.RegisteredUser.Password = password;

                // The GetTaxRateUS operation can now be called.  The output type for this operation is SIWSOutputOfTaxRateUSAData.
                // Note that for simplicity, there is no error handling in this sample project.  In a production environment, any
                // web service call should be encapsulated in a try-catch block.
                var wsOutput = taxService.GetTaxRateUS(zipCode);

                // The output objects of this StrikeIron web service contains two sections: ServiceStatus, which stores data
                // indicating the success/failure status of the the web service request; and ServiceResult, which contains the
                // actual data returne as a result of the request.

                // ServiceStatus contains two elements - StatusNbr: a numeric status code, and StatusDescription: a string
                // describing the status of the output object.  As a standard, you can apply the following assumptions for the value of
                // StatusNbr:
                //   200-299: Successful web service call (data found, etc...)
                //   300-399: Nonfatal error (No data found, etc...)
                //   400-499: Error due to invalid input
                //   500+: Unexpected internal error; contact [email protected]
                if ((wsOutput.ServiceStatus.StatusNbr >= 200) && (wsOutput.ServiceStatus.StatusNbr < 300))
                {
                    //Successfully called SalesTax service...
                    var sb = new StringBuilder();
                    sb.AppendLine("City name: " + wsOutput.ServiceResult.City);
                    sb.AppendLine("Zip Code: " + wsOutput.ServiceResult.ZIPCode);
                    sb.AppendLine("City sales tax: " + wsOutput.ServiceResult.CitySalesTax.ToString());
                    sb.AppendLine("City use tax: " + wsOutput.ServiceResult.CityUseTax.ToString());
                    sb.AppendLine("County name: " + wsOutput.ServiceResult.County);
                    sb.AppendLine("County sales tax: " + wsOutput.ServiceResult.CountySalesTax.ToString());
                    sb.AppendLine("County use tax: " + wsOutput.ServiceResult.CountyUseTax.ToString());
                    sb.AppendLine("State name: " + wsOutput.ServiceResult.State);
                    sb.AppendLine("State sales tax: " + wsOutput.ServiceResult.StateSalesTax.ToString());
                    sb.AppendLine("State use tax: " + wsOutput.ServiceResult.StateUseTax.ToString());
                    sb.AppendLine("State tax shipping alone: " + wsOutput.ServiceResult.TaxShippingAlone);
                    sb.AppendLine("State tax shipping and handling: " + wsOutput.ServiceResult.TaxShippingHandling);
                    sb.AppendLine("State total sales tax: " + wsOutput.ServiceResult.TotalSalesTax.ToString());
                    sb.AppendLine("State total use tax: " + wsOutput.ServiceResult.TotalUseTax.ToString());
                    string debug = sb.ToString();
                    Debug.WriteLine(debug);
                    result = Convert.ToDecimal(wsOutput.ServiceResult.TotalUseTax);
                }
                else
                {
                    // StrikeIron does not return SoapFault for invalid data when it cannot find a zipcode.
                    error = String.Format("[{0}] - {1}", wsOutput.ServiceStatus.StatusNbr.ToString(), wsOutput.ServiceStatus.StatusDescription);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            CacheManager.Set(key, result, 60);

            return(result);
        }
        /// <summary>
        /// Gets a tax rate
        /// </summary>
        /// <param name="zipCode">zip</param>
        /// <param name="userId">User ID</param>
        /// <param name="password">Password</param>
        /// <param name="error">Error</param>
        /// <returns>Tax rate</returns>
        public decimal GetTaxRateUsa(string zipCode, string userId,
            string password, ref string error)
        {
            decimal result = decimal.Zero;
            string key = string.Format(TAXRATEUSA_KEY, zipCode);
            if (CacheManager.IsSet(key))
                return CacheManager.Get<decimal>(key);

            try
            {
                var taxService = new Nop.Plugin.Tax.StrikeIron.TaxDataBasic.TaxDataBasic();
                taxService.LicenseInfoValue = new LicenseInfo();
                taxService.LicenseInfoValue.RegisteredUser = new RegisteredUser();
                taxService.LicenseInfoValue.RegisteredUser.UserID = userId;
                taxService.LicenseInfoValue.RegisteredUser.Password = password;

                // The GetTaxRateUS operation can now be called.  The output type for this operation is SIWSOutputOfTaxRateUSAData.
                // Note that for simplicity, there is no error handling in this sample project.  In a production environment, any
                // web service call should be encapsulated in a try-catch block.
                var wsOutput = taxService.GetTaxRateUS(zipCode);

                // The output objects of this StrikeIron web service contains two sections: ServiceStatus, which stores data
                // indicating the success/failure status of the the web service request; and ServiceResult, which contains the
                // actual data returne as a result of the request.

                // ServiceStatus contains two elements - StatusNbr: a numeric status code, and StatusDescription: a string
                // describing the status of the output object.  As a standard, you can apply the following assumptions for the value of
                // StatusNbr:
                //   200-299: Successful web service call (data found, etc...)
                //   300-399: Nonfatal error (No data found, etc...)
                //   400-499: Error due to invalid input
                //   500+: Unexpected internal error; contact [email protected]
                if ((wsOutput.ServiceStatus.StatusNbr >= 200) && (wsOutput.ServiceStatus.StatusNbr < 300))
                {
                    //Successfully called SalesTax service...
                    var sb = new StringBuilder();
                    sb.AppendLine("City name: " + wsOutput.ServiceResult.City);
                    sb.AppendLine("Zip Code: " + wsOutput.ServiceResult.ZIPCode);
                    sb.AppendLine("City sales tax: " + wsOutput.ServiceResult.CitySalesTax.ToString());
                    sb.AppendLine("City use tax: " + wsOutput.ServiceResult.CityUseTax.ToString());
                    sb.AppendLine("County name: " + wsOutput.ServiceResult.County);
                    sb.AppendLine("County sales tax: " + wsOutput.ServiceResult.CountySalesTax.ToString());
                    sb.AppendLine("County use tax: " + wsOutput.ServiceResult.CountyUseTax.ToString());
                    sb.AppendLine("State name: " + wsOutput.ServiceResult.State);
                    sb.AppendLine("State sales tax: " + wsOutput.ServiceResult.StateSalesTax.ToString());
                    sb.AppendLine("State use tax: " + wsOutput.ServiceResult.StateUseTax.ToString());
                    sb.AppendLine("State tax shipping alone: " + wsOutput.ServiceResult.TaxShippingAlone);
                    sb.AppendLine("State tax shipping and handling: " + wsOutput.ServiceResult.TaxShippingHandling);
                    sb.AppendLine("State total sales tax: " + wsOutput.ServiceResult.TotalSalesTax.ToString());
                    sb.AppendLine("State total use tax: " + wsOutput.ServiceResult.TotalUseTax.ToString());
                    string debug = sb.ToString();
                    Debug.WriteLine(debug);
                    result = Convert.ToDecimal(wsOutput.ServiceResult.TotalUseTax);
                }
                else
                {
                    // StrikeIron does not return SoapFault for invalid data when it cannot find a zipcode. 
                    error = String.Format("[{0}] - {1}", wsOutput.ServiceStatus.StatusNbr.ToString(), wsOutput.ServiceStatus.StatusDescription);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            CacheManager.Set(key, result, 60);
            
            return result;
        }
예제 #3
0
        /// <summary>
        /// Gets a tax rate
        /// </summary>
        /// <param name="zipCode">zip</param>
        /// <param name="licenseKey">License key</param>
        /// <param name="error">Error</param>
        /// <returns>Tax rate</returns>
        public decimal GetTaxRateUsa(string zipCode,
                                     string licenseKey,
                                     ref string error)
        {
            var     key    = string.Format(TAXRATEUSA_KEY, zipCode);
            decimal result = decimal.Zero;

            try
            {
                result = _cacheManager.Get(key, () =>
                {
                    var tax = Decimal.Zero;

                    var taxService = new TaxDataBasic.TaxDataBasic
                    {
                        LicenseInfoValue = new LicenseInfo
                        {
                            RegisteredUser = new RegisteredUser
                            {
                                UserID = licenseKey
                            }
                        }
                    };

                    // The GetTaxRateUS operation can now be called.  The output type for this operation is SIWSOutputOfTaxRateUSAData.
                    // Note that for simplicity, there is no error handling in this sample project.  In a production environment, any
                    // web service call should be encapsulated in a try-catch block.
                    var wsOutput = taxService.GetTaxRateUS(zipCode);

                    // The output objects of this StrikeIron web service contains two sections: ServiceStatus, which stores data
                    // indicating the success/failure status of the the web service request; and ServiceResult, which contains the
                    // actual data returne as a result of the request.

                    // ServiceStatus contains two elements - StatusNbr: a numeric status code, and StatusDescription: a string
                    // describing the status of the output object.  As a standard, you can apply the following assumptions for the value of
                    // StatusNbr:
                    //   200-299: Successful web service call (data found, etc...)
                    //   300-399: Nonfatal error (No data found, etc...)
                    //   400-499: Error due to invalid input
                    //   500+: Unexpected internal error; contact [email protected]
                    if ((wsOutput.ServiceStatus.StatusNbr >= 200) && (wsOutput.ServiceStatus.StatusNbr < 300))
                    {
                        tax = Convert.ToDecimal(wsOutput.ServiceResult.TotalUseTax);
                    }
                    else
                    {
                        // StrikeIron does not return SoapFault for invalid data when it cannot find a zipcode.
                        throw new Exception(string.Format("[{0}] - {1}", wsOutput.ServiceStatus.StatusNbr,
                                                          wsOutput.ServiceStatus.StatusDescription));
                    }

                    return(tax);
                });
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            return(result);
        }