Ejemplo n.º 1
0
        public bool ValidateAddress(Address_V01 address, out Address_V01 avsOutputAddress)
        {
            ServiceProvider.AddressValidationSvc.Address avsAddress = null;
            var errorCode = string.Empty;
            var isValid   =
                new ShippingProvider_US().ValidateAddress(new ShippingAddress_V02(0, string.Empty, string.Empty,
                                                                                  string.Empty, string.Empty, address, string.Empty, string.Empty, true, string.Empty, DateTime.Now),
                                                          out errorCode, out avsAddress);

            if (isValid && null != avsAddress && !CheckAvsAddressForNull(avsAddress))
            {
                avsOutputAddress = new Address_V01
                {
                    City                   = avsAddress.City,
                    Country                = avsAddress.CountryCode,
                    CountyDistrict         = avsAddress.CountyDistrict,
                    Line1                  = avsAddress.Line1,
                    Line2                  = avsAddress.Line2,
                    Line3                  = avsAddress.Line3,
                    Line4                  = avsAddress.Line4,
                    PostalCode             = avsAddress.PostalCode,
                    StateProvinceTerritory = avsAddress.StateProvinceTerritory
                };
                return(true);
            }
            avsOutputAddress = null;
            return(false);
        }
Ejemplo n.º 2
0
        private bool AVSAddressValidationCheck(out string errorCode,
                                               out ServiceProvider.AddressValidationSvc.Address avsAddress)
        {
            errorCode  = string.Empty;
            avsAddress = null;

            if (ProductsBase.CountryCode.Equals("US"))
            {
                IShippingProvider provider = ShippingProvider.GetShippingProvider("US");
                if (provider != null)
                {
                    return(provider.ValidateAddress(_shippingAddr, out errorCode,
                                                    out avsAddress));
                }
            }
            else if (ProductsBase.CountryCode.Equals("PR"))
            {
                IShippingProvider provider = ShippingProvider.GetShippingProvider("PR");
                if (provider != null)
                {
                    return(provider.ValidateAddress(_shippingAddr, out errorCode,
                                                    out avsAddress));
                }
            }



            return(true);
        }
Ejemplo n.º 3
0
        private void setAvsErrorLevel(bool svcCallStatus, string errorCode, List <string> errorList,
                                      ServiceProvider.AddressValidationSvc.Address avsAddress)
        {
            //there are field validation errors,
            if (errorList.Count > 0)
            {
                AVSErrorLevel = 4;
                return;
            }

            if (level1ErrorCodes.Exists(l => l == errorCode))
            {
                AVSErrorLevel = 1;
            }
            if (level2ErrorCodes.Exists(l => l == errorCode))
            {
                AVSErrorLevel = 2;
            }
            if (level3ErrorCodes.Exists(l => l == errorCode))
            {
                AVSErrorLevel = 3;
            }
            if (level4ErrorCodes.Exists(l => l == errorCode))
            {
                AVSErrorLevel = 4;
            }

            //if State Code has changed, set the AVSErrorLevel to 2.
            if (AVSErrorLevel.Equals(0))
            {
                if (!_shippingAddr.Address.StateProvinceTerritory.Equals(avsAddress.StateProvinceTerritory))
                {
                    AVSErrorLevel = 2;
                }
            }


            //set Error messages for UI/View rendering
            if (AVSErrorLevel == 1)
            {
                errorList.Add(GetLocalResourceObject("Level1ErrorMessage") as string);
            }
            if (AVSErrorLevel == 2)
            {
                errorList.Add(GetLocalResourceObject("Level2ErrorMessage") as string);
            }
            if (AVSErrorLevel == 3)
            {
                errorList.Add(GetLocalResourceObject("Level3ErrorMessage") as string);
            }
            if (AVSErrorLevel == 4)
            {
                errorList.Add(GetLocalResourceObject("Level4ErrorMessage") as string);
            }
        }
Ejemplo n.º 4
0
        private void updateViewWithAVSRecommendation(ServiceProvider.AddressValidationSvc.Address avsAddress)
        {
            txtStreet.Text = avsAddress.Line1;
            txtCity.Text   = avsAddress.City;

            dnlState.SelectedIndex = -1;
            ListItem itemState = dnlState.Items.FindByValue(avsAddress.StateProvinceTerritory);

            if (itemState != null)
            {
                itemState.Selected = true;
            }

            txtPostCode.Text = avsAddress.PostalCode;
            County           = avsAddress.CountyDistrict;
            string phone = _shippingAddr.Phone;

            CreateAddressFromControl();
            _shippingAddr.Phone = phone;
        }
