Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/05/2013, 07:48
alexperaza
 
Fecha de Ingreso: diciembre-2012
Mensajes: 178
Antigüedad: 12 años, 1 mes
Puntos: 2
Pregunta Problemas con el IPN paypal

Bueno espero esten bien
Pues tengo un pequeño problema con el ipn de paypal cuando un usuario realiza el pago y esta verificada y completada la transaccion necesito que me actualice unos campos en mi base de datos y que me inserte el ID de la transaccion pero al final no hace nada de nada y siempre recibo el pago.. les dejo el codigo para que echen un vistazo PD. Estoy desesperado
ESTE ES EL BOTON
Código PHP:
Ver original
  1. <div class = "boton">
  2. <?php  //Variable para guardar la ruta hacia la clase  Class.PayPalEWP.php
  3. $cert_id = 'LLW2ULUAYYKUS'; //Id del certificado
  4. include("Class.PayPalEWP.php"); //Ruta hacia la clase  
  5. $paypal = new PayPalEWP();
  6. $paypal->setTempFileDirectory("tmp"); // HAY que crear una carpeta tmp en el directorio de la clase
  7. $paypal->setCertificate("my-pubcert.pem", "my-prvkey.pem");
  8. $paypal->setPayPalCertificate("paypal_cert_pem.txt");
  9. $paypal->setCertificateID($cert_id);  
  10.  
  11. $boton1 = array(
  12.         'cmd' => '_xclick',
  13.         'cert_id' => $cert_id,
  14.         'business' => '[email protected]',                
  15.         'receiver_email' => '[email protected]',                
  16.         'custom' => $row_BotonPaypal['id_principal'] ,         //Por si quieres añadir algún dato más
  17.         'item_name' => 'Cuenta premium en Clasificados Online',           // Nombre del objeto que vendemos
  18.         'currency_code' => 'USD',                             //Tipo de moneda
  19.         'amount' => '0.01',                                     //Precio
  20.         'lc' => 'ES',                                         //Idioma
  21.         'no_note' => '1',                                     //1-0 Mostrar cuadro de texto
  22.         'no_shipping' => '1',                                  
  23.         'return' => 'http://clasificadosonline.comxa.com/return.php',                    //Url de retorno a la que nos devuelve paypal al comprar (incluido en el tuto)
  24.         'cancel_return' => 'http://clasificadosonline.comxa.com',             //Url a la que nos devuelve al cancelar la compra
  25.         'notify_url' => 'http://clasificadosonline.comxa.com/ipn.php',                //Url de notificación dónde se realiza el IPN (incluido en el tuto)
  26.         'cbt' => 'Texto Voler a mi página',
  27.    
  28.    
  29.     );
  30.      
  31. ?>
  32.  
  33.  
  34.   <form action="https://www.paypal.com/cgi-bin/webscr" method="POST" name= "form1">
  35.  
  36.   <input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="cmd" value="_s-xclick">
  37.   <table width="296" border="1">
  38.     <tr>
  39.       <td>Inserte la clave de registro de su PRODUCTO</td>
  40.       <td><span id="sprytextfield1">
  41.       <input name="id_PRODUCTO" id ="id_PRODUCTO" type="text" />
  42.       <span class="textfieldRequiredMsg">recuerde que tiene que rellenar este campo.</span><span class="textfieldInvalidFormatMsg">Su codigo es solamente en numeros.</span></span></td>
  43.     </tr>
  44.   </table>
  45.   <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----<?php echo $paypal->encryptButton($boton1); ?>-----END PKCS7-----"/>
  46.  
  47.   <input type="image" src="https://www.paypal.com/es_XC/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal, la forma más segura y rápida de pagar en línea.">
  48.   <img alt="" border="0" src="https://www.paypal.com/es_XC/i/scr/pixel.gif" width="1" height="1"></p></div>
  49. </form>

