Example #1
0
        public _ResponseConsultaProductos ConsultaProductos()
        {
            _ResponseConsultaProductos responseConsultaProductos = null;

            try
            {
                responseConsultaProductos = new _ResponseConsultaProductos();
                String         result  = string.Empty;
                byte[]         data    = UTF8Encoding.UTF8.GetBytes(ConexionAPI.ObtenerConexion() + "&showLegend=true");
                string         token   = new Authenticate().GeneraToken();
                HttpWebRequest request = initRequest(data, getListaProducto);
                request.Headers.Add("Authorization", "Bearer " + token);
                Stream postStream = request.GetRequestStream();
                postStream.Write(data, 0, data.Length);

                HttpWebResponse response       = request.GetResponse() as HttpWebResponse;
                StreamReader    readerResponse = new StreamReader(response.GetResponseStream());

                result = readerResponse.ReadToEnd();

                //responsePagarServicios.response = result;
                if (!string.IsNullOrEmpty(result))
                {
                    ResponseConsultaProductos responseAbonar = SerializerManager <ResponseConsultaProductos> .DeseralizarStringToObject(result);

                    responseConsultaProductos.Productos = responseAbonar;
                    return(responseConsultaProductos);
                }
            }
            catch (Exception ex)
            {
                _ExceptionPagarServicios exceptionPagarServicios = new _ExceptionPagarServicios();
                exceptionPagarServicios.Codigo  = -1;
                exceptionPagarServicios.Mensaje = ex.Message;
                throw new FaultException <_ExceptionPagarServicios>(exceptionPagarServicios, "Error personalizado por Exception", new FaultCode("-1"));
            }
            return(null);
        }
Example #2
0
        public _ResponseConfirmaTransaccion ConfirmaTransaccion(RequestPagarServicios requestPagarServicios)
        {
            bool intento = true;
            _ResponseConfirmaTransaccion responseConfirmaTransaccion = null;

            try
            {
                if (!(requestPagarServicios.TipoFront == 1 || requestPagarServicios.TipoFront == 2))
                {
                    _ExceptionPagarServicios exceptionPagarServicios = new _ExceptionPagarServicios();
                    exceptionPagarServicios.Codigo  = -1;
                    exceptionPagarServicios.Mensaje = "El tipo front no corresponde a este servicio";
                    throw new FaultException <_ExceptionPagarServicios>(exceptionPagarServicios, "Error personalizado por CMV", new FaultCode("-1"));
                }

                String result = string.Empty;
                responseConfirmaTransaccion = new _ResponseConfirmaTransaccion();


                result = PagarServicioJWT(requestPagarServicios, confirmTx);

                /*
                 * responseConfirmaTransaccion.request = ParametrosConfig() + requestPagarServicios.ObtenerParametros();
                 * byte[] data = UTF8Encoding.UTF8.GetBytes(ParametrosConfig() + requestPagarServicios.ObtenerParametros());
                 *
                 * HttpWebRequest request = initRequest(data,confirmaTransaccion);
                 * Stream postStream = request.GetRequestStream();
                 * postStream.Write(data, 0, data.Length);
                 *
                 * HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                 * StreamReader readerResponse = new StreamReader(response.GetResponseStream());
                 *
                 * result = readerResponse.ReadToEnd();
                 */
                responseConfirmaTransaccion.response = result;
                if (!string.IsNullOrEmpty(result))
                {
                    responseConfirmaTransaccion.request = "Metodo: " + confirmTx + ConexionAPI.ObtenerConexion() + " | " + JsonConvert.SerializeObject(requestPagarServicios);
                    responseConfirmaTransaccion.signed  = Cifrado.CifradoTexto(Uri.EscapeDataString(JsonConvert.SerializeObject(requestPagarServicios)));
                    ResponseAbonar responseAbonar = SerializerManager <ResponseAbonar> .DeseralizarStringToObject(result);

                    responseConfirmaTransaccion.EstatusCmv     = EstatusCMV.Ok;
                    responseConfirmaTransaccion.MensajeCmv     = "Pago realizado Exitosamente";
                    responseConfirmaTransaccion.ResponseAbonar = responseAbonar;
                    return(responseConfirmaTransaccion);
                }
            }
            catch (WebException e)
            {
                responseConfirmaTransaccion.request    = "Metodo: " + confirmTx + ConexionAPI.ObtenerConexion() + " | " + JsonConvert.SerializeObject(requestPagarServicios);
                responseConfirmaTransaccion.signed     = Cifrado.CifradoTexto(Uri.EscapeDataString(JsonConvert.SerializeObject(requestPagarServicios)));
                responseConfirmaTransaccion.EstatusCmv = EstatusCMV.Error;
                responseConfirmaTransaccion.MensajeCmv = e.Message + " | " + e.StackTrace;
                return(responseConfirmaTransaccion);
            }
            catch (FaultException <_ExceptionPagarServicios> ex)
            {
                throw ex;
            }

            catch (Exception ex)
            {
                _ExceptionPagarServicios exceptionPagarServicios = new _ExceptionPagarServicios();
                exceptionPagarServicios.Codigo  = -1;
                exceptionPagarServicios.Mensaje = ex.Message;
                throw new FaultException <_ExceptionPagarServicios>(exceptionPagarServicios, "CMV: Error personalizado por Exception", new FaultCode("-1"));
            }
            return(null);
        }
Example #3
0
        public static Object PagarServicio(ref RequestPagarServicios requestPagarServicios)
        {
            bool intento = true;

            try
            {
                String result = string.Empty;
                requestPagarServicios.request = ParametrosConfig() + requestPagarServicios.ObtenerParametros();
                byte[]         data = UTF8Encoding.UTF8.GetBytes(ParametrosConfig() + requestPagarServicios.ObtenerParametros());
                HttpWebRequest request;
                string         url = Path.Combine(SesionGestoPago.URL, SesionGestoPago.abonar);
                request               = WebRequest.Create(url) as HttpWebRequest;
                request.Timeout       = 60 * 1000; // 60 segundos
                request.Method        = "POST";
                request.ContentLength = data.Length;
                request.ContentType   = "application/x-www-form-urlencoded; charset=utf-8";

                Stream postStream = request.GetRequestStream();
                postStream.Write(data, 0, data.Length);

                HttpWebResponse response       = request.GetResponse() as HttpWebResponse;
                StreamReader    readerResponse = new StreamReader(response.GetResponseStream());

                result = readerResponse.ReadToEnd();
                requestPagarServicios.response = result;
                if (!string.IsNullOrEmpty(result))
                {
                    Console.WriteLine(result.ToString());
                    switch (requestPagarServicios.TipoFront)
                    {
                    case 1:
                    case 2:
                        ResponseAbonar responseAbonar = SerializerManager <ResponseAbonar> .DeseralizarStringToObject(result);

                        return(responseAbonar);

                        break;

                    case 4:
                        ResponseConsultaSaldo esponseConsultaSaldo = SerializerManager <ResponseConsultaSaldo> .DeseralizarStringToObject(result);

                        return(esponseConsultaSaldo);

                        break;

                    default:
                        break;
                    }
                }
            }
            catch (WebException e)
            {
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    if (intento)
                    {
                        intento = false;
                        //PagarServicio(requestPagarServicios);
                    }
                }
                else
                {
                    throw e;
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }
            return(null);
        }