private void buttonAuthorized_Click(object sender, System.EventArgs e) { if (textOperations.Text == "") { MessageBox.Show("Please insert the method name(s).", "Autherization Result", MessageBoxButtons.OK, MessageBoxIcon.Information); textOperations.Focus(); return; } else { try { this.Cursor = Cursors.WaitCursor; ApplySettings(); // if(_parent.UserName!=null||_parent.Password!=null) // settings = _parent.UserName+","+_parent.Password; //textUserName.Text+","+textPassword.Text; TaxSvc taxSvc = new TaxSvc(); _parent.SetConfig(taxSvc); // PingResult result = taxSvc.Ping(""); // if(result.ResultCode >= SeverityLevel.Error) // { // MessageBox.Show(result.Messages[0].Summary, "Ping Result", MessageBoxButtons.OK, MessageBoxIcon.Error); // } // else // { String operations = textOperations.Text.Replace(" ", ","); IsAuthorizedResult isAuthorizedResult = taxSvc.IsAuthorized(operations.Trim()); if (isAuthorizedResult.ResultCode >= SeverityLevel.Error) { MessageBox.Show(isAuthorizedResult.Messages[0].Summary, "Authorization Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (isAuthorizedResult.Operations.Length == 0) { MessageBox.Show("User is not authorized to listed method(s).", "Authorization Result", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Operation(s) authorized: " + isAuthorizedResult.Operations, "Authorization Result", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { Util.ShowError(ex); } finally { RejectChanges(settings); this.Cursor = Cursors.Default; } } }
private void buttonPing_Click(object sender, EventArgs e) { try { Util.PreMethodCall(this, lblStatus); TaxSvc taxSvc = new TaxSvc(); SetConfig(taxSvc); PingResult result = taxSvc.Ping(""); if (result.ResultCode >= SeverityLevel.Error) { MessageBox.Show(result.Messages[0].Summary, "Ping Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Result Code: " + result.ResultCode + "\r\n" + "# Messages: " + result.Messages.Count.ToString() + "\r\n" + "Service Version: " + result.Version, "Ping Result", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { Util.ShowError(ex); } finally { Util.PostMethodCall(this, lblStatus); } }
public static CommitTaxResult Execute(bool inProduction, string strOCN, out string summary) { summary = ""; TaxServiceWrapper taxSvcWrapper = new TaxServiceWrapper(); TaxSvc taxSvc = taxSvcWrapper.GetTaxSvcInstance(inProduction); CommitTaxRequest commitTaxRequest = new CommitTaxRequest(); // Required Parameters commitTaxRequest.DocCode = strOCN; commitTaxRequest.DocType = DocumentType.SalesInvoice; commitTaxRequest.CompanyCode = Properties.Settings.Default.CompanyCode; // Optional Parameters //commitTaxRequest.NewDocCode = "INV001"; CommitTaxResult commitTaxResult = taxSvc.CommitTax(commitTaxRequest); if (!commitTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in commitTaxResult.Messages) { summary = message.Summary; } } return(commitTaxResult); }
public static AdjustTaxResult Execute(CustomerOrder refundOrder, out string summary) { summary = ""; TaxServiceWrapper taxSvcWrapper = new TaxServiceWrapper(); TaxSvc taxSvc = taxSvcWrapper.GetTaxSvcInstance(refundOrder.InProduction); AdjustTaxRequest adjustTaxRequest = new AdjustTaxRequest(); GetTaxRequest getTaxRequest = GetTax.BuildGetTaxRequest(refundOrder); getTaxRequest.TaxOverride.TaxOverrideType = TaxOverrideType.TaxAmount; getTaxRequest.TaxOverride.Reason = "Adjustment for router return"; //getTaxRequest.TaxOverride.TaxDate = DateTime.Parse("2013-07-01"); getTaxRequest.TaxOverride.TaxAmount = refundOrder.TotalTax; getTaxRequest.ServiceMode = ServiceMode.Automatic; adjustTaxRequest.GetTaxRequest = getTaxRequest; adjustTaxRequest.AdjustmentReason = 5; adjustTaxRequest.AdjustmentDescription = "Tax adjusted based on router refund"; AdjustTaxResult adjustTaxResult = taxSvc.AdjustTax(adjustTaxRequest); if (!adjustTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in adjustTaxResult.Messages) { summary = message.Summary; } } return(adjustTaxResult); }
protected TaxSvc GetConfiguredTaxService() { var serviceUrl = customSettings.TaxCalculatorAvalaraTaxServiceURL; var accountNumber = customSettings.TaxCalculatorAvalaraTaxServiceAccount; var licenseKey = customSettings.TaxCalculatorAvalaraTaxServiceLicense; var userName = customSettings.TaxCalculatorAvalaraTaxServiceUserName; var password = customSettings.TaxCalculatorAvalaraTaxServicePassword; if (!string.IsNullOrEmpty(serviceUrl) && !string.IsNullOrEmpty(accountNumber) && !string.IsNullOrEmpty(licenseKey) && !string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password)) { TaxSvc taxSvc = new TaxSvc(); taxSvc.Configuration.RequestTimeout = 300; taxSvc.Profile.Client = "InSite eCommerce"; taxSvc.Configuration.Security.Account = accountNumber; taxSvc.Configuration.Security.License = licenseKey; taxSvc.Configuration.Security.UserName = userName; taxSvc.Configuration.Security.Password = password; taxSvc.Configuration.Url = serviceUrl; taxSvc.Configuration.ViaUrl = serviceUrl; taxSvc.Profile.Name = "Brasseler"; return(taxSvc); } LogHelper.For((object)this).Error("Avalara Tax Service is not configured completely in Commerce App Settings", "TaxCalculator_Avalara"); throw new InvalidOperationException("Avalara Tax Service is not configured completely in Commerce App Settings"); }
public static PostTaxResult Execute(CustomerOrder order, Avalara.AvaTax.Adapter.TaxService.GetTaxResult getTaxResult, out string summary) { summary = ""; TaxServiceWrapper taxSvcWrapper = new TaxServiceWrapper(); TaxSvc taxSvc = taxSvcWrapper.GetTaxSvcInstance(order.InProduction); PostTaxRequest postTaxRequest = new PostTaxRequest(); // Required Request Parameters postTaxRequest.CompanyCode = Properties.Settings.Default.CompanyCode; postTaxRequest.DocType = DocumentType.SalesInvoice; postTaxRequest.DocCode = getTaxResult.DocCode; postTaxRequest.Commit = order.IsCommit; postTaxRequest.DocDate = getTaxResult.DocDate; postTaxRequest.TotalTax = order.TotalTax; postTaxRequest.TotalAmount = order.TotalAmount; // Optional Request Parameters postTaxRequest.NewDocCode = order.OCN; PostTaxResult postTaxResult = taxSvc.PostTax(postTaxRequest); if (!postTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in postTaxResult.Messages) { summary = message.Summary; } } return(postTaxResult); }
public static void Test() { string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"]; string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"]; string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"]; TaxSvc taxSvc = new TaxSvc(); // Header Level Parameters // Required Header Parameters taxSvc.Configuration.Security.Account = accountNumber; taxSvc.Configuration.Security.License = licenseKey; taxSvc.Configuration.Url = serviceURL; taxSvc.Configuration.ViaUrl = serviceURL; taxSvc.Profile.Client = "AvaTaxSample"; // Optional Header Parameters taxSvc.Profile.Name = "Development"; PingResult pingResult = taxSvc.Ping(string.Empty); Console.WriteLine("PingTest Result: " + pingResult.ResultCode.ToString()); if (!pingResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in pingResult.Messages) { Console.WriteLine(message.Summary); } } }
public IHttpActionResult CartTotal(ShoppingCart cart) { 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 = cart.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>()) { cart.Items.ToArray()[Int32.Parse(taxLine.LineNo)].TaxTotal = taxLine.Tax; //foreach (TaxDetail taxDetail in taxLine.TaxDetails ?? Enumerable.Empty<TaxDetail>()) //{ //} } cart.TaxTotal = getTaxResult.TotalTax; } } else { return(BadRequest()); } return(Ok(cart)); }
public static void CalculateAvalaraTax(OpportunityMaint rg, CROpportunity order) { TaxSvc service = new TaxSvc(); AvalaraMaint.SetupService(rg, service); AddressSvc addressService = new AddressSvc(); AvalaraMaint.SetupService(rg, addressService); GetTaxRequest getRequest = null; bool isValidByDefault = true; if (order.IsTaxValid != true) { getRequest = BuildGetTaxRequest(rg, order); if (getRequest.Lines.Count > 0) { isValidByDefault = false; } else { getRequest = null; } } if (isValidByDefault) { PXDatabase.Update <CROpportunity>( new PXDataFieldAssign("IsTaxValid", true), new PXDataFieldRestrict("OpportunityID", PXDbType.NVarChar, CROpportunity.OpportunityIDLength, order.OpportunityID, PXComp.EQ) ); return; } GetTaxResult result = service.GetTax(getRequest); if (result.ResultCode == SeverityLevel.Success) { try { ApplyAvalaraTax(rg, order, result); PXDatabase.Update <CROpportunity>( new PXDataFieldAssign("IsTaxValid", true), new PXDataFieldRestrict("OpportunityID", PXDbType.NVarChar, CROpportunity.OpportunityIDLength, order.OpportunityID, PXComp.EQ) ); } catch (Exception ex) { throw new PXException(ex, TX.Messages.FailedToApplyTaxes); } } else { LogMessages(result); throw new PXException(TX.Messages.FailedToGetTaxes); } }
public void PostTax(OriginAddress originAddress, CustomerOrder customerOrder) { if (!this.AvalaraSettings.PostTaxes) // Added condition to check post taxes setting { return; } string str = string.Empty; if (ValidateOrderAddressForAvalara(customerOrder)) { try { GetTaxRequest requestFromOrder1 = GetCalcTaxRequestFromOrder(originAddress, customerOrder, DocumentType.SalesInvoice); PostTaxRequest requestFromOrder2 = GetPostTaxRequestFromOrder(customerOrder); TaxSvc configuredTaxService = GetConfiguredTaxService(); configuredTaxService.GetTax(requestFromOrder1); str = this.ProcessAvalaraResponseMessage(configuredTaxService.PostTax(requestFromOrder2)); } catch (Exception ex) { LogHelper.For(this).Error("Error running Avalara PostTax method: " + ex.Message, "TaxCalculator_Avalara"); throw; } } else { LogHelper.For(this).Debug("The billto/shipto customer does not have an address specified. In order to calculate tax this must be set up.", "TaxCalculator_Avalara"); return; } if (string.IsNullOrEmpty(str)) { return; } LogHelper.For(this).Debug(str, "Avalara Result, PostTax: "); }
private void buttonTestConnection_Click(object sender, System.EventArgs e) { //string settings = ""; //if(_parent.Account != null||_parent.Key!= null||_parent.UserName!=null||_parent.Password!=null) // settings = textAccount.Text +","+ textKey.Text +","+textUserName.Text+","+textPassword.Text; try { this.Cursor = Cursors.WaitCursor; ApplySettings(); TaxSvc taxSvc = new TaxSvc(); _parent.SetConfig(taxSvc); PingResult result = taxSvc.Ping(""); if (result.ResultCode >= SeverityLevel.Error) { MessageBox.Show(result.Messages[0].Summary, "Settings Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { IsAuthorizedResult isAuthorizedResult = taxSvc.IsAuthorized("GetTax, PostTax, CommitTax, CancelTax, AdjustTax, GetTaxHistory, ReconcileTaxHistory"); if (isAuthorizedResult.ResultCode >= SeverityLevel.Error) { //Util.ShowError(ex); MessageBox.Show(isAuthorizedResult.Messages[0].Summary, "Settings Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { isConnectionSuccess = true; MessageBox.Show("Result Code: " + isAuthorizedResult.ResultCode + "\r\n" + "# Messages: " + isAuthorizedResult.Messages.Count + "\r\n" + "Expires: " + isAuthorizedResult.Expires + "\r\n" + "Operations: " + isAuthorizedResult.Operations, "Settings Result", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { isConnectionSuccess = false; Util.ShowError(ex); } finally { RejectChanges(settings); if (isConnectionSuccess) { buttonApply.Enabled = true; } else { buttonApply.Enabled = false; } this.Cursor = Cursors.Default; } }
public void OrderPlaced(Order order) { if (!Enabled) { throw new InvalidOperationException("AvalaraInactiveException"); } var customer = new Customer(order.CustomerID); var cartItems = order.CartItems; var orderOptions = GetOrderOptions(order); // Create line items for all cart items and shipping selections var cartItemAddressGroups = GroupCartItemsByShippingAddress(cartItems, customer.PrimaryShippingAddressID); var lineItems = CreateItemAndShippingLineItems(cartItemAddressGroups, (shipmentAddressId, shipmentAddress, shipmentCartItems) => CreateOrderShippingLineItem(shipmentAddress, shipmentCartItems, order, shipmentAddressId)); // Create line items for order options using the first shipping address as the destination var firstShippingAddress = LoadAvalaraAddress(cartItemAddressGroups.First().Key); lineItems = lineItems.Concat(CreateOrderOptionLineItems(orderOptions, firstShippingAddress)); // Calculate the discount from the promotion usages for this order decimal discountAmount; using (var promotionsDataContext = new AspDotNetStorefront.Promotions.Data.EntityContextDataContext()) { discountAmount = promotionsDataContext.PromotionUsages .Where(pu => pu.OrderId == order.OrderNumber) .Where(pu => pu.Complete) .Sum(pu => - pu.OrderDiscountAmount) // Avalara expects a positive number .GetValueOrDefault(0); } // Build and submit the tax request GetTaxRequest taxRequest = BuildTaxRequest(customer, GetOriginAddress(), DocumentType.SalesInvoice); taxRequest.Discount = discountAmount; taxRequest.DocCode = order.OrderNumber.ToString(); taxRequest.TaxOverride.TaxDate = order.OrderDate; // Add each line to the request, setting the line number sequentially int lineItemIndex = 0; foreach (var line in lineItems) { line.No = (++lineItemIndex).ToString(); taxRequest.Lines.Add(line); } TaxSvc taxService = CreateTaxService(); GetTaxResult taxResult = taxService.GetTax(taxRequest); foreach (Message message in taxResult.Messages) { LogErrorMessage(message); //this throws an exception } //not used currently //decimal taxAmount = taxResult.TotalTax; }
private void CalculateCustomerOrderTaxes(OrderChangeEvent context) { var order = context.ModifiedOrder; if (order.Items.Any()) { order.Items.ForEach(x => { x.Tax = 0; x.TaxDetails = null; }); } order.Tax = 0; if (_taxSettings.IsEnabled && !string.IsNullOrEmpty(_taxSettings.Username) && !string.IsNullOrEmpty(_taxSettings.Password) && !string.IsNullOrEmpty(_taxSettings.ServiceUrl) && !string.IsNullOrEmpty(_taxSettings.CompanyCode)) { var taxSvc = new TaxSvc(_taxSettings.Username, _taxSettings.Password, _taxSettings.ServiceUrl); var isCommit = order.InPayments != null && order.InPayments.Any() && order.InPayments.All(pi => pi.IsApproved); var request = order.ToAvaTaxRequest(_taxSettings.CompanyCode, isCommit); if (request != null) { var getTaxResult = taxSvc.GetTax(request); if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success)) { var error = string.Join(Environment.NewLine, getTaxResult.Messages.Select(m => m.Details)); OnError(new Exception(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.Items.ToArray()[Int32.Parse(taxLine.LineNo)].TaxDetails = new[] // { // new VirtoCommerce.Domain.Commerce.Model.TaxDetail // { // Amount = taxDetail.Tax, // Name = taxDetail.TaxName, // Rate = taxDetail.Rate // } // }; //} } order.Tax = getTaxResult.TotalTax; } } } else { OnError(new Exception("AvaTax credentials not provided")); } }
private void LoadConfig() { TaxSvc taxSvc = new TaxSvc(); Url = taxSvc.Configuration.Url; //ViaUrl = taxSvc.Configuration.ViaUrl; UserName = taxSvc.Configuration.Security.UserName; Password = taxSvc.Configuration.Security.Password; Account = taxSvc.Configuration.Security.Account; Key = taxSvc.Configuration.Security.License; }
protected TaxSvc CreateTaxService() { var assemblyVersion = System.Reflection.Assembly.GetAssembly(this.GetType()).GetName().Version; var taxService = new TaxSvc(); taxService.Configuration.Security.Account = Account; taxService.Configuration.Security.License = License; taxService.Configuration.Url = ServiceURL; taxService.Profile.Client = String.Format("AspDotNetStorefront,{0}.{1},{2}.{3},AspDotNetStorefront Avalara Tax Addin,{0}.{1},{2}.{3}", assemblyVersion.Major, assemblyVersion.MajorRevision, assemblyVersion.Minor, assemblyVersion.MinorRevision); return(taxService); }
/// <summary> /// 获取费用列表 /// </summary> /// <param name="rows">页大小</param> /// <param name="page">页索引</param> /// <returns></returns> public string GetTaxAndTaxRateList(string rows, string page) { int count = 0; string C_GUID = Session["CurrentCompany"].ToString(); string strFormatter = "{{\"total\":\"{0}\",\"rows\":{1}}}"; StringBuilder strJson = new StringBuilder(); List <T_Tax> List = new List <T_Tax>(); List = new TaxSvc().GetTax(C_GUID, int.Parse(page), int.Parse(rows), out count); strJson.AppendFormat(strFormatter, count, new JavaScriptSerializer().Serialize(List)); return(strJson.ToString()); }
public static void Test() { string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"]; string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"]; string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"]; TaxSvc taxSvc = new TaxSvc(); // Header Level Parameters // Required Header Parameters taxSvc.Configuration.Security.Account = accountNumber; taxSvc.Configuration.Security.License = licenseKey; taxSvc.Configuration.Url = serviceURL; taxSvc.Configuration.ViaUrl = serviceURL; taxSvc.Profile.Client = "AvaTaxSample"; // Optional Header Parameters taxSvc.Profile.Name = "Development"; GetTaxHistoryRequest getTaxHistoryRequest = new GetTaxHistoryRequest(); // Required Request Parameters getTaxHistoryRequest.CompanyCode = "APITrialCompany"; getTaxHistoryRequest.DocType = DocumentType.SalesInvoice; getTaxHistoryRequest.DocCode = "INV001"; // Optional Request Parameters getTaxHistoryRequest.DetailLevel = DetailLevel.Tax; GetTaxHistoryResult getTaxHistoryResult = taxSvc.GetTaxHistory(getTaxHistoryRequest); Console.WriteLine("GetTaxHistoryTest Result: " + getTaxHistoryResult.ResultCode.ToString()); if (!getTaxHistoryResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in getTaxHistoryResult.Messages) { Console.WriteLine(message.Summary); } } else { Console.WriteLine("Document Code: " + getTaxHistoryResult.GetTaxResult.DocCode + " Total Tax: " + getTaxHistoryResult.GetTaxResult.TotalTax); foreach (TaxLine taxLine in getTaxHistoryResult.GetTaxResult.TaxLines) { Console.WriteLine(" " + "Line Number: " + taxLine.No + " Line Tax: " + taxLine.Tax.ToString()); foreach (TaxDetail taxDetail in taxLine.TaxDetails) { Console.WriteLine(" " + "Jurisdiction: " + taxDetail.JurisName + " Tax: " + taxDetail.Tax.ToString()); } } } }
public TaxSvc GetTaxSvcInstance(bool inProduction) { TaxSvc taxSvc = new TaxSvc(); taxSvc.Configuration.Url = Properties.Settings.Default.ServiceUrl; taxSvc.Configuration.ViaUrl = Properties.Settings.Default.ServiceUrl; taxSvc.Profile.Client = Properties.Settings.Default.Client; taxSvc.Configuration.Security.UserName = Properties.Settings.Default.UserName; taxSvc.Configuration.Security.Password = Properties.Settings.Default.Password; taxSvc.Profile.Name = inProduction ? "Production" : "Development"; return(taxSvc); }
/// <summary> /// 获取税种列表 /// </summary> /// <returns></returns> public string GetTaxAndTaxRateList() { int count = 0; string C_GUID = Session["CurrentCompanyGuid"].ToString(); StringBuilder strJson = new StringBuilder(); List <T_Tax> List = new List <T_Tax>(); List = new TaxSvc().GetTax(C_GUID); string json = new JavaScriptSerializer().Serialize(List); return(json); }
private void buttonGetTaxHistory_Click(object sender, EventArgs e) { try { //######################################################################### //### 1st WE CREATE THE REQUEST OBJECT FOR THE DOCUMENT HISTORY WE WANT ### //######################################################################### GetTaxHistoryRequest getTaxHistoryRequest = new GetTaxHistoryRequest(); //########################################################### //### 2nd WE LOAD THE REQUEST-LEVEL DATA INTO THE REQUEST ### //########################################################### getTaxHistoryRequest.CompanyCode = textCompanyCode.Text; getTaxHistoryRequest.DocCode = textDocCode.Text; getTaxHistoryRequest.DocType = (DocumentType)comboDocType.SelectedItem; getTaxHistoryRequest.DetailLevel = (DetailLevel)cboDetailLevel.SelectedItem; //################################################################################################## //### 3rd WE INVOKE THE GETTAXHISTORY() METHOD OF THE TAXSVC OBJECT AND GET BACK A RESULT OBJECT ### //################################################################################################## Util.PreMethodCall(this, lblStatus); TaxSvc taxSvc = new TaxSvc(); ((formMain)this.Owner).SetConfig(taxSvc); //set the Url and Security configuration _getTaxHistoryResult = taxSvc.GetTaxHistory(getTaxHistoryRequest); Util.PostMethodCall(this, lblStatus); //##################################### //### 4th WE READ THE RESULT OBJECT ### //##################################### lblResultCode.Text = _getTaxHistoryResult.ResultCode.ToString(); Util.SetMessageLabelText(lblResultMsg, _getTaxHistoryResult); _getTaxRequest = _getTaxHistoryResult.GetTaxRequest; _getTaxResult = _getTaxHistoryResult.GetTaxResult; buttonGetTaxRequest.Enabled = (_getTaxRequest != null); buttonGetTaxResult.Enabled = (_getTaxResult != null); getTaxHistoryRequest = null; taxSvc = null; } catch (Exception ex) { Util.ShowError(ex); } finally { Util.PostMethodCall(this, lblStatus); } }
private void SaveConfigSettings() { TaxSvc taxSvc = new TaxSvc(); taxSvc.Configuration.Url = _parent.Url; //taxSvc.Configuration.ViaUrl = _parent.ViaUrl; taxSvc.Configuration.Security.Account = _parent.Account; taxSvc.Configuration.Security.License = _parent.Key; taxSvc.Configuration.Security.UserName = _parent.UserName; taxSvc.Configuration.Security.Password = _parent.Password; //taxSvc.Configuration.Save (); }
public static decimal GetTax(int orderId, bool UpdateOrderTax, bool CartTax, ClientCartContext clientData) { decimal taxAmount = 0M; try { XmlNode config = null; config = GetTax_AvalaraConfig(); string accountNumber = config.Attributes["accountNumber"].Value; string licenseKey = config.Attributes["licenseKey"].Value; string serviceURL = config.Attributes["serviceURL"].Value; TaxSvc taxSvc = new TaxSvc(accountNumber, licenseKey, serviceURL); GetTaxRequest getTaxRequest = GetTax_Request(orderId, UpdateOrderTax, CartTax, clientData); XmlSerializerNamespaces namesp = new XmlSerializerNamespaces(); namesp.Add(string.Empty, string.Empty); XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; XmlSerializer x1 = new XmlSerializer(getTaxRequest.GetType()); StringBuilder sb = new StringBuilder(); x1.Serialize(XmlTextWriter.Create(sb, settings), getTaxRequest, namesp); string req = sb.ToString(); int timeout = getTimeOutTax(); // This is for Request TimeOut GetTaxResult getTaxResult = taxSvc.GetTax(getTaxRequest, timeout); XmlSerializer x2 = new XmlSerializer(getTaxResult.GetType()); StringBuilder sb2 = new StringBuilder(); x2.Serialize(XmlTextWriter.Create(sb2, settings), getTaxResult, namesp); string res = sb2.ToString(); if (getTaxResult.ResultCode.Equals(SeverityLevel.Success)) { taxAmount = getTaxResult.TotalTax; } if (UpdateOrderTax && orderId > 0) { CSResolve.Resolve <IOrderService>().UpdateOrderTax(orderId, taxAmount); Dictionary <string, AttributeValue> orderAttributes = new Dictionary <string, AttributeValue>(); orderAttributes.Add("TaxRequest", new CSBusiness.Attributes.AttributeValue(req)); orderAttributes.Add("TaxResponse", new CSBusiness.Attributes.AttributeValue(res)); CSResolve.Resolve <IOrderService>().UpdateOrderAttributes(orderId, orderAttributes, null); } } catch { } return(taxAmount); }
private void buttonCommitTax_Click(object sender, EventArgs e) { try { //############################################################################## //### 1st WE CREATE THE REQUEST OBJECT FOR DOCUMENT THAT SHOULD BE COMMITTED ### //############################################################################## CommitTaxRequest commitTaxRequest = new CommitTaxRequest(); //########################################################### //### 2nd WE LOAD THE REQUEST-LEVEL DATA INTO THE REQUEST ### //########################################################### commitTaxRequest.CompanyCode = textCompanyCode.Text; commitTaxRequest.DocType = (DocumentType)comboDocType.SelectedItem; commitTaxRequest.DocCode = textDocCode.Text; commitTaxRequest.NewDocCode = textNewDocCode.Text; //############################################################################################## //### 3rd WE INVOKE THE COMMITTAX() METHOD OF THE TAXSVC OBJECT AND GET BACK A RESULT OBJECT ### //############################################################################################## Util.PreMethodCall(this, lblStatus); TaxSvc taxSvc = new TaxSvc(); ((formMain)this.Owner).SetConfig(taxSvc); //set the Url and Security configuration _commitTaxResult = taxSvc.CommitTax(commitTaxRequest); Util.PostMethodCall(this, lblStatus); //##################################### //### 4th WE READ THE RESULT OBJECT ### //##################################### lblResultCode.Text = _commitTaxResult.ResultCode.ToString(); Util.SetMessageLabelText(lblResultMsg, _commitTaxResult); commitTaxRequest = null; taxSvc = null; } catch (Exception ex) { Util.ShowError(ex); } finally { Util.PostMethodCall(this, lblStatus); } }
/// <summary> /// 获取税种 /// </summary> /// <returns></returns> public string GetTaxList(string TaxPayer) { string C_GUID = Session["CurrentCompanyGuid"].ToString(); if (TaxPayer == "1") { var taxList = new TaxSvc().GetTax(C_GUID); var strJson = ConvertToSelectJson(taxList, "Name", "T_GUID"); return(strJson.ToString()); } else { var taxList = new TaxSvc().GetTax(C_GUID, TaxPayer); var strJson = ConvertToSelectJson(taxList, "Name", "T_GUID"); return(strJson.ToString()); } }
/// <summary> /// 新增申报预收客户款记录 /// </summary> /// <param name="form"></param> /// <returns></returns> public string UpdTaxAndTaxRate(T_Tax form) { bool result = false; string msg = string.Empty; form.C_GUID = Session["CurrentCompany"].ToString(); result = new TaxSvc().UpdTax(form); if (result) { msg = General.Resource.Common.Success; } else { msg = General.Resource.Common.Failed; } return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}" , result.ToString().ToLower(), msg)); }
public static TaxSvc Result() { const string salt = "7Jr&9%259*TSet%"; ConfigService.SetAppDomain(); var taxSvc = new TaxSvc(); taxSvc.Configuration.Security.Account = Encryption.Decrypt( System.Configuration.ConfigurationManager.AppSettings[ConfigService.AccountNumber()], salt); taxSvc.Configuration.Security.License = Encryption.Decrypt( System.Configuration.ConfigurationManager.AppSettings[ConfigService.LicenseKey()], salt); taxSvc.Configuration.Url = Encryption.Decrypt(System.Configuration.ConfigurationManager.AppSettings[ConfigService.ServiceUrl()], salt); taxSvc.Configuration.ViaUrl = Encryption.Decrypt( System.Configuration.ConfigurationManager.AppSettings[ConfigService.ServiceUrl()], salt); taxSvc.Profile.Client = Encryption.Decrypt(System.Configuration.ConfigurationManager.AppSettings[ConfigService.ProfileClient()], salt); taxSvc.Profile.Name = Encryption.Decrypt(System.Configuration.ConfigurationManager.AppSettings[ConfigService.ProfileName()], salt); return taxSvc; }
/// <summary> /// 删除税种 /// </summary> /// <param name="form"></param> /// <returns></returns> public string DelTax(string Tguid) { bool result = false; string msg = string.Empty; //C_GUID = Session["CurrentCompanyGuid"].ToString(); result = new TaxSvc().DelTax(Tguid); if (result) { msg = General.Resource.Common.Success; } else { msg = General.Resource.Common.Failed; } return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}" , result.ToString().ToLower(), msg)); }
public static void Test() { string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"]; string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"]; string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"]; TaxSvc taxSvc = new TaxSvc(); // Header Level Parameters // Required Header Parameters taxSvc.Configuration.Security.Account = accountNumber; taxSvc.Configuration.Security.License = licenseKey; taxSvc.Configuration.Url = serviceURL; taxSvc.Configuration.ViaUrl = serviceURL; taxSvc.Profile.Client = "AvaTaxSample"; // Optional Header Parameters taxSvc.Profile.Name = "Development"; PostTaxRequest postTaxRequest = new PostTaxRequest(); // Required Request Parameters postTaxRequest.CompanyCode = "APITrialCompany"; postTaxRequest.DocType = DocumentType.SalesInvoice; postTaxRequest.DocCode = "INV001"; postTaxRequest.Commit = false; postTaxRequest.DocDate = DateTime.Parse("2014-01-01"); postTaxRequest.TotalTax = (decimal)14.27; postTaxRequest.TotalAmount = 175; // Optional Request Parameters postTaxRequest.NewDocCode = "INV001-1"; PostTaxResult postTaxResult = taxSvc.PostTax(postTaxRequest); Console.WriteLine("PostTaxTest Result: " + postTaxResult.ResultCode.ToString()); if (!postTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in postTaxResult.Messages) { Console.WriteLine(message.Summary); } } }
/// <summary> /// Stops the monitoring clock. /// </summary> public void Stop(TaxSvc svc, string transactionId) { _end = DateTime.Now; if (!_running) { throw new ApplicationException("An attempt was made to stop the performance timekeeper that was not running. Call the Start method prior to calling Stop method."); } try { //call Ping Method and send ClientMetric svc.Ping(Utilities.BuildAuditMetrics("", transactionId, _end.Subtract(_start).Milliseconds)); } catch (Exception ex) { _avaLog.Error(string.Format("Error sending ClientMetrics: {0}", ex.Message)); } _running = false; }
private void buttonAbout_Click(object sender, EventArgs e) { try { Util.PreMethodCall(this, lblStatus); TaxSvc taxSvc = new TaxSvc(); MessageBox.Show("About (Version): " + taxSvc.Profile.Adapter, "About Result", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { Util.ShowError(ex); } finally { Util.PostMethodCall(this, lblStatus); } }
private TaxSvc GetTaxServiceProxy() { var svc = new TaxSvc(); svc.Profile.Client = "Hotcakes Commerce"; if (Url != null) { svc.Configuration.Url = Url; } if (Account != null && Account.Length > 0) { svc.Configuration.Security.Account = Account; } if (License != null && License.Length > 0) { svc.Configuration.Security.License = License; } return(svc); }
public void SetConfig(TaxSvc svc) { svc.Profile.Client = "AdapterSampleCode,1.0"; if (Url != null) { svc.Configuration.Url = Url; } if (Account != null && Account.Length > 0) { svc.Configuration.Security.Account = Account; } if (Key != null && Key.Length > 0) { svc.Configuration.Security.License = Key; } svc.Configuration.Security.UserName = UserName; //write as plain text svc.Configuration.Security.Password = Password; }
public static void Test() { string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"]; string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"]; string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"]; TaxSvc taxSvc = new TaxSvc(); // Header Level Parameters // Required Header Parameters taxSvc.Configuration.Security.Account = accountNumber; taxSvc.Configuration.Security.License = licenseKey; taxSvc.Configuration.Url = serviceURL; taxSvc.Configuration.ViaUrl = serviceURL; taxSvc.Profile.Client = "AvaTaxSample"; // Optional Header Parameters taxSvc.Profile.Name = "Development"; CommitTaxRequest commitTaxRequest = new CommitTaxRequest(); // Required Parameters commitTaxRequest.DocCode = "INV001-1"; commitTaxRequest.DocType = DocumentType.SalesInvoice; commitTaxRequest.CompanyCode = "APITrialCompany"; // Optional Parameters commitTaxRequest.NewDocCode = "INV001"; CommitTaxResult commitTaxResult = taxSvc.CommitTax(commitTaxRequest); Console.WriteLine("CommitTaxTest Result: " + commitTaxResult.ResultCode.ToString()); if (!commitTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in commitTaxResult.Messages) { Console.WriteLine(message.Summary); } } }
public static GetTaxResult Execute(CustomerOrder order, out string summary) { summary = ""; TaxServiceWrapper taxSvcWrapper = new TaxServiceWrapper(); TaxSvc taxSvc = taxSvcWrapper.GetTaxSvcInstance(order.InProduction); PostTaxRequest postTaxRequest = new PostTaxRequest(); GetTaxRequest getTaxRequest = BuildGetTaxRequest(order); GetTaxResult getTaxResult = taxSvc.GetTax(getTaxRequest); if (!getTaxResult.ResultCode.Equals(SeverityLevel.Success)) { foreach (Message message in getTaxResult.Messages) { summary = message.Summary; } } return(getTaxResult); }
private void VoidRefunds(Order order) { TaxSvc taxService = CreateTaxService(); int numberOfRefundTransactions = (order.ChildOrderNumbers ?? String.Empty).Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Length; for (int i = 1; i <= numberOfRefundTransactions; i++) { CancelTaxRequest cancelTaxRequest = new CancelTaxRequest { CancelCode = CancelCode.DocVoided, CompanyCode = CompanyCode, DocCode = order.OrderNumber.ToString() + "." + i.ToString(), DocType = DocumentType.ReturnInvoice, }; var cancelTaxResult = taxService.CancelTax(cancelTaxRequest); foreach (Message message in cancelTaxResult.Messages) { LogErrorMessage(message); } } }
public static void Test() { string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"]; string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"]; string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"]; TaxSvc taxSvc = new TaxSvc(); // Header Level Parameters // Required Header Parameters taxSvc.Configuration.Security.Account = accountNumber; taxSvc.Configuration.Security.License = licenseKey; taxSvc.Configuration.Url = serviceURL; taxSvc.Configuration.ViaUrl = serviceURL; taxSvc.Profile.Client = "AvaTaxSample"; // Optional Header Parameters taxSvc.Profile.Name = "Development"; GetTaxRequest getTaxRequest = new GetTaxRequest(); // Document Level Parameters // Required Request Parameters getTaxRequest.CustomerCode = "ABC4335"; getTaxRequest.DocDate = DateTime.Parse("2014-01-01"); //// getTaxRequest.Lines is also required, and is presented later in this file. // Best Practice Request Parameters getTaxRequest.CompanyCode = "APITrialCompany"; getTaxRequest.DocCode = "INV001"; getTaxRequest.DetailLevel = DetailLevel.Tax; getTaxRequest.Commit = false; getTaxRequest.DocType = DocumentType.SalesInvoice; // Situational Request Parameters // getTaxRequest.BusinessIdentificationNo = "234243"; // getTaxRequest.CustomerUsageType = "G"; // getTaxRequest.ExemptionNo = "12345"; // getTaxRequest.Discount = 50; // getTaxRequest.LocationCode = "01"; // getTaxRequest.TaxOverride.TaxOverrideType = TaxOverrideType.TaxDate; // getTaxRequest.TaxOverride.Reason = "Adjustment for return"; // getTaxRequest.TaxOverride.TaxDate = DateTime.Parse("2013-07-01"); // getTaxRequest.TaxOverride.TaxAmount = 0; // getTaxRequest.ServiceMode = ServiceMode.Automatic; // Optional Request Parameters getTaxRequest.PurchaseOrderNo = "PO123456"; getTaxRequest.ReferenceCode = "ref123456"; getTaxRequest.PosLaneCode = "09"; getTaxRequest.CurrencyCode = "USD"; getTaxRequest.ExchangeRate = (decimal)1.0; getTaxRequest.ExchangeRateEffDate = DateTime.Parse("2013-01-01"); getTaxRequest.SalespersonCode = "Bill Sales"; // Address Data Address address1 = new Address(); address1.Line1 = "45 Fremont Street"; address1.City = "San Francisco"; address1.Region = "CA"; Address address2 = new Address(); 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.Latitude = "47.627935"; address3.Longitude = "-122.51702"; // Line Data // Required Parameters Line line1 = new Line(); line1.No = "01"; line1.ItemCode = "N543"; line1.Qty = 1; line1.Amount = 10; line1.OriginAddress = address1; line1.DestinationAddress = address2; // Best Practice Request Parameters line1.Description = "Red Size 7 Widget"; line1.TaxCode = "NT"; // Situational Request Parameters // line1.CustomerUsageType = "L"; // line1.ExemptionNo = "12345"; // line1.Discounted = true; // line1.TaxIncluded = true; // line1.TaxOverride.TaxOverrideType = TaxOverrideType.TaxDate; // line1.TaxOverride.Reason = "Adjustment for return"; // line1.TaxOverride.TaxDate = DateTime.Parse("2013-07-01"); // line1.TaxOverride.TaxAmount = 0; // Optional Request Parameters line1.Ref1 = "ref123"; line1.Ref2 = "ref456"; getTaxRequest.Lines.Add(line1); Line line2 = new Line(); line2.No = "02"; line2.ItemCode = "T345"; line2.Qty = 3; line2.Amount = 150; line2.OriginAddress = address1; line2.DestinationAddress = address3; line2.Description = "Size 10 Green Running Shoe"; line2.TaxCode = "PC030147"; getTaxRequest.Lines.Add(line2); Line line3 = new Line(); line3.No = "02-FR"; line3.ItemCode = "FREIGHT"; line3.Qty = 1; line3.Amount = 15; line3.OriginAddress = address1; line3.DestinationAddress = address3; line3.Description = "Shipping Charge"; line3.TaxCode = "FR"; getTaxRequest.Lines.Add(line3); GetTaxResult getTaxResult = taxSvc.GetTax(getTaxRequest); 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) { Console.WriteLine(" " + "Line Number: " + taxLine.No + " Line Tax: " + getTaxResult.TotalTax.ToString()); foreach (TaxDetail taxDetail in taxLine.TaxDetails) { Console.WriteLine(" " + "Jurisdiction: " + taxDetail.JurisName + " Tax: " + taxDetail.Tax.ToString()); } } } }