Ejemplo n.º 5
0
 private static bool CheckAvsAddressForNull(ServiceProvider.AddressValidationSvc.Address avsAddress)
 {
     return(string.IsNullOrEmpty(avsAddress.City) || string.IsNullOrEmpty(avsAddress.PostalCode) ||
            string.IsNullOrEmpty(avsAddress.StateProvinceTerritory));
 }
        public override bool ValidateAddress(ShippingAddress_V02 shippingAddress,
                                             out String errorCode,
                                             out ServiceProvider.AddressValidationSvc.Address avsAddress)
        {
            errorCode = string.Empty;

            var request = new ValidateAddressRequest();
            var address = new ServiceProvider.AddressValidationSvc.Address();

            address.City                   = shippingAddress.Address.City;
            address.CountryCode            = shippingAddress.Address.Country;
            address.Line1                  = shippingAddress.Address.Line1;
            address.PostalCode             = shippingAddress.Address.PostalCode;
            address.StateProvinceTerritory = shippingAddress.Address.StateProvinceTerritory;
            request.Address                = address;

            // Avoid validation where ValidatePostalCode is disabled
            if (!HLConfigManager.Configurations.AddressingConfiguration.ValidatePostalCode)
            {
                avsAddress = request.Address;
                return(true);
            }

            var proxy = ServiceClientProvider.GetAddressValidationServiceProxy();

            try
            {
                var response = proxy.ValidateAddress(new ValidateAddressRequest1(request)).ValidateAddressResponse;
                if (response != null)
                {
                    if (response.ValidationResult.Value.ToUpper() == "FOUND" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E421" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E422" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E427" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E412" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E413" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E423" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E425" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E420" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E430" ||
                        response.ValidationResult.ErrorCode.ToUpper() == "E600")
                    {
                        // address is valid
                        errorCode  = response.ValidationResult.ErrorCode;
                        avsAddress = response.Address;
                        return(true);
                    }
                }
                // address is invalid
                errorCode  = response.ValidationResult.ErrorCode;
                avsAddress = response.Address;
                return(false);
            }
            catch (Exception ex)
            {
                LoggerHelper.Error(string.Format("AVS Address Validation Failed:{0}", ex.Message));
                errorCode  = ex.Message;
                avsAddress = null;
                return(false);
            }
        }