ESTE ES EL IPN
Código PHP:
Ver original
  1. <?php require_once('Connections/clasi.php'); ?>
  2. <?php
  3.  
  4. // STEP 1: Read POST data
  5.  
  6. // reading posted data from directly from $_POST causes serialization
  7. // issues with array data in POST
  8. // reading raw POST data from input stream instead.
  9. $raw_post_data = file_get_contents('php://input');
  10. $raw_post_array = explode('&', $raw_post_data);
  11. $myPost = array();
  12. foreach ($raw_post_array as $keyval) {
  13.   $keyval = explode ('=', $keyval);
  14.   if (count($keyval) == 2)
  15.      $myPost[$keyval[0]] = urldecode($keyval[1]);
  16. }
  17. // read the post from PayPal system and add 'cmd'
  18. $req = 'cmd=_notify-validate';
  19. if(function_exists('get_magic_quotes_gpc')) {
  20.    $get_magic_quotes_exists = true;
  21. }
  22. foreach ($myPost as $key => $value) {        
  23.    if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
  24.         $value = urlencode(stripslashes($value));
  25.    } else {
  26.         $value = urlencode($value);
  27.    }
  28.    $req .= "&$key=$value";
  29. }
  30.  
  31.  
  32. // STEP 2: Post IPN data back to paypal to validate
  33.  
  34. $ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
  35. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  36. curl_setopt($ch, CURLOPT_POST, 1);
  37. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  38. curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
  39. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
  40. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
  41. curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
  42. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
  43.  
  44. // In wamp like environments that do not come bundled with root authority certificates,
  45. // please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
  46. // of the certificate as shown below.
  47. // curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__) . '/cacert.pem');
  48. if( !($res = curl_exec($ch)) ) {
  49.     // error_log("Got " . curl_error($ch) . " when processing IPN data");
  50.     echo "error con el ipn";
  51.     curl_close($ch);
  52.     exit;
  53. }
  54.  
  55.  
  56. // STEP 3: Inspect IPN validation result and act accordingly
  57.  
  58. if (strcmp ($res['status'], "VERIFIED") == 0) {
  59.     if($payment_status=='Completed'){
  60.         mysql_select_db($database_clasi, $clasi);
  61.         $query_txnid=mysql_query("SELECT txn_id FROM log WHERE txn_id='".$txn_id."'");
  62.         $txnid = mysql_query($query_txnid, $clasi) or die(mysql_error());
  63.         if(mysql_num_rows($txn_id_check)!=1){
  64.             if($receiver_email=='[email protected]'){
  65.                 if($payment_amount=='0.01' && $payment_currency=='USD'){
  66.                     //ADD txn_id A DB
  67.                      $insertSQL = sprintf("INSERT INTO log (txn_id, email) VALUES (%s, %s)",
  68.                                             GetSQLValueString($txn_id , "text"),
  69.                                             GetSQLValueString( $payer_email, "text"));
  70.                                              mysql_select_db($database_clasi, $clasi);
  71.                                     $Result1 = mysql_query($insertSQL, $clasi) or die(mysql_error());
  72.                    
  73.                     //ACTUALIZAR PREMIUM A 1
  74.                    
  75.  
  76.            
  77.                                             mysql_select_db($database_clasi, $clasi);
  78.                             $query_ConsulLocal = "UPDATE principal SET premium='1' WHERE id_principal='".$PRODUCTO_id."'";
  79.                             $ConsulLocal = mysql_query($query_ConsulLocal, $clasi) or die(mysql_error());
  80.                            
  81.                            
  82.  
  83.                    
  84.                     }
  85.                 }
  86.             }
  87.        
  88.         }
  89.    
  90.     // assign posted variables to local variables
  91.     $item_name = $_POST['item_name'];
  92.     $item_number = $_POST['item_number'];
  93.     $payment_status = $_POST['payment_status'];
  94.     $payment_amount = $_POST['mc_gross'];
  95.     $payment_currency = $_POST['mc_currency'];
  96.     $txn_id = $_POST['txn_id'];
  97.     $receiver_email = $_POST['receiver_email'];
  98.     $payer_email = $_POST['payer_email'];
  99.     $PRODUCTO_id=mysql_real_escape_string($_POST['custom']);
  100. } else if (strcmp ($res, "INVALID") == 0) {
  101.     // log for manual investigation
  102. }
  103. ?>

espero me ayuden