private string PagarServicioJWT(RequestPagarServicios requestPagarServicios, string metodoApiGestoPago) { String result = string.Empty; _ResponsePagarServicios responsePagarServicios = new _ResponsePagarServicios(); responsePagarServicios.request = ConexionAPI.ObtenerConexion() + requestPagarServicios.ObtenerParametros(); string dataPost = JsonConvert.SerializeObject(requestPagarServicios); String cadenaNormal = Cifrado.CifradoTexto(dataPost); String cadenaEscape = Uri.EscapeDataString(Cifrado.CifradoTexto(dataPost)); byte[] data = UTF8Encoding.UTF8.GetBytes("signed=" + cadenaEscape); new Logg().Info("strKey : " + ConexionAPI.secretKey + " | IV: " + ConexionAPI.IV); new Logg().Info("signed cadenaEscape =" + cadenaEscape); new Logg().Info("signed cadenaNormal =" + cadenaNormal); new Logg().Info("Descrypt: " + Cifrado.DescifradoTexto(cadenaNormal)); string token = new Authenticate().GeneraToken(); HttpWebRequest request = initRequest(data, metodoApiGestoPago); 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(); Debug.WriteLine("Result ws: " + result); Debug.WriteLine("Json Params: " + JsonConvert.SerializeObject(requestPagarServicios)); Debug.WriteLine("Data Cifrada: " + cadenaNormal); Debug.WriteLine("Data Cifrada Escape: " + cadenaEscape); Debug.WriteLine("token: " + token); return(result); }
public _ResponsePagarServicios PagarServicio(RequestPagarServicios requestPagarServicios) { _ResponsePagarServicios responsePagarServicios = 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; responsePagarServicios = new _ResponsePagarServicios(); // throw new WebException(); result = PagarServicioJWT(requestPagarServicios, sendTx); /* Para consumir a GestoPago antes de implementar JWT * responsePagarServicios.request = ParametrosConfig() + requestPagarServicios.ObtenerParametros(); * byte[] data = UTF8Encoding.UTF8.GetBytes(ParametrosConfig() + requestPagarServicios.ObtenerParametros()); * HttpWebRequest request = initRequest(data, abonar); * 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)) { new Logg().Warning("xml respuesta :" + result.ToString()); ResponseAbonar responseAbonar = SerializerManager <ResponseGeneral> .DeseralizarStringXMLToObject(result).ResponseAbonar; responsePagarServicios.request = "Metodo: " + sendTx + ConexionAPI.ObtenerConexion() + " | " + JsonConvert.SerializeObject(requestPagarServicios); responsePagarServicios.signed = Cifrado.CifradoTexto(Uri.EscapeDataString(JsonConvert.SerializeObject(requestPagarServicios))); responsePagarServicios.ResponseAbonar = responseAbonar; responsePagarServicios.EstatusCmv = EstatusCMV.Ok; responsePagarServicios.MensajeCmv = "OK"; return(responsePagarServicios); } } catch (FaultException <_ExceptionPagarServicios> ex) { throw ex; } catch (WebException e) { new Logg().Error("Error :" + e.ToString()); responsePagarServicios = new _ResponsePagarServicios(); responsePagarServicios.request = "Metodo: " + sendTx + ConexionAPI.ObtenerConexion() + " | " + JsonConvert.SerializeObject(requestPagarServicios); responsePagarServicios.signed = Cifrado.CifradoTexto(Uri.EscapeDataString(JsonConvert.SerializeObject(requestPagarServicios))); responsePagarServicios.EstatusCmv = EstatusCMV.Error; responsePagarServicios.MensajeCmv = e.Message + "|" + e.StackTrace; //return responsePagarServicios; _ResponseConfirmaTransaccion responseConfirmaTransaccion = ConfirmaTransaccion(requestPagarServicios); responseConfirmaTransaccion.ResponseAbonar.MENSAJE.CODIGO = responseConfirmaTransaccion.ResponseAbonar.MENSAJE.CODIGO == "06" ? "01" : responseConfirmaTransaccion.ResponseAbonar.MENSAJE.CODIGO; Mapper.Initialize(x => { x.CreateMap <_ResponseConfirmaTransaccion, _ResponsePagarServicios>(); }); responsePagarServicios = Mapper.Map <_ResponsePagarServicios>(responseConfirmaTransaccion); return(responsePagarServicios); } catch (Exception ex) { _ExceptionPagarServicios exceptionPagarServicios = new _ExceptionPagarServicios(); exceptionPagarServicios.Codigo = 1000;//Error no definido p exceptionPagarServicios.Mensaje = ex.Message; throw new FaultException <_ExceptionPagarServicios>(exceptionPagarServicios, "Error personalizado por Exception", new FaultCode("-1")); } return(null); }