Foros del Web » Programación para mayores de 30 ;) » Java »

Problema jsp y ipn de paypal

Estas en el tema de Problema jsp y ipn de paypal en el foro de Java en Foros del Web. Hola chicos, estoy como loco buscando solución a este problema... vereis el ipn que he programado inserta demasiado en base de datos, solo debería insertar ...
  #1 (permalink)  
Antiguo 03/09/2012, 09:54
 
Fecha de Ingreso: junio-2008
Mensajes: 165
Antigüedad: 15 años, 10 meses
Puntos: 6
Problema jsp y ipn de paypal

Hola chicos, estoy como loco buscando solución a este problema... vereis el ipn que he programado inserta demasiado en base de datos, solo debería insertar un registro con completado, pendiente... etc en bd,, pero no es asi por algun motivo inserta todos:

Código ASP:
Ver original
  1. <%@ page import="java.util.*"%>
  2. <%@ page import="java.net.*"%>
  3. <%@ page import="java.io.*"%>
  4. <%@page import="java.sql.DriverManager"%>
  5. <%@page import="java.sql.SQLException"%>
  6. <%@page import="java.sql.Connection"%>
  7. <%@page import="java.sql.Statement"%>
  8. <%@page import="java.sql.ResultSet"%>
  9. <%@page import="mk.webapps.xxx.server.DBAccess"%>
  10. <%@page import="java.util.Date"%>
  11. <%@ page import="java.text.SimpleDateFormat"%>
  12. <%
  13.     // read post from PayPal system and add 'cmd'
  14.     Enumeration en = request.getParameterNames();
  15.     String str = "cmd=_notify-validate";
  16.     while (en.hasMoreElements()) {
  17.         String paramName = (String) en.nextElement();
  18.         String paramValue = request.getParameter(paramName);
  19.         str = str + "&" + paramName + "=" + URLEncoder.encode(paramValue);
  20.     }
  21.  
  22.     // post back to PayPal system to validate
  23.     // NOTE: change http: to https: in the following URL to verify using SSL (for increased security).
  24.     // using HTTPS requires either Java 1.4 or greater, or Java Secure Socket Extension (JSSE)
  25.     // and configured for older versions.
  26.     //URL u = new URL("https://www.paypal.com/cgi-bin/webscr");
  27.     URL u = new URL("https://www.sandbox.paypal.com/cgi-bin/webscr");
  28.     URLConnection uc = u.openConnection();
  29.     uc.setDoOutput(true);
  30.     uc.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
  31.     uc.setRequestProperty("Host", "www.sandbox.paypal.com");
  32.     PrintWriter pw = new PrintWriter(uc.getOutputStream());
  33.     pw.println(str);
  34.     pw.close();
  35.  
  36.     BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
  37.     String res = in.readLine();
  38.     in.close();
  39.  
  40.     // assign posted variables to local variables
  41.     String itemName = request.getParameter("item_name");
  42.     String itemNumber = request.getParameter("item_number");
  43.     String paymentStatus = request.getParameter("payment_status");
  44.     String paymentAmount = request.getParameter("mc_gross");
  45.     String paymentCurrency = request.getParameter("mc_currency");
  46.     String txnId = request.getParameter("txn_id");
  47.     String txnType = request.getParameter("txn_type");
  48.     String receiverEmail = request.getParameter("receiver_email");
  49.     String payerEmail = request.getParameter("payer_email");
  50.     String custom = request.getParameter("custom");
  51.  
  52. //  String dbprefix = session.getAttribute("db_prefix").toString();     // For production systems
  53.     String dbprefix = "dev_";   // For paypal testing
  54.                 Connection conn = null;
  55.                 Statement select = null;
  56.                 ResultSet result = null;
  57.     try
  58. {
  59.                         DBAccess dba = new DBAccess(request);
  60.                         conn = dba.getDBConn();
  61. //                        String sql = "";
  62.                         select = conn.createStatement();
  63.  
  64. }
  65. catch(Exception e)
  66. {
  67. }
  68.     select.executeUpdate("insert into dev_xxx.garbage values ('" + res + "');");
  69.     //check notification validation
  70.     if (res.equals("VERIFIED")) {
  71. //      Connection conn = null;
  72. //      Statement select = null;
  73. //      ResultSet result = null;
  74.         try {
  75. //          DBAccess dba = new DBAccess(request);
  76. //          conn = dba.getDBConn();
  77.             String sql = "";
  78. //          select = conn.createStatement();
  79.             Date dDate = new Date();
  80.             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  81.             String sDate = sdf.format(dDate);
  82.             dDate.setMonth(dDate.getMonth() + 1);
  83.             String sDateMes = sdf.format(dDate);
  84.             select.executeUpdate("insert into dev_xxx.garbage values ('" + paymentStatus + "');");
  85.             select.executeUpdate("insert into dev_xxx.garbage values ('" + txnType + "');");
  86.             if (paymentStatus.equals("Completed") && txnType.equals("subscr_payment")) {//pago completado y periódico
  87.                 if (paymentAmount.equals("9.90")) {
  88.                     sql = "insert into "+ dbprefix + "xxx.UserPremium (IdUser, MailPaypal, IdPromo, IdUserType, IdPremium, FirstDate, EndDate) values("+ custom + ",'" + payerEmail + "', null, 2, 2, '"+ sDate + "', '" + sDateMes + "')";
  89.                     select.executeUpdate(sql);
  90.                 } else if (paymentAmount.equals("99.00")) {
  91.                     dDate.setMonth(dDate.getMonth() - 1);
  92.                     dDate.setYear(dDate.getYear() + 1);
  93.                     String sDateYear = sdf.format(dDate);
  94.                     sql = "insert into "+ dbprefix + "xxx.UserPremium (IdUser, MailPaypal, IdPromo, IdUserType, IdPremium, FirstDate, EndDate) values("+ custom + ",'" + payerEmail + "', null, 2, 2, '"+ sDate + "', '" + sDateYear + "')";
  95.                     select.executeUpdate(sql);
  96.                 }
  97.                 else{
  98.                     select.executeUpdate("insert into dev_xxx.garbage values ('" + paymentAmount + "');");
  99.                 }
  100.             }
  101.             else if (txnType.equals("subscr_eot") || txnType.equals("subscr_cancel")){//suscripcion cancelada
  102.                 String [] datos = custom.split(";");
  103.                 sql = "insert into "+ dbprefix + "xxx.UserPremium (IdUser, MailPaypal, IdPromo, IdUserType, IdPremium, FirstDate, EndDate) values("+ datos[0] + ",'" + payerEmail + "', null, 2, 3, '"+ sDate + "', '" + sDateMes + "')";
  104.                 select.executeUpdate(sql);
  105.                 if (datos[1].equals("avanzado")){
  106.                     sql = "insert into "+ dbprefix + "xxx.UserPremium (IdUser, MailPaypal, IdPromo, IdUserType, IdPremium, FirstDate, EndDate) values("+ datos[0] + ",'" + payerEmail + "', null, 1, 3, '"+ sDate + "', '" + sDateMes + "')";
  107.                     select.executeUpdate(sql);
  108.                     sql = "update "+ dbprefix +"xxx.Users set Valid=-1 WHERE Id=" + datos[0] ;
  109.                     select.executeUpdate(sql);
  110.                 }
  111.                 // check that paymentStatus=Completed
  112.                 // check that txnId has not been previously processed
  113.                 // check that receiverEmail is your Primary PayPal email
  114.                 // check that paymentAmount/paymentCurrency are correct
  115.                 // process payment
  116.             }
  117.         } catch (Exception e) {
  118.             conn.rollback();
  119.         }
  120.         finally{
  121.             select.close();
  122.             result.close();
  123.             conn.close();
  124.         }
  125.  
  126.     }
  127.     else if (res.equals("INVALID"))
  128.     {
  129.         select.executeUpdate("insert into dev_xxx.garbage values ('##INVALID##');");
  130.         // log for investigation
  131.     } else {
  132.         // error
  133.         select.executeUpdate("insert into dev_xxx.garbage values ('#"+res+"#');");
  134.     }
  135. %>

Etiquetas: ipn, jsp, paypal, programa, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 08:04.