public static Loan ObtenerCuentaPrestamo(string parentAccountKey) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; List <Loan> contrato = null; List <FilterConstraints> filterConstraints = new List <FilterConstraints>(); FilterConstraints filterConstraint = new FilterConstraints(); filterConstraint = null; filterConstraint = new FilterConstraints(); filterConstraint.filterSelection = Constantes.FILTRO_CAMPO_ENCODED_KEY; filterConstraint.filterElement = Constantes.OPERADOR_EQUALS; filterConstraint.value = parentAccountKey; filterConstraint.dataItemType = Constantes.DATA_ITEM_TYPE_LOANS; filterConstraints.Add(filterConstraint); Filtros filtros = new Filtros(); filtros.filterConstraints = filterConstraints; string json = JsonConvert.SerializeObject(filtros); WebRequest req = WebRequest.Create(ConfigurationManager.AppSettings["ambiente"] + "/" + Constantes.API_MAMBU_LOAN + "/" + Constantes.API_MAMBU_SEARCH + "?" + Constantes.LIMITE_CONSULTA); req.ContentType = "application/json; charset=utf-8"; req.Method = Constantes.METODO_POST; req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(ConfigurationManager.AppSettings["user"] + ":" + ConfigurationManager.AppSettings["psw"])); JavaScriptSerializer js = new JavaScriptSerializer(); js.MaxJsonLength = Int32.MaxValue; try { using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)req.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var objText = streamReader.ReadToEnd(); contrato = js.Deserialize <List <Loan> >(objText); } } catch (Exception e) { log.Error("ERROR ------------ " + e.StackTrace); } return(contrato[0]); }
public static List <Transaccion> ObtenerTransacciones(string tipo, string fechaInicio, string fechaFin, bool reversado) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; int offset = 0; bool acaba = false; Filtros filtros = new Filtros(); FilterConstraints filterConstraint = new FilterConstraints(); // Tipo de Transacción filterConstraint = new FilterConstraints(); filterConstraint.filterSelection = ConstantesMambu.FILTRO_SELECCION_EVENT; filterConstraint.filterElement = ConstantesMambu.OPERADOR_EQUALS; filterConstraint.value = tipo; filterConstraint.dataItemType = ConstantesMambu.DATA_ITEM_TYPE_LOAN_TRANSACTION; filtros.filterConstraints.Add(filterConstraint); // Rango de Fechas filterConstraint = null; filterConstraint = new FilterConstraints(); filterConstraint.filterSelection = ConstantesMambu.FILTRO_CAMPO_TRANSACTION_DATE; filterConstraint.filterElement = ConstantesMambu.OPERADOR_BETWEEN; filterConstraint.value = fechaInicio; filterConstraint.secondValue = fechaFin; filterConstraint.dataItemType = ConstantesMambu.DATA_ITEM_TYPE_LOAN_TRANSACTION; filtros.filterConstraints.Add(filterConstraint); // Fue Reversado? filterConstraint = null; filterConstraint = new FilterConstraints(); filterConstraint.filterSelection = ConstantesMambu.FILTRO_CAMPO_WAS_REVERSED; filterConstraint.filterElement = ConstantesMambu.OPERADOR_EQUALS; filterConstraint.value = reversado ? ConstantesMambu.VALOR_CAMPO_VERDADERO : ConstantesMambu.VALOR_CAMPO_FALSO; filterConstraint.dataItemType = ConstantesMambu.DATA_ITEM_TYPE_LOAN_TRANSACTION; filtros.filterConstraints.Add(filterConstraint); string json = JsonConvert.SerializeObject(filtros); List <Transaccion> transacciones = null; List <Transaccion> acumuladoTransacciones = new List <Transaccion>(); while (!acaba) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["ambiente"] + "/" + "loans/transactions/search?" + Constantes.LIMITE_CONSULTA + "&" + Constantes.OFFSET_CONSULTA + offset); req.Method = Constantes.METODO_POST; req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(ConfigurationManager.AppSettings["user"] + ":" + ConfigurationManager.AppSettings["psw"])); req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0"; req.ContentType = "application/json"; JavaScriptSerializer js = new JavaScriptSerializer(); js.MaxJsonLength = Int32.MaxValue; using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } try { var httpResponse = (HttpWebResponse)req.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var objText = streamReader.ReadToEnd(); transacciones = js.Deserialize <List <Transaccion> >(objText); if (transacciones.Count <= 0) { acaba = true; } else { offset += 1000; acumuladoTransacciones.AddRange(transacciones); } transacciones = null; } } catch (Exception e) { log.Error("ERROR ------------ " + e.StackTrace); } } return(acumuladoTransacciones); }
/// <summary> /// Método para obtener las cuentas de prestamo (Contratos) con base al estatus /// </summary> /// <param name="idContrato"></param> /// <param name="estatus"></param> /// <returns></returns> public static List <Loan> ObtenerCuentasPrestamo(string idContrato, string estatus) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; int offset = 0; bool acaba = false; List <FilterConstraints> filterConstraints = new List <FilterConstraints>(); FilterConstraints filterConstraint = new FilterConstraints(); #region Filtros if (estatus != null) { filterConstraint = null; filterConstraint = new Entidades.FilterConstraints(); filterConstraint.filterSelection = Negocio.Globales.ConstantesMambu.FILTRO_CAMPO_ESTATUS_CONTRATO; filterConstraint.filterElement = Negocio.Globales.ConstantesMambu.OPERADOR_EQUALS; filterConstraint.dataItemType = Negocio.Globales.ConstantesMambu.DATA_ITEM_TYPE_LOANS; filterConstraint.value = estatus; filterConstraints.Add(filterConstraint); } filterConstraint = null; filterConstraint = new Entidades.FilterConstraints(); filterConstraint.filterSelection = Negocio.Globales.Constantes.FILTRO_CAMPO_ACCOUNT_ID; filterConstraint.filterElement = Negocio.Globales.Constantes.OPERADOR_EQUALS; filterConstraint.value = idContrato; filterConstraint.dataItemType = Negocio.Globales.Constantes.DATA_ITEM_TYPE_LOANS; filterConstraints.Add(filterConstraint); #endregion Filtros filtros = new Filtros(); filtros.filterConstraints = filterConstraints; string json = JsonConvert.SerializeObject(filtros); List <Loan> contratos = null; List <Loan> acumuladoContratos = new List <Loan>(); while (!acaba) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["ambiente"] + "/loans/search?" + Constantes.LIMITE_CONSULTA + "&" + Constantes.OFFSET_CONSULTA + offset); req.Method = Constantes.METODO_POST; req.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(ConfigurationManager.AppSettings["user"] + ":" + ConfigurationManager.AppSettings["psw"])); req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0"; req.ContentType = "application/json"; JavaScriptSerializer js = new JavaScriptSerializer(); js.MaxJsonLength = Int32.MaxValue; try { using (var streamWriter = new StreamWriter(req.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)req.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var objText = streamReader.ReadToEnd(); contratos = js.Deserialize <List <Loan> >(objText); if (contratos.Count <= 0) { acaba = true; } else { offset += 1000; acumuladoContratos.AddRange(contratos); } contratos = null; } } catch (Exception e) { log.Error("ERROR ------------ " + e.StackTrace); } } return(acumuladoContratos); }