Ejemplo n.º 7
0
        public override bool Validate()
        {
            base.Validate(); // call base to validate required
            string countryCode = ProductsBase.CountryCode;

            if (countryCode.Equals("US") || countryCode.Equals("CA"))
            {
                if (string.IsNullOrEmpty(_shippingAddr.FirstName))
                {
                    ErrorList.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "NoFirstName"));
                }
                if (string.IsNullOrEmpty(_shippingAddr.LastName))
                {
                    ErrorList.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "NoLastName"));
                }
            }
            else
            {
                if (string.IsNullOrEmpty(_shippingAddr.Recipient))
                {
                    ErrorList.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "NoCareOfName"));
                }
            }

            if (countryCode.Equals("CA"))
            {
                if (string.IsNullOrEmpty(_shippingAddr.Address.StateProvinceTerritory) ||
                    (_shippingAddr.Address.StateProvinceTerritory.ToLower()
                     .Equals(GetLocalResourceObject("Select").ToString().ToLower())))
                {
                    ErrorList.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "NoState"));
                }
                if (string.IsNullOrEmpty(_shippingAddr.Address.City))
                {
                    ErrorList.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "NoCity"));
                }
                if (string.IsNullOrEmpty(_shippingAddr.Address.PostalCode))
                {
                    ErrorList.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "NoZipCode"));
                }
            }

            if (countryCode.Equals("US"))
            {
                if (string.IsNullOrEmpty(_shippingAddr.Address.StateProvinceTerritory) ||
                    (_shippingAddr.Address.StateProvinceTerritory.ToLower()
                     .Equals(GetLocalResourceObject("Select").ToString().ToLower())))
                {
                    ErrorList.Add(GetLocalResourceObject("NoState") as string);
                }
                if (string.IsNullOrEmpty(_shippingAddr.Address.City))
                {
                    ErrorList.Add(GetLocalResourceObject("NoCity") as string);
                }
                if (string.IsNullOrEmpty(_shippingAddr.Address.PostalCode))
                {
                    ErrorList.Add(GetLocalResourceObject("NoZip") as string);
                }
            }

            if (countryCode.Equals("PR"))
            {
                if (string.IsNullOrEmpty(_shippingAddr.Address.StateProvinceTerritory) ||
                    (_shippingAddr.Address.StateProvinceTerritory.ToLower()
                     .Equals(GetLocalResourceObject("Select").ToString().ToLower())))
                {
                    ErrorList.Add(GetLocalResourceObject("NoState") as string);
                }
                if (string.IsNullOrEmpty(_shippingAddr.Address.City))
                {
                    ErrorList.Add(GetLocalResourceObject("NoCity") as string);
                }
                if (string.IsNullOrEmpty(_shippingAddr.Address.PostalCode))
                {
                    ErrorList.Add(GetLocalResourceObject("NoZip") as string);
                }
            }

            NameStreetAndPhoneValidation(ErrorList);

            if (countryCode.Equals("US") || countryCode.Equals("PR"))
            {
                USFieldValidation(ErrorList);

                //AVS address validation check. If false, avs address validation failed.
                string errorCode = string.Empty;
                ServiceProvider.AddressValidationSvc.Address avsAddress = null;
                _shippingAddr.Address.StateProvinceTerritory = _shippingAddr.Address.StateProvinceTerritory;
                bool avsSvcStatus = AVSAddressValidationCheck(out errorCode, out avsAddress);
                setAvsErrorLevel(avsSvcStatus, errorCode, ErrorList, avsAddress);

                //Update VIEW with AVS recommendations
                if (!this.AVSErrorLevel.Equals(4))
                {
                    updateViewWithAVSRecommendation(avsAddress);
                }
                if (ErrorList.Count == 0)
                {
                    return(true);
                }

                bool bSave = IsOkToSave();
                if (bSave)
                {
                    if (this.ErrorList.Contains(GetLocalResourceObject("Level1ErrorMessage") as string))
                    {
                        this.ErrorList.Remove(GetLocalResourceObject("Level1ErrorMessage") as string);
                    }
                    else if (this.ErrorList.Contains(GetLocalResourceObject("Level2ErrorMessage") as string))
                    {
                        this.ErrorList.Remove(GetLocalResourceObject("Level2ErrorMessage") as string);
                    }
                    else if (this.ErrorList.Contains(GetLocalResourceObject("Level3ErrorMessage") as string))
                    {
                        this.ErrorList.Remove(GetLocalResourceObject("Level3ErrorMessage") as string);
                    }
                    else if (this.ErrorList.Contains(GetLocalResourceObject("Level4ErrorMessage") as string))
                    {
                        this.ErrorList.Remove(GetLocalResourceObject("Level4ErrorMessage") as string);
                    }
                }

                return(bSave);
            }

            //CANADA
            if (countryCode.Equals("CA"))
            {
                //31554: All textbox allow these special characters (,) (-) (‘) (.) (/) and (\)
                if (!string.IsNullOrEmpty(_shippingAddr.Address.City))
                {
                    if (!Regex.IsMatch(_shippingAddr.Address.City,
                                       @"(^[\w\s\/,-.'\\]+$)"))
                    {
                        ErrorList.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "InvalidCity"));
                    }
                }

                if (!string.IsNullOrEmpty(_shippingAddr.Address.PostalCode))
                {
                    //if (!Regex.IsMatch(_shippingAddr.Address.PostalCode,
                    //                   @"(^[a-zA-Z0-9]{3}\s[a-zA-Z0-9]{3}$)"))
                    if (!Regex.IsMatch(_shippingAddr.Address.PostalCode, @"^[ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy]{1}\d{1}[a-zA-Z]{1} *\d{1}[a-zA-Z]{1}\d{1}$"))
                    {
                        ErrorList.Add(PlatformResources.GetGlobalResourceString("ErrorMessage", "InvalidZipCode"));
                    }
                }
            }

            return(ErrorList.Count == 0);
        }