public void SetConfig(AddressSvc svc)
        {
            svc.Profile.Client = "AdapterSampleCode,1.0";

            if (Url != null)
            {
                svc.Configuration.Url = Url;
            }
            if (ViaUrl != null)
            {
                svc.Configuration.ViaUrl = ViaUrl;
            }
            //this could be null if we haven't set the plain-text via the Security dialog
            if (Account != null)
            {
                svc.Configuration.Security.Account = Account;
            }
            //this could be null if we haven't set the plain-text via the Security dialog
            if (Key != null)
            {
                svc.Configuration.Security.License = Key;
            }
            svc.Configuration.Security.UserName = UserName;
            //write as plain text
            svc.Configuration.Security.Password = Password;
        }
Exemplo n.º 2
0
        public void Init()
        {
            try
            {
                _addressSvc = new AddressSvc();

                _addressSvc.Configuration.Url = ConfigurationSettings.AppSettings.Get("Url");

                //fill these only if they haven't been loaded from Avalara.AvaTax.Adapter.dll.config
                //if (_addressSvc.Configuration.Security.Account == null || _addressSvc.Configuration.Security.Account.Length == 0)
                //{
                _addressSvc.Configuration.Security.Account = ConfigurationSettings.AppSettings.Get("account");
                //}
                //if (_addressSvc.Configuration.Security.Key == null || _addressSvc.Configuration.Security.Key.Length == 0)
                //{
                _addressSvc.Configuration.Security.License = ConfigurationSettings.AppSettings.Get("key");
                //}

                //_addressSvc.Configuration.Security.Timeout = Convert.ToInt32(ConfigurationSettings.AppSettings.Get("timeout"));
                _addressSvc.Profile.Client = "NUnit AddressSvcTest";
                _addressSvc.Profile.Name   = "";
            }
            catch (Exception ex)
            {
                Assert.Fail("AddressSvc failed creation: " + ex.Message + " : " + ex.StackTrace);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Stops the monitoring clock.
        /// </summary>
        public void Stop(AddressSvc svc, ref Avalara.AvaTax.Adapter.Proxies.AddressSvcProxy.ProxyValidateResult result)
        {
            _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
            {
                if (Utilities.HasClientMetricMessage(result.Messages))
                {
                    //call Ping Method and send ClientMetric
                    //Sample Entry - ClientMetrics:17849,ClientDuration,1500
                    svc.Ping(Utilities.BuildAuditMetrics("", result.TransactionId, _end.Subtract(_start).Milliseconds));
                }
            }
            catch (Exception ex)
            {
                _avaLog.Error(string.Format("Error sending ClientMetrics: {0}", ex.Message));
            }

            _running = false;
        }
        private void buttonPing_Click(object sender, EventArgs e)
        {
            try
            {
                Util.PreMethodCall(this, lblStatus);

                AddressSvc addressSvc = new AddressSvc();
                SetConfig(addressSvc);

                PingResult result = addressSvc.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.ToString() + "\r\n" +
                                    "# Messages: " + result.Messages.Count + "\r\n" +
                                    "Service Version: " + result.Version, "Ping Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                Util.ShowError(ex);
            }
            finally
            {
                Util.PostMethodCall(this, lblStatus);
            }
        }
Exemplo n.º 6
0
        public bool ValidateAddress_Avalara(CSWeb.AvaTax.Address address)
        {
            bool    IsValidAddress = false;
            XmlNode config         = null;

            config = GetTax_AvalaraConfig();
            string     accountNumber = config.Attributes["accountNumber"].Value;
            string     licenseKey    = config.Attributes["licenseKey"].Value;
            string     serviceURL    = config.Attributes["serviceURL"].Value;
            AddressSvc AddressSvc1   = new AddressSvc(accountNumber, licenseKey, serviceURL);

            // Check for Address Line1 and Zipcode Only
            address.Line2  = "";
            address.City   = "";
            address.Region = "";
            int            timeout = getTimeOutAddressVerify(); // This is for Request TimeOut
            ValidateResult result  = AddressSvc1.Validate(address, timeout);

            if (result.ResultCode.Equals(SeverityLevel.Success) || result.ResultCode.Equals(SeverityLevel.Warning))
            {
                IsValidAddress = true;
            }
            else
            {
                IsValidAddress = false;
            }
            return(IsValidAddress);
        }
        public static void Test()
        {
            string accountNumber = ConfigurationManager.AppSettings["AvaTax:AccountNumber"];
            string licenseKey = ConfigurationManager.AppSettings["AvaTax:LicenseKey"];
            string serviceURL = ConfigurationManager.AppSettings["AvaTax:ServiceUrl"];

            AddressSvc addressSvc = new AddressSvc();

            // Header Level Parameters
            // Required Header Parameters
            addressSvc.Configuration.Security.Account = accountNumber;
            addressSvc.Configuration.Security.License = licenseKey;
            addressSvc.Configuration.Url = serviceURL;
            addressSvc.Configuration.ViaUrl = serviceURL;
            addressSvc.Profile.Client = "AvaTaxSample";

            // Optional Header Parameters
            addressSvc.Profile.Name = "Development";

            ValidateRequest validateRequest = new ValidateRequest();

            Address address = new Address();
            // Required Request Parameters
            address.Line1 = "118 N Clark St";
            address.City = "Chicago";
            address.Region = "IL";

            // Optional Request Parameters
            address.Line2 = "Suite 100";
            address.Line3 = "ATTN Accounts Payable";
            address.Country = "US";
            address.PostalCode = "60602";

            validateRequest.Address = address;
            validateRequest.Coordinates = true;
            validateRequest.Taxability = true;
            validateRequest.TextCase = TextCase.Upper;

            ValidateResult validateResult = addressSvc.Validate(validateRequest);

            Console.WriteLine("ValidateAddressTest Result: " + validateResult.ResultCode.ToString());
            if (!validateResult.ResultCode.Equals(SeverityLevel.Success))
            {
                foreach (Message message in validateResult.Messages)
                {
                    Console.WriteLine(message.Summary);
                }
            }
            else
            {
                Console.WriteLine(validateResult.Addresses[0].Line1
                    + " "
                    + validateResult.Addresses[0].City
                    + ", "
                    + validateResult.Addresses[0].Region
                    + " "
                    + validateResult.Addresses[0].PostalCode);
            }
        }
Exemplo n.º 8
0
        private void buttonTestConnection_Click(object sender, System.EventArgs e)
        {
            //string settings = "";
            bool isConnectionSuccess = false;

            //if(_parent.Account != null || _parent.Account != "" || _parent.Key!= null|| _parent.Key!=""||_parent.UserName!=null||_parent.UserName!=""||_parent.Password!=null||_parent.Password!="")
            //settings = textAccount.Text +","+ textKey.Text +","+textUserName.Text+","+textPassword.Text;

            try
            {
                this.Cursor = Cursors.WaitCursor;

                ApplySettings();

                AddressSvc addressSvc = new AddressSvc();
                _parent.SetConfig(addressSvc);

                PingResult result = addressSvc.Ping("");
                if (result.ResultCode >= SeverityLevel.Error)
                {
                    MessageBox.Show(result.Messages[0].Summary, "Settings Result", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    IsAuthorizedResult isAuthorizedResult = addressSvc.IsAuthorized("Validate");

                    if (isAuthorizedResult.ResultCode >= SeverityLevel.Error)
                    {
                        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;
            }
        }
Exemplo n.º 9
0
        public async Task <ValidateResult> ValidateAddress(AvaTax.LocationAddress address)
        {
            _locationAddress = address;
            AddressSvc addressSvc = new AddressSvc(_accountNumber, _licenseKey, _serviceUrl);

            ValidateResult validateResult = addressSvc.Validate(_locationAddress);

            return(await Task.FromResult(validateResult));
        }
        private void LoadConfig()
        {
            AddressSvc addressSvc = new AddressSvc();

            Url      = addressSvc.Configuration.Url;
            UserName = addressSvc.Configuration.Security.UserName;
            Password = addressSvc.Configuration.Security.Password;
            Account  = addressSvc.Configuration.Security.Account;
            Key      = addressSvc.Configuration.Security.License;
        }
Exemplo n.º 11
0
        private void SaveConfigSettings()
        {
            AddressSvc addressSvc = new AddressSvc();

            addressSvc.Configuration.Url = _parent.Url;

            addressSvc.Configuration.Security.Account  = _parent.Account;
            addressSvc.Configuration.Security.License  = _parent.Key;
            addressSvc.Configuration.Security.UserName = _parent.UserName;
            addressSvc.Configuration.Security.Password = _parent.Password;

            //addressSvc.Configuration.Save ();
        }
        private void buttonValidate_Click(object sender, System.EventArgs e)
        {
            try
            {
                //##############################################################################
                //### 1st WE CREATE THE REQUEST OBJECT FOR THE ADDRESS THAT NEEDS VALIDATION ###
                //##############################################################################
                Address address = new Address();
                address.Line1      = textLine1.Text;
                address.Line2      = textLine2.Text;
                address.Line3      = textLine3.Text;
                address.City       = textCity.Text;
                address.Region     = textState.Text;
                address.PostalCode = textZip.Text;
                address.Country    = textCountry.Text;

                //#################################################################################################
                //### 2nd WE INVOKE THE VALIDATE() METHOD OF THE ADDRESSSVC OBJECT AND GET BACK A RESULT OBJECT ###
                //#################################################################################################
                Util.PreMethodCall(this, lblStatus);

                AddressSvc addressSvc = new AddressSvc();
                SetConfig(addressSvc);                   //set user-defined config data

                ValidateRequest request = new ValidateRequest();
                request.Address  = address;
                request.TextCase = TextCase.Upper;

                ValidateResult result = addressSvc.Validate(request);

                Util.PostMethodCall(this, lblStatus);

                //#######################################
                //### 3rd WE REVIEW THE RESULT OBJECT ###
                //#######################################
                formResults frm = new formResults(result);
                frm.Owner = this;
                frm.ShowDialog();
            } catch (SoapException soapEx)
            {
                Util.ShowError(soapEx);
            }
            catch (Exception ex)
            {
                Util.ShowError(ex);
            } finally
            {
                Util.PostMethodCall(this, lblStatus);
            }
        }
Exemplo n.º 13
0
 public void Dispose()
 {
     try
     {
         if (_addressSvc != null)
         {
             _addressSvc.Dispose();
             _addressSvc = null;
         }
     }
     catch (Exception ex)
     {
         Assert.Fail("TearDown failed: " + ex.Message + " : " + ex.StackTrace);
     }
 }
Exemplo n.º 14
0
        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();
                    AddressSvc addressSvc = new AddressSvc();
                    _parent.SetConfig(addressSvc);

                    String             operations         = textOperations.Text.Replace(" ", ",");
                    IsAuthorizedResult isAuthorizedResult = addressSvc.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;
                }
            }
        }
Exemplo n.º 15
0
        public void Test()
        {
            AddressSvc adrssSvc = new AddressSvc();

            SetupService(this, adrssSvc);

            PingResult pres = adrssSvc.Ping("");

            if (pres.ResultCode == SeverityLevel.Success)
            {
                Setup.Ask(Setup.Current, Messages.AvalaraConnectSuccessAskHeader, PXMessages.LocalizeFormatNoPrefixNLA(Messages.AvalaraConnectSuccessAskMsg, pres.Version), MessageButtons.OK, MessageIcon.Information);
            }
            else
            {
                LogMessages(pres);
                throw new PXException(Messages.ConnectionToAvalaraFailed);
            }
        }
Exemplo n.º 16
0
        public void Test()
        {
            AddressSvc adrssSvc = new AddressSvc();

            SetupService(this, adrssSvc);

            PingResult pres = adrssSvc.Ping("");

            if (pres.ResultCode == SeverityLevel.Success)
            {
                string msg = string.Format("Connection to Avalara was successful. Version of service is {0}", pres.Version);
                Setup.Ask(Setup.Current, "Setup", msg, MessageButtons.OK, MessageIcon.Information);
            }
            else
            {
                LogMessages(pres);
                throw new PXException(Messages.ConnectionToAvalaraFailed);
            }
        }
        private void buttonAbout_Click(object sender, EventArgs e)
        {
            try
            {
                Util.PreMethodCall(this, lblStatus);

                AddressSvc addressSvc = new AddressSvc();

                MessageBox.Show("About (Version): " + addressSvc.Profile.Adapter, "About Adapter", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                Util.ShowError(ex);
            }
            finally
            {
                Util.PostMethodCall(this, lblStatus);
            }
        }
Exemplo n.º 18
0
        public string ValidateAddress(Customer customer, Address inputAddress, out Address ResultAddress)
        {
            //If coming from address.aspx do not include Avalara-specific string resources
            bool stringResourceInResult = inputAddress == null ? true : false;

            ResultAddress = new Address();
            if (!Enabled)
            {
                throw new InvalidOperationException("AvalaraInactiveException");
            }

            if (!customer.HasAtLeastOneAddress())
            {
                return(AppLogic.GetString("Avalara.AddressValidate.AtLeastOneAddress", customer.LocaleSetting));
            }

            var addrSvc = new AddressSvc();

            addrSvc.Configuration.Url = ServiceURL;
            addrSvc.Configuration.Security.Account = Account;
            addrSvc.Configuration.Security.License = License;

            //set address to validate and ensure ResultAddress returns non-blank address
            var addrReq = new ValidateRequest();

            if (inputAddress == null)
            {
                addrReq.Address = LoadAvalaraAddress(customer.PrimaryShippingAddressID);
                ResultAddress.LoadFromDB(customer.PrimaryShippingAddressID);
            }
            else
            {
                addrReq.Address = LoadAvalaraAddress(inputAddress.AddressID);
                ResultAddress   = inputAddress;
            }

            try
            {
                //http://developer.avalara.com/api-docs/api-reference/address-validation
                ValidateResult addressResult = addrSvc.Validate(addrReq);
                if (addressResult.Messages.Count > 0)
                {
                    var errorMessages = new StringBuilder();
                    foreach (Message message in addressResult.Messages)
                    {
                        if (message.Severity == SeverityLevel.Error)
                        {
                            if (stringResourceInResult)
                            {
                                errorMessages.Append(String.Format(AppLogic.GetString("Avalara.AddressValidate.ValidationFailed", customer.LocaleSetting), message.Details));
                            }
                            errorMessages.Append(message.Details);
                        }
                    }
                    return(errorMessages.ToString());
                }
                else
                {
                    if (addressResult.ResultCode == SeverityLevel.Success && addressResult.Addresses.Count == 1)
                    {
                        ValidAddress normalizedAddress = addressResult.Addresses[0];
                        ResultAddress.Address1 = normalizedAddress.Line1;
                        ResultAddress.Address2 = normalizedAddress.Line2;
                        ResultAddress.City     = normalizedAddress.City;
                        ResultAddress.State    = normalizedAddress.Region;
                        ResultAddress.Zip      = normalizedAddress.PostalCode;
                        ResultAddress.Country  = AppLogic.GetCountryNameFromTwoLetterISOCode(normalizedAddress.Country);
                    }
                    return(String.Empty);
                }
            }
            catch (Exception ex)
            {
                return(String.Format(AppLogic.GetString("Avalara.AddressValidate.Exception", customer.LocaleSetting), ex.Message));
            }
        }