public bool ValidateAddress(IAddressBase aAddress, out bool isValid, Dictionary <PXAddressValidator.Fields, string> messages) { isValid = false; AvaAddress.ValidateRequest request = new AvaAddress.ValidateRequest(); request.Address = FromAddress(aAddress); AvaAddress.ValidateResult result = this._service.Validate(request); isValid = (result.ResultCode == Avalara.AvaTax.Adapter.SeverityLevel.Success || result.ResultCode == Avalara.AvaTax.Adapter.SeverityLevel.Warning); if (result.ResultCode != Avalara.AvaTax.Adapter.SeverityLevel.Success) { foreach (Avalara.AvaTax.Adapter.Message iMsg in result.Messages) { PXAddressValidator.Fields id = GetExtFieldName(iMsg.RefersTo); messages.Add(id, String.IsNullOrEmpty(iMsg.Details) ? (String.IsNullOrEmpty(iMsg.Summary)? (String.IsNullOrEmpty(iMsg.Source)? Messages.AvalaraAVSUnknownError:iMsg.Source) :iMsg.Summary) :iMsg.Details); } } if (isValid && result.Addresses.Count > 0) { Copy(aAddress, result.Addresses[0]); } return(true); }
public ValidateResult Validate(ValidateRequest validateRequest) { try { _avaLog.Debug("AddressSvc.Validate"); Utilities.VerifyRequestObject(validateRequest); _avaLog.Debug("Copying address into proxy object"); ProxyValidateRequest proxyRequest = new ProxyValidateRequest(); validateRequest.CopyTo(proxyRequest); //Record time take for address validation Perf monitor = new Perf(); monitor.Start(); ProxyValidateResult svcResult = (ProxyValidateResult)base.InvokeService(typeof(ProxyAddressSvc), MethodBase.GetCurrentMethod().Name, new object[] { proxyRequest }); monitor.Stop(this, ref svcResult); _avaLog.Debug("Copying address from proxy object"); ValidateResult localResult = new ValidateResult(); localResult.CopyFrom(svcResult); return(localResult); } catch (Exception ex) { return(ValidateResult.CastFromBaseResult(ExceptionManager.HandleException(ex))); } }