示例#1
0
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"];
            string licenseKey    = ConfigurationManager.AppSettings["AvaTax:LicenseKey"];
            string serviceURL    = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"];

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            CancelTaxRequest cancelTaxRequest = new CancelTaxRequest();

            // Required Request Parameters
            cancelTaxRequest.CompanyCode = "APITrialCompany";
            cancelTaxRequest.DocType     = DocType.SalesInvoice;
            cancelTaxRequest.DocCode     = "INV001";
            cancelTaxRequest.CancelCode  = CancelCode.DocVoided;

            CancelTaxResult cancelTaxResult = taxSvc.CancelTax(cancelTaxRequest);

            // Print results
            Console.WriteLine("CancelTaxTest Result: " + cancelTaxResult.ResultCode.ToString());
            if (!cancelTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in cancelTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
        }
示例#2
0
 public IHttpActionResult Total(CustomerOrder order)
 {
     if (!string.IsNullOrEmpty(_taxSettings.Username) && !string.IsNullOrEmpty(_taxSettings.Password)
         && !string.IsNullOrEmpty(_taxSettings.ServiceUrl)
         && !string.IsNullOrEmpty(_taxSettings.CompanyCode) && _taxSettings.IsEnabled)
     {
         var taxSvc = new TaxSvc(_taxSettings.Username, _taxSettings.Password, _taxSettings.ServiceUrl);
         var request = order.ToAvaTaxRequest(_taxSettings.CompanyCode);
         var getTaxResult = taxSvc.GetTax(request);
         if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success))
         {
             var error = string.Join(Environment.NewLine, getTaxResult.Messages.Select(m => m.Details));
             return BadRequest(error);
         }
         else
         {
             foreach (TaxLine taxLine in getTaxResult.TaxLines ?? Enumerable.Empty<TaxLine>())
             {
                 order.Items.ToArray()[Int32.Parse(taxLine.LineNo)].Tax = taxLine.Tax;
                 //foreach (TaxDetail taxDetail in taxLine.TaxDetails ?? Enumerable.Empty<TaxDetail>())
                 //{
                 //}
             }
             order.Tax = getTaxResult.TotalTax;
         }
     }
     else
     {
         return BadRequest();
     }
     return Ok(order);
 }
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"];
            string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"];
            string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"];

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            CancelTaxRequest cancelTaxRequest = new CancelTaxRequest();

            // Required Request Parameters
            cancelTaxRequest.CompanyCode = "APITrialCompany";
            cancelTaxRequest.DocType = DocType.SalesInvoice;
            cancelTaxRequest.DocCode = "INV001";
            cancelTaxRequest.CancelCode = CancelCode.DocVoided;

            CancelTaxResult cancelTaxResult = taxSvc.CancelTax(cancelTaxRequest);

            // Print results
            Console.WriteLine("CancelTaxTest Result: " + cancelTaxResult.ResultCode.ToString());
            if (!cancelTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in cancelTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
        }
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = "1234567890";
            string licenseKey = "A1B2C3D4E5F6G7H8";
            string serviceURL = "https://development.avalara.net";

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            CancelTaxRequest cancelTaxRequest = new CancelTaxRequest();

            // Required Request Parameters
            cancelTaxRequest.CompanyCode = "APITrialCompany";
            cancelTaxRequest.DocType = DocType.SalesInvoice;
            cancelTaxRequest.DocCode = "INV001";
            cancelTaxRequest.CancelCode = CancelCode.DocVoided;

            CancelTaxResult cancelTaxResult = taxSvc.CancelTax(cancelTaxRequest);

            // Print results
            Console.WriteLine("CancelTaxTest Result: " + cancelTaxResult.ResultCode.ToString());
            if (!cancelTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in cancelTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
        }
示例#5
0
        public IHttpActionResult TestConnection()
        {
            if (!string.IsNullOrEmpty(_taxSettings.Username) && !string.IsNullOrEmpty(_taxSettings.Password)
                && !string.IsNullOrEmpty(_taxSettings.ServiceUrl)
                && !string.IsNullOrEmpty(_taxSettings.CompanyCode))
            {
                if (!_taxSettings.IsEnabled)
                    return BadRequest("Tax calculation disabled, enable before testing connection");

                var taxSvc = new TaxSvc(_taxSettings.Username, _taxSettings.Password, _taxSettings.ServiceUrl);
                var retVal = taxSvc.Ping();
                if (retVal.ResultCode.Equals(SeverityLevel.Success))
                    return Ok(new[] {retVal});

                return BadRequest(string.Join(", ", retVal.Messages.Select(m => m.Summary)));
            }
            
            return BadRequest("AvaTax credentials not provided");
        }
