Esempio n. 1
0
        public static string CardHolderDetails(string cardHolderDetail, AddressFields fieldName)
        {
            IDictionary <Enum, int> dict = new Dictionary <Enum, int>();

            dict.Add(AddressFields.FirstName, NAME_MAX_LENGTH);
            dict.Add(AddressFields.LastName, NAME_MAX_LENGTH);
            dict.Add(AddressFields.Address, ADDRESS_MAX_LENGTH);
            dict.Add(AddressFields.City, CITY_MAX_LENGTH);
            dict.Add(AddressFields.State, STATE_MAX_LENGTH);
            if ((!string.IsNullOrEmpty(cardHolderDetail)) && (cardHolderDetail.Length > dict[fieldName]))
            {
                throw new HpsInvalidRequestException(HpsExceptionCodes.InvalidCardHolderDetail, "The value for " + fieldName + " should not more than" + dict[fieldName] + "characters", "cardHolderDetail");
            }
            return(cardHolderDetail);
        }
Esempio n. 2
0
        protected void ValidateAddressValues(AddressValue[] values)
        {
            if (values.Length == 0)
            {
                throw new ArgumentException("At least one address value must be provided.");
            }

            foreach (AddressValue addressValue in values)
            {
                if (!AddressFields.Any(o => String.Compare(o.Name, addressValue.Name, true) == 0))
                {
                    throw new ArgumentException(String.Format("This geocoder does not contain an address field named \"{0}\".", addressValue.Name));
                }
            }

            foreach (CommonField field in AddressFields.Where(o => o.Required))
            {
                if (!values.Any(o => String.Compare(o.Name, field.Name, true) == 0))
                {
                    throw new ArgumentException(String.Format("Required address value \"{0}\" is missing.", field.Name));
                }
            }
        }
Esempio n. 3
0
        public static bool Execute(
            decimal lat,
            decimal lng,
            string apiKey,
            out AddressFields af
            )
        {
            af = new AddressFields {
            };
            try {
                var resource = "maps/api/geocode/json?latlng=" + lat.ToString() + "," + lng.ToString() + "&key=" + apiKey;
                var client   = new RestClient("https://maps.googleapis.com/");
                var request  = new RestRequest(resource, Method.GET);
                request.RequestFormat = DataFormat.Json;
                var response = client.Execute(request);
                if (response.ErrorException != null)
                {
                    LogIt.W(response.ErrorException);
                }
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    LogIt.W(response.StatusCode);
                }
                var     content            = response.Content;
                dynamic json               = Newtonsoft.Json.Linq.JObject.Parse(content);
                dynamic address_components = json.results[0].address_components;

                for (int i = 0; i < address_components.Count; i++)
                {
                    var ac  = address_components[i];
                    var lot = ac.types;
                    for (int j = 0; j < ac.types.Count; j++)
                    {
                        var t = (string)ac.types[j].Value;
                        if (t.Equals("street_number"))
                        {
                            af.line1 = ac.short_name.Value;
                            break;
                        }
                    }
                    for (int j = 0; j < ac.types.Count; j++)
                    {
                        var t = (string)ac.types[j].Value;
                        if (t.Equals("route"))
                        {
                            af.street = ac.short_name.Value;
                            break;
                        }
                    }
                    for (int j = 0; j < ac.types.Count; j++)
                    {
                        var t = (string)ac.types[j].Value;
                        if (t.Equals("sublocality"))
                        {
                            af.city = ac.short_name.Value;
                            break;
                        }
                    }
                    for (int j = 0; j < ac.types.Count; j++)
                    {
                        var t = (string)ac.types[j].Value;
                        if (t.Equals("administrative_area_level_1"))
                        {
                            af.statecode = ac.short_name.Value;
                            af.state     = ac.long_name.Value;
                            break;
                        }
                    }
                    for (int j = 0; j < ac.types.Count; j++)
                    {
                        var t = (string)ac.types[j].Value;
                        if (t.Equals("country"))
                        {
                            af.countrycode = ac.short_name.Value;
                            break;
                        }
                    }
                    for (int j = 0; j < ac.types.Count; j++)
                    {
                        var t = (string)ac.types[j].Value;
                        if (t.Equals("postal_code"))
                        {
                            af.postal = ac.short_name.Value;
                            break;
                        }
                    }
                }
                return(true);
            } catch (Exception ex) {
                LogIt.W(ex.Message + "|" + lat + "|" + lng);
            }
            return(false);
        }