Пример #1
0
        public static Cliente ObtenerDatosClienteMambu(string id)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
            Cliente      cliente              = new Cliente();
            ClienteMambu clienteMambu         = new ClienteMambu();
            Dictionary <string, string> datos = new Dictionary <string, string>();


            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["ambiente"] + "/" + Constantes.API_MAMBU_CLIENT + "/" + id + "?fulldetails=true");

            req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0";
            req.Method    = Constantes.METODO_GET;
            req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(ConfigurationManager.AppSettings["user"] + ":" + ConfigurationManager.AppSettings["psw"]));



            JavaScriptSerializer js = new JavaScriptSerializer();

            js.MaxJsonLength = Int32.MaxValue;


            try
            {
                var httpResponse = (HttpWebResponse)req.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var objText = streamReader.ReadToEnd();
                    clienteMambu = js.Deserialize <ClienteMambu>(objText);
                }

                if (clienteMambu != null)
                {
                    cliente.idCliente       = clienteMambu.client.id;
                    cliente.nombre          = clienteMambu.client.firstName;
                    cliente.apellidoPaterno = clienteMambu.client.lastName;
                    cliente.apellidoMaterno = clienteMambu.client.middleName;

                    var rfc = clienteMambu.customInformation.FirstOrDefault(i => i.customFieldID == ConstantesMambu.ID_CAMPO_RFC_CLIENTE).value;
                }
            }
            catch (Exception e)
            {
                log.Error("ERROR ------------ " + e.StackTrace);
            }
            return(cliente);
        }
Пример #2
0
        public static Dictionary <string, string> ObtenerDatosCliente(string id)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            ClienteMambu objeto  = new ClienteMambu();
            Cliente      cliente = new Cliente();
            Dictionary <string, string> datos = new Dictionary <string, string>();


            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["ambiente"] + "/" + Constantes.API_MAMBU_CLIENT + "/" + id + "?fulldetails=true");

            req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0";
            req.Method    = Constantes.METODO_GET;
            req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(ConfigurationManager.AppSettings["user"] + ":" + ConfigurationManager.AppSettings["psw"]));



            JavaScriptSerializer js = new JavaScriptSerializer();

            js.MaxJsonLength = Int32.MaxValue;

            try
            {
                var httpResponse = (HttpWebResponse)req.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var objText = streamReader.ReadToEnd();
                    objeto = js.Deserialize <ClienteMambu>(objText);
                }

                if (objeto != null)
                {
                    datos.Add("nombreCliente", objeto.client.firstName);
                    datos.Add("paternoCliente", objeto.client.middleName);
                    datos.Add("maternoCliente", objeto.client.lastName);
                    datos.Add("fechaNacimiento", objeto.client.birthDate);
                    datos.Add("sexo", objeto.client.gender);
                    datos.Add("direccion", objeto.customInformation.FirstOrDefault(i => i.customFieldKey == ConstantesMambu.KEY_CAMPO_CALLE).value + " "
                              + objeto.customInformation.FirstOrDefault(i => i.customFieldKey == ConstantesMambu.KEY_CAMPO_NUMERO_EXTERIOR).value + " "
                              + objeto.customInformation.FirstOrDefault(i => i.customFieldKey == ConstantesMambu.KEY_CAMPO_NUMERO_INTERIOR).value);
                    datos.Add("coloniaPoblacion", objeto.customInformation.FirstOrDefault(i => i.customFieldKey == ConstantesMambu.KEY_CAMPO_COLONIA).value);

                    if (objeto.groupKeys.Count > 0)
                    {
                        datos.Add("keyGrupo", objeto.groupKeys.FirstOrDefault().ToString());
                    }
                    else
                    {
                        datos.Add("keyGrupo", objeto.id);
                    }

                    objeto = null;
                }
            }
            catch (Exception e)
            {
                log.Error("ERROR ------------ " + e.StackTrace);
            }

            return(datos);
        }