private void SetBillingAddress(VirtoCommerce.Domain.Commerce.Model.Address address, Hashtable request) { request.Add("billTo_firstName", address.FirstName); request.Add("billTo_lastName", address.LastName); request.Add("billTo_street1", address.Line1); if (!string.IsNullOrEmpty(address.Line2)) { request.Add("billTo_street2", address.Line2); } request.Add("billTo_city", address.City); request.Add("billTo_state", address.RegionName); request.Add("billTo_postalCode", address.PostalCode); request.Add("billTo_country", address.CountryName); if (!string.IsNullOrEmpty(address.Email)) { request.Add("billTo_email", address.Email); } if (!string.IsNullOrEmpty(address.Phone)) { request.Add("billTo_phone", address.Phone); } }
public static dataModel.AddressEntity ToDataModel(this coreModel.Address address) { if (address == null) { throw new ArgumentNullException("address"); } var retVal = new dataModel.AddressEntity(); retVal.InjectFrom(address); retVal.AddressType = address.AddressType.ToString(); return(retVal); }
public static coreModel.Address ToCoreModel(this dataModel.AddressEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } var retVal = new coreModel.Address(); retVal.InjectFrom(entity); retVal.AddressType = (coreModel.AddressType)Enum.Parse(typeof(coreModel.AddressType), entity.AddressType); return(retVal); }
public IHttpActionResult ValidateAddress(domainModel.Address address) { IHttpActionResult retVal = BadRequest(); LogInvoker <AvalaraLogger.TaxRequestContext> .Execute(log => { if (!_taxSettings.IsValidateAddress) { retVal = BadRequest("AvaTax address validation disabled"); throw new Exception((retVal as BadRequestErrorMessageResult).Message); } if (!string.IsNullOrEmpty(_taxSettings.Username) && !string.IsNullOrEmpty(_taxSettings.Password) && !string.IsNullOrEmpty(_taxSettings.ServiceUrl) && !string.IsNullOrEmpty(_taxSettings.CompanyCode)) { var addressSvc = new JsonAddressSvc(_taxSettings.Username, _taxSettings.Password, _taxSettings.ServiceUrl); var request = address.ToValidateAddressRequest(_taxSettings.CompanyCode); var validateAddressResult = addressSvc.Validate(request); if (!validateAddressResult.ResultCode.Equals(SeverityLevel.Success)) { var error = string.Join(Environment.NewLine, validateAddressResult.Messages.Where(ms => ms.Severity == SeverityLevel.Error).Select( m => m.Summary + string.Format(" [{0} - {1}] ", m.RefersTo, m.Details == null ? string.Empty : string.Join(", ", m.Details)))); retVal = BadRequest(error); throw new Exception((retVal as BadRequestErrorMessageResult).Message); } retVal = Ok(validateAddressResult); } if (!(retVal is OkNegotiatedContentResult <ValidateResult>)) { retVal = BadRequest("AvaTax credentials not provided"); throw new Exception((retVal as BadRequestErrorMessageResult).Message); } }) .OnError(_logger, AvalaraLogger.EventCodes.AddressValidationError) .OnSuccess(_logger, AvalaraLogger.EventCodes.ValidateAddress); return(retVal); }