private void button2_Click(object sender, EventArgs e) { try { ResponseGeneral r = SerializerManager <ResponseGeneral> .DeseralizarStringXMLToObject(this.textData.Text); this.txtResult.Text = r.ResponseAbonar.MENSAJE.legend; } catch (Exception ex) { this.txtResult.Text = "Error :" + ex.Message; } }
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); }
public _ResponseConsultaSaldo ConsultarSaldoSerivicio(RequestPagarServicios requestPagarServicios) { _ResponseConsultaSaldo responseConsultaSaldo = null; try { if (requestPagarServicios.TipoFront != 4) { _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; responseConsultaSaldo = new _ResponseConsultaSaldo(); result = PagarServicioJWT(requestPagarServicios, sendTx); /* * responseConsultaSaldo.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(); */ responseConsultaSaldo.response = result; if (!string.IsNullOrEmpty(result)) { new Logg().Info("xml respuesta :" + result.ToString()); ResponseAbonar responseAbonar = SerializerManager <ResponseGeneral> .DeseralizarStringXMLToObject(result).ResponseAbonar; responseConsultaSaldo.request = "Metodo: " + sendTx + ConexionAPI.ObtenerConexion() + " | " + JsonConvert.SerializeObject(requestPagarServicios); responseConsultaSaldo.ResponseAbonar = responseAbonar; responseConsultaSaldo.EstatusCmv = EstatusCMV.Ok; responseConsultaSaldo.MensajeCmv = "Ejecución exitosa del servicio de consultar saldo"; responseConsultaSaldo.Signed = Cifrado.CifradoTexto(Uri.EscapeDataString(JsonConvert.SerializeObject(requestPagarServicios))); return(responseConsultaSaldo); } } catch (FaultException <_ExceptionPagarServicios> ex) { throw ex; } catch (WebException e) { responseConsultaSaldo.request = "Metodo: " + sendTx + ConexionAPI.ObtenerConexion() + " | " + JsonConvert.SerializeObject(requestPagarServicios); responseConsultaSaldo.EstatusCmv = EstatusCMV.Error; responseConsultaSaldo.MensajeCmv = e.Message + " | " + e.StackTrace; return(responseConsultaSaldo); } catch (Exception ex) { _ExceptionPagarServicios exceptionPagarServicios = new _ExceptionPagarServicios(); exceptionPagarServicios.Codigo = -1; exceptionPagarServicios.Mensaje = ex.Message; throw new FaultException <_ExceptionPagarServicios>(exceptionPagarServicios, "Error personalizado por Exception | " + ex.Message, new FaultCode("-1")); } return(null); }