示例#6
0
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = "1234567890";
            string licenseKey = "A1B2C3D4E5F6G7H8";
            string serviceURL = "https://development.avalara.net";

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            GeoTaxResult geoTaxResult = taxSvc.Ping();

            Console.WriteLine("PingTest Result: " + geoTaxResult.ResultCode.ToString());
            if (!geoTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in geoTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
        }
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"];
            string licenseKey    = ConfigurationManager.AppSettings["AvaTax:LicenseKey"];
            string serviceURL    = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"];

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            GeoTaxResult geoTaxResult = taxSvc.Ping();

            Console.WriteLine("PingTest Result: " + geoTaxResult.ResultCode.ToString());
            if (!geoTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in geoTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
        }
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"];
            string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"];
            string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"];

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            GeoTaxResult geoTaxResult = taxSvc.Ping();

            Console.WriteLine("PingTest Result: " + geoTaxResult.ResultCode.ToString());
            if (!geoTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in geoTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
        }
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"];
            string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"];
            string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"];

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            // Required Request Parameters
            decimal latitude = (decimal)47.627935;
            decimal longitude = (decimal)-122.51702;
            decimal saleAmount = (decimal)10;

            GeoTaxResult geoTaxResult = taxSvc.EstimateTax(latitude, longitude, saleAmount);

            // Print results
            Console.WriteLine("EstimateTaxTest Result: " + geoTaxResult.ResultCode.ToString());
            if (!geoTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in geoTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
            else
            {
                Console.WriteLine("Total Rate: " + geoTaxResult.Rate + " Total Tax: " + geoTaxResult.Tax);

                foreach (TaxDetail taxDetail in geoTaxResult.TaxDetails ?? Enumerable.Empty<TaxDetail>())
                {
                    Console.WriteLine("    " + "Jurisdiction: " + taxDetail.JurisName + " Tax: " + taxDetail.Tax.ToString());
                }
            }
        }
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = "1234567890";
            string licenseKey = "A1B2C3D4E5F6G7H8";
            string serviceURL = "https://development.avalara.net";

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            // Required Request Parameters
            decimal latitude = (decimal)47.627935;
            decimal longitude = (decimal)-122.51702;
            decimal saleAmount = (decimal)10;

            GeoTaxResult geoTaxResult = taxSvc.EstimateTax(latitude, longitude, saleAmount);

            // Print results
            Console.WriteLine("EstimateTaxTest Result: " + geoTaxResult.ResultCode.ToString());
            if (!geoTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in geoTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
            else
            {
                Console.WriteLine("Total Rate: " + geoTaxResult.Rate + " Total Tax: " + geoTaxResult.Tax);

                foreach (TaxDetail taxDetail in geoTaxResult.TaxDetails ?? Enumerable.Empty<TaxDetail>())
                {
                    Console.WriteLine("    " + "Jurisdiction: " + taxDetail.JurisName + " Tax: " + taxDetail.Tax.ToString());
                }
            }
        }
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"];
            string licenseKey    = ConfigurationManager.AppSettings["AvaTax:LicenseKey"];
            string serviceURL    = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"];

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            // Required Request Parameters
            decimal latitude   = (decimal)47.627935;
            decimal longitude  = (decimal) - 122.51702;
            decimal saleAmount = (decimal)10;

            GeoTaxResult geoTaxResult = taxSvc.EstimateTax(latitude, longitude, saleAmount);

            // Print results
            Console.WriteLine("EstimateTaxTest Result: " + geoTaxResult.ResultCode.ToString());
            if (!geoTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in geoTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
            else
            {
                Console.WriteLine("Total Rate: " + geoTaxResult.Rate + " Total Tax: " + geoTaxResult.Tax);

                foreach (TaxDetail taxDetail in geoTaxResult.TaxDetails ?? Enumerable.Empty <TaxDetail>())
                {
                    Console.WriteLine("    " + "Jurisdiction: " + taxDetail.JurisName + " Tax: " + taxDetail.Tax.ToString());
                }
            }
        }
示例#12
0
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = "1234567890";
            string licenseKey = "A1B2C3D4E5F6G7H8";
            string serviceURL = "https://development.avalara.net";

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            GetTaxRequest getTaxRequest = new GetTaxRequest();

            // Document Level Elements
            // Required Request Parameters
            getTaxRequest.CustomerCode = "ABC4335";
            getTaxRequest.DocDate = "2014-01-01";

            // Best Practice Request Parameters
            getTaxRequest.CompanyCode = "APITrialCompany";
            getTaxRequest.Client = "AvaTaxSample";
            getTaxRequest.DocCode = "INV001";
            getTaxRequest.DetailLevel = DetailLevel.Tax;
            getTaxRequest.Commit = false;
            getTaxRequest.DocType = DocType.SalesInvoice;

            // Situational Request Parameters
            // getTaxRequest.CustomerUsageType = "G";
            // getTaxRequest.ExemptionNo = "12345";
            // getTaxRequest.Discount = 50;
            // getTaxRequest.TaxOverride = new TaxOverrideDef();
            // getTaxRequest.TaxOverride.TaxOverrideType = "TaxDate";
            // getTaxRequest.TaxOverride.Reason = "Adjustment for return";
            // getTaxRequest.TaxOverride.TaxDate = "2013-07-01";
            // getTaxRequest.TaxOverride.TaxAmount = "0";

            // Optional Request Parameters
            getTaxRequest.PurchaseOrderNo = "PO123456";
            getTaxRequest.ReferenceCode = "ref123456";
            getTaxRequest.PosLaneCode = "09";
            getTaxRequest.CurrencyCode = "USD";

            // Address Data
            Address address1 = new Address();
            address1.AddressCode = "01";
            address1.Line1 = "45 Fremont Street";
            address1.City = "San Francisco";
            address1.Region = "CA";

            Address address2 = new Address();
            address2.AddressCode = "02";
            address2.Line1 = "118 N Clark St";
            address2.Line2 = "Suite 100";
            address2.Line3 = "ATTN Accounts Payable";
            address2.City = "Chicago";
            address2.Region = "IL";
            address2.Country = "US";
            address2.PostalCode = "60602";

            Address address3 = new Address();
            address3.AddressCode = "03";
            address3.Latitude = (decimal)47.627935;
            address3.Longitude = (decimal)-122.51702;
            Address[] addresses = { address1, address2, address3 };
            getTaxRequest.Addresses = addresses;

            // Line Data
            // Required Parameters
            Line line1 = new Line();
            line1.LineNo = "01";
            line1.ItemCode = "N543";
            line1.Qty = 1;
            line1.Amount = 10;
            line1.OriginCode = "01";
            line1.DestinationCode = "02";

            // Best Practice Request Parameters
            line1.Description = "Red Size 7 Widget";
            line1.TaxCode = "NT";

            // Situational Request Parameters
            // line1.CustomerUsageType = "L";
            // line1.Discounted = true;
            // line1.TaxIncluded = true;
            // line1.TaxOverride = new TaxOverrideDef();
            // line1.TaxOverride.TaxOverrideType = "TaxDate";
            // line1.TaxOverride.Reason = "Adjustment for return";
            // line1.TaxOverride.TaxDate = "2013-07-01";
            // line1.TaxOverride.TaxAmount = "0";

            // Optional Request Parameters
            line1.Ref1 = "ref123";
            line1.Ref2 = "ref456";

            Line line2 = new Line();
            line2.LineNo = "02";
            line2.ItemCode = "T345";
            line2.Qty = 3;
            line2.Amount = 150;
            line2.OriginCode = "01";
            line2.DestinationCode = "03";
            line2.Description = "Size 10 Green Running Shoe";
            line2.TaxCode = "PC030147";

            Line line3 = new Line();
            line3.LineNo = "02-FR";
            line3.ItemCode = "FREIGHT";
            line3.Qty = 1;
            line3.Amount = 15;
            line3.OriginCode = "01";
            line3.DestinationCode = "03";
            line3.Description = "Shipping Charge";
            line3.TaxCode = "FR";
            Line[] lines = { line1, line2, line3 };
            getTaxRequest.Lines = lines;

            GetTaxResult getTaxResult = taxSvc.GetTax(getTaxRequest);

            // Print results
            Console.WriteLine("GetTaxTest Result: " + getTaxResult.ResultCode.ToString());
            if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in getTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
            else
            {
                Console.WriteLine("Document Code: " + getTaxResult.DocCode + " Total Tax: " + getTaxResult.TotalTax);
                foreach (TaxLine taxLine in getTaxResult.TaxLines ?? Enumerable.Empty<TaxLine>())
                {
                    Console.WriteLine("    " + "Line Number: " + taxLine.LineNo + " Line Tax: " + taxLine.Tax.ToString());
                    foreach (TaxDetail taxDetail in taxLine.TaxDetails ?? Enumerable.Empty<TaxDetail>())
                    {
                        Console.WriteLine("        " + "Jurisdiction: " + taxDetail.JurisName + "Tax: " + taxDetail.Tax.ToString());
                    }
                }
            }
        }
示例#13
0
        public static void Test()
        {
            // Header Level Elements
            // Required Header Level Elements
            string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"];
            string licenseKey    = ConfigurationManager.AppSettings["AvaTax:LicenseKey"];
            string serviceURL    = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"];

            TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL);

            GetTaxRequest getTaxRequest = new GetTaxRequest();

            // Document Level Elements
            // Required Request Parameters
            getTaxRequest.CustomerCode = "ABC4335";
            getTaxRequest.DocDate      = "2014-01-01";

            // Best Practice Request Parameters
            getTaxRequest.CompanyCode = "APITrialCompany";
            getTaxRequest.Client      = "AvaTaxSample";
            getTaxRequest.DocCode     = "INV001";
            getTaxRequest.DetailLevel = DetailLevel.Tax;
            getTaxRequest.Commit      = false;
            getTaxRequest.DocType     = DocType.SalesInvoice;

            // Situational Request Parameters
            // getTaxRequest.CustomerUsageType = "G";
            // getTaxRequest.ExemptionNo = "12345";
            // getTaxRequest.BusinessIdentificationNo = "234243";
            // getTaxRequest.Discount = 50;
            // getTaxRequest.TaxOverride = new TaxOverrideDef();
            // getTaxRequest.TaxOverride.TaxOverrideType = "TaxDate";
            // getTaxRequest.TaxOverride.Reason = "Adjustment for return";
            // getTaxRequest.TaxOverride.TaxDate = "2013-07-01";
            // getTaxRequest.TaxOverride.TaxAmount = "0";

            // Optional Request Parameters
            getTaxRequest.PurchaseOrderNo = "PO123456";
            getTaxRequest.ReferenceCode   = "ref123456";
            getTaxRequest.PosLaneCode     = "09";
            getTaxRequest.CurrencyCode    = "USD";

            // Address Data
            Address address1 = new Address();

            address1.AddressCode = "01";
            address1.Line1       = "45 Fremont Street";
            address1.City        = "San Francisco";
            address1.Region      = "CA";

            Address address2 = new Address();

            address2.AddressCode = "02";
            address2.Line1       = "118 N Clark St";
            address2.Line2       = "Suite 100";
            address2.Line3       = "ATTN Accounts Payable";
            address2.City        = "Chicago";
            address2.Region      = "IL";
            address2.Country     = "US";
            address2.PostalCode  = "60602";

            Address address3 = new Address();

            address3.AddressCode = "03";
            address3.Latitude    = (decimal)47.627935;
            address3.Longitude   = (decimal) - 122.51702;
            Address[] addresses = { address1, address2, address3 };
            getTaxRequest.Addresses = addresses;

            // Line Data
            // Required Parameters
            Line line1 = new Line();

            line1.LineNo          = "01";
            line1.ItemCode        = "N543";
            line1.Qty             = 1;
            line1.Amount          = 10;
            line1.OriginCode      = "01";
            line1.DestinationCode = "02";

            // Best Practice Request Parameters
            line1.Description = "Red Size 7 Widget";
            line1.TaxCode     = "NT";

            // Situational Request Parameters
            // line1.CustomerUsageType = "L";
            // line1.Discounted = true;
            // line1.TaxIncluded = true;
            // line1.BusinessIdentificationNo = "234243";
            // line1.TaxOverride = new TaxOverrideDef();
            // line1.TaxOverride.TaxOverrideType = "TaxDate";
            // line1.TaxOverride.Reason = "Adjustment for return";
            // line1.TaxOverride.TaxDate = "2013-07-01";
            // line1.TaxOverride.TaxAmount = "0";

            // Optional Request Parameters
            line1.Ref1 = "ref123";
            line1.Ref2 = "ref456";

            Line line2 = new Line();

            line2.LineNo          = "02";
            line2.ItemCode        = "T345";
            line2.Qty             = 3;
            line2.Amount          = 150;
            line2.OriginCode      = "01";
            line2.DestinationCode = "03";
            line2.Description     = "Size 10 Green Running Shoe";
            line2.TaxCode         = "PC030147";

            Line line3 = new Line();

            line3.LineNo          = "02-FR";
            line3.ItemCode        = "FREIGHT";
            line3.Qty             = 1;
            line3.Amount          = 15;
            line3.OriginCode      = "01";
            line3.DestinationCode = "03";
            line3.Description     = "Shipping Charge";
            line3.TaxCode         = "FR";
            Line[] lines = { line1, line2, line3 };
            getTaxRequest.Lines = lines;

            GetTaxResult getTaxResult = taxSvc.GetTax(getTaxRequest);

            // Print results
            Console.WriteLine("GetTaxTest Result: " + getTaxResult.ResultCode.ToString());
            if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in getTaxResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
            else
            {
                Console.WriteLine("Document Code: " + getTaxResult.DocCode + " Total Tax: " + getTaxResult.TotalTax);
                foreach (TaxLine taxLine in getTaxResult.TaxLines ?? Enumerable.Empty <TaxLine>())
                {
                    Console.WriteLine("    " + "Line Number: " + taxLine.LineNo + " Line Tax: " + taxLine.Tax.ToString());
                    foreach (TaxDetail taxDetail in taxLine.TaxDetails ?? Enumerable.Empty <TaxDetail>())
                    {
                        Console.WriteLine("        " + "Jurisdiction: " + taxDetail.JurisName + "Tax: " + taxDetail.Tax.ToString());
                    }
                }
            }
        }