protected void btnConsultar_Click(object sender, EventArgs e) { try { Servicio.PlaceToPlayPSEService.Authentication Auth = new Servicio.PlaceToPlayPSEService.Authentication(); Auth = CrearAutenticacion(); //Se instancion un objeto de Tipo PSEPORTCLIENTE Servicio.PlaceToPlayPSEService.PlacetoPay_PSEPortClient Servicio = new Servicio.PlaceToPlayPSEService.PlacetoPay_PSEPortClient(); //Se crea OBjeto para consultar la informacion de la transaccion Servicio.PlaceToPlayPSEService.TransactionInformation InformacionTransaccion = new Servicio.PlaceToPlayPSEService.TransactionInformation(); if (!string.IsNullOrEmpty(txtIdTransaccion.Text)) { InformacionTransaccion = Servicio.getTransactionInformation(Auth, int.Parse(txtIdTransaccion.Text)); if (InformacionTransaccion != null) { if (InformacionTransaccion.transactionState == "OK") { lblAprobada.Visible = true; lblRechazada.Visible = false; lblPendiente.Visible = false; lblAprobada.Text = "APROBADA"; lblRechazada.Text = ""; lblPendiente.Text = ""; txtDetalle.Visible = true; txtDetalle.Text = "Felicidades, su compra ha sido aprobada por el banco."; } if (InformacionTransaccion.transactionState == "PENDING") { lblAprobada.Visible = false; lblPendiente.Visible = true; lblRechazada.Visible = false; lblAprobada.Text = ""; lblPendiente.Text = "PENDIENTE"; lblRechazada.Text = ""; txtDetalle.Visible = true; txtDetalle.Text = InformacionTransaccion.responseReasonText; } if (InformacionTransaccion.transactionState == "FAILED") { lblAprobada.Visible = false; lblPendiente.Visible = false; lblRechazada.Visible = true; lblAprobada.Text = ""; lblPendiente.Text = ""; lblRechazada.Text = "FALLIDA"; txtDetalle.Visible = true; txtDetalle.Text = InformacionTransaccion.responseReasonText; } if (InformacionTransaccion.transactionState == "NOT_AUTHORIZED") { lblAprobada.Visible = false; lblPendiente.Visible = false; lblRechazada.Visible = true; lblAprobada.Text = ""; lblPendiente.Text = ""; lblRechazada.Text = "NO AUTORIZADA"; txtDetalle.Visible = true; txtDetalle.Text = InformacionTransaccion.responseReasonText; } } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar un Id de transacción.');</script>"); return; } } catch (Exception ex) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Se presentó un error en el proceso. Contacte al administrador del sistema.');</script>"); return; } }
protected void btnPagar_Click(object sender, EventArgs e) { #region Validaciones #region Validaciones Prrsona que paga if (cmbTipoBanca.SelectedValue == null || cmbTipoBanca.SelectedValue == "0") { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe seleccionar el Tipo de banca.');</script>"); return; } if (cmbBancos.SelectedValue == null || cmbBancos.SelectedValue == "0") { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe seleccionar el Banco.');</script>"); return; } //Validacion para ambiente de pruebas, para garantizar que se seleccione el banco de prueba y no genere errores por el tipo de conexion if (cmbBancos.SelectedValue != "1022") { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Por pruebas el Banco seleccionado debe ser BANCO UNION COLOMBIANO.');</script>"); return; } //Validar campos si se digitaron manualmente if (RBInfo.SelectedValue == "0") { #region Validar Campos si el user Digita if (cmbTipoIdentificacion.SelectedValue == null || cmbTipoIdentificacion.SelectedValue == "0") { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe seleccionar el Tipo de identificación.');</script>"); return; } if (string.IsNullOrEmpty(txtNroDocumento.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Documento.');</script>"); return; } if (string.IsNullOrEmpty(txtNombres.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Nombres.');</script>"); return; } if (string.IsNullOrEmpty(txtApellidos.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Apellidos.');</script>"); return; } if (string.IsNullOrEmpty(txtDireccion.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Dirección.');</script>"); return; } if (string.IsNullOrEmpty(txtTelFijo.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Teléfono fijo.');</script>"); return; } if (string.IsNullOrEmpty(txtTelMovil.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Teléfono móvil.');</script>"); return; } if (string.IsNullOrEmpty(txtEmail.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo E-mail.');</script>"); return; } if (!ComprobarFormatoEmail(txtEmail.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('MAil invalido.');</script>"); return; } if (string.IsNullOrEmpty(txtCiudad.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Ciudad.');</script>"); return; } if (string.IsNullOrEmpty(txtDepartamento.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Departamento.');</script>"); return; } if (string.IsNullOrEmpty(txtEmpresa.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Empresa.');</script>"); return; } #endregion } #endregion #region Validaciones Informacion Pago if (string.IsNullOrEmpty(txtReferenciaPago.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Referencia de pago.');</script>"); return; } if (string.IsNullOrEmpty(txtDescripcion.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Descripción.');</script>"); return; } if (string.IsNullOrEmpty(txtTotal.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Total.');</script>"); return; } if (double.Parse(txtTotal.Text) <= 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('El campo Total debe ser mayor a cero (0).');</script>"); return; } if (string.IsNullOrEmpty(txtImpuesto.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Impuesto.');</script>"); return; } if (double.Parse(txtImpuesto.Text) < 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('El campo Impuesto debe ser mayor a cero (0).');</script>"); return; } if (string.IsNullOrEmpty(txtBaseImpuesto.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Base impuesto.');</script>"); return; } if (double.Parse(txtBaseImpuesto.Text) < 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('El campo Base impuesto debe ser mayor a cero (0).');</script>"); return; } if (string.IsNullOrEmpty(txtPropinas.Text)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Debe ingresar el campo Propinas.');</script>"); return; } if (double.Parse(txtPropinas.Text) < 0) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('El campo Propinas debe ser mayor a cero (0).');</script>"); return; } #endregion #endregion Servicio.PlaceToPlayPSEService.Authentication Auth = new Servicio.PlaceToPlayPSEService.Authentication(); Auth = CrearAutenticacion(); //Se crea la isntancia de tipo Person para el PAgador, Comprador, y Shiping Servicio.PlaceToPlayPSEService.Person Pagador = new Servicio.PlaceToPlayPSEService.Person(); Servicio.PlaceToPlayPSEService.Person Comprador = new Servicio.PlaceToPlayPSEService.Person(); Servicio.PlaceToPlayPSEService.Person Shiping = new Servicio.PlaceToPlayPSEService.Person(); //Al objeto Pagador se le pasan los datos del cliente Pagador.document = txtNroDocumento.Text; Pagador.documentType = cmbTipoIdentificacion.SelectedValue == "1" ? "CC" : cmbTipoIdentificacion.SelectedValue == "2" ? "CE" : cmbTipoIdentificacion.SelectedValue == "3" ? "TI" : "PPN"; Pagador.firstName = txtNombres.Text; Pagador.lastName = txtApellidos.Text; Pagador.company = txtEmpresa.Text; Pagador.emailAddress = txtEmail.Text; Pagador.address = txtDireccion.Text; Pagador.city = txtCiudad.Text; Pagador.province = txtDepartamento.Text; Pagador.country = txtPais.Text; Pagador.phone = txtTelFijo.Text; Pagador.mobile = txtTelMovil.Text; //Se instancia un Objeto de Tipo PSETransactionRequest Servicio.PlaceToPlayPSEService.PSETransactionRequest oTransaccion = new Servicio.PlaceToPlayPSEService.PSETransactionRequest(); oTransaccion.bankCode = cmbBancos.SelectedValue.ToString(); oTransaccion.bankInterface = cmbTipoBanca.SelectedValue == "1" ? "0" : "1"; oTransaccion.returnURL = "http://localhost:61281/Respuesta.aspx"; oTransaccion.reference = txtReferenciaPago.Text; oTransaccion.description = txtDescripcion.Text; oTransaccion.language = "ES"; oTransaccion.currency = "COP"; oTransaccion.totalAmount = double.Parse(txtTotal.Text); oTransaccion.taxAmount = double.Parse(txtImpuesto.Text); oTransaccion.devolutionBase = double.Parse(txtBaseImpuesto.Text); oTransaccion.tipAmount = double.Parse(txtPropinas.Text); oTransaccion.payer = Pagador; oTransaccion.ipAddress = ObtenerIp(); oTransaccion.userAgent = "UNE"; //Se instancion un objeto de Tipo PSEPORTCLIENTE Servicio.PlaceToPlayPSEService.PlacetoPay_PSEPortClient Servicio = new Servicio.PlaceToPlayPSEService.PlacetoPay_PSEPortClient(); //Se crea el Obeto para guardar los datos de la transaccion Servicio.PlaceToPlayPSEService.PSETransactionResponse RespuestaTransaccion = new Servicio.PlaceToPlayPSEService.PSETransactionResponse(); //Se crea OBjeto para consultar la informacion de la transaccion Servicio.PlaceToPlayPSEService.TransactionInformation InformacionTransaccion = new Servicio.PlaceToPlayPSEService.TransactionInformation(); //Se manda a crear la transaccion y se guarda la respuesta RespuestaTransaccion = Servicio.createTransaction(Auth, oTransaccion); //Se valida que la transaccion sea exitosa para re dirigir al usuario a la pagina del banco if (RespuestaTransaccion.returnCode == "SUCCESS") { //Se redirecciona a pagina para que el ID de la transaccion sea visible y el user tome nota de el Response.Redirect("http://localhost:61281/Respuesta.aspx?IdTransaccion=" + RespuestaTransaccion.transactionID.Value + "&Ruta=" + RespuestaTransaccion.bankURL); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Se presento un error, intentalo de nuevo.');</script>"); return; } }