Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/05/2013, 12:00
alexperaza
 
Fecha de Ingreso: diciembre-2012
Mensajes: 178
Antigüedad: 11 años, 4 meses
Puntos: 2
Pregunta Mi IPN no funciona en paypal

Hola como ya dias estoy tratando de poner paypal en mi pagina pero mi ipn no me funciona quisiera saber si me pudieran ayudar a identificar la falla de mi codigo gracias de ante mano
Boton
Código PHP:
Ver original
  1. <?php  //Variable para guardar la ruta hacia la clase  Class.PayPalEWP.php
  2. $cert_id = 'CTNEMDKBS5AVY'; //Id del certificado
  3. include("Class.PayPalEWP.php"); //Ruta hacia la clase  
  4. $paypal = new PayPalEWP();
  5. $paypal->setTempFileDirectory("tmp"); // HAY que crear una carpeta tmp en el directorio de la clase
  6. $paypal->setCertificate("my-pubcert.pem", "my-prvkey.pem");
  7. $paypal->setPayPalCertificate("paypal_cert_pem.txt");
  8. $paypal->setCertificateID($cert_id);  
  9.  
  10. $boton1 = array(
  11.         'cmd' => '_xclick',
  12.         'cert_id' => $cert_id,
  13.         'business' => '[email protected]',                
  14.         'receiver_email' => '[email protected]',                
  15.         'custom' => $row_BotonPaypal['id_principal'] ,         //Por si quieres añadir algún dato más
  16.         'item_name' => 'Cuenta premium en Clasificados Online',           // Nombre del objeto que vendemos
  17.         'currency_code' => 'USD',                             //Tipo de moneda
  18.         'amount' => '5.00',                                     //Precio
  19.         'lc' => 'ES',                                         //Idioma
  20.         'no_note' => '1',                                     //1-0 Mostrar cuadro de texto
  21.         'no_shipping' => '1',                                  
  22.         'return' => 'http://clasificadosonline.comxa.com/return.php',                    //Url de retorno a la que nos devuelve paypal al comprar (incluido en el tuto)
  23.         'cancel_return' => 'http://clasificadosonline.comxa.com',             //Url a la que nos devuelve al cancelar la compra
  24.         'notify_url' => 'http://clasificadosonline.comxa.com/ipn.php',                //Url de notificación dónde se realiza el IPN (incluido en el tuto)
  25.         'cbt' => 'Texto Voler a mi página',
  26.    
  27.    
  28.     );
  29.      
  30. ?>
  31.  
  32.  
  33.   <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST" name= "form1">
  34.  
  35.   <input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="cmd" value="_s-xclick">
  36.   <table width="296" border="1">
  37.     <tr>
  38.       <td>Inserte la clave de registro de su anuncio</td>
  39.       <td><span id="sprytextfield1">
  40.       <input name="id_anuncio" id ="id_anuncio" type="text" />
  41.       <span class="textfieldRequiredMsg">recuerde que tiene que rellenar este campa.</span><span class="textfieldInvalidFormatMsg">Su codigo es solamente en numeros.</span></span></td>
  42.     </tr>
  43.   </table>
  44.   <input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----<?php echo $paypal->encryptButton($boton1); ?>-----END PKCS7-----"/>
  45.  
  46.   <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.">
  47.   <img alt="" border="0" src="https://www.paypal.com/es_XC/i/scr/pixel.gif" width="1" height="1"></p></div>
  48. </form>

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.sandbox.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=='5.00' && $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='".$anuncio_id."'";
  79.                             $ConsulLocal = mysql_query($query_ConsulLocal, $clasi) or die(mysql_error());
  80.                            
  81.                            
  82.  
  83.                    
  84.                     }
  85.                 }
  86.             }
  87.        
  88.         }
  89.     // check whether the payment_status is Completed
  90.     // check that txn_id has not been previously processed
  91.     // check that receiver_email is your Primary PayPal email
  92.     // check that payment_amount/payment_currency are correct
  93.     // process payment
  94.  
  95.     // assign posted variables to local variables
  96.     $item_name = $_POST['item_name'];
  97.     $item_number = $_POST['item_number'];
  98.     $payment_status = $_POST['payment_status'];
  99.     $payment_amount = $_POST['mc_gross'];
  100.     $payment_currency = $_POST['mc_currency'];
  101.     $txn_id = $_POST['txn_id'];
  102.     $receiver_email = $_POST['receiver_email'];
  103.     $payer_email = $_POST['payer_email'];
  104.     $anuncio_id=mysql_real_escape_string($_POST['custom']);
  105. } else if (strcmp ($res, "INVALID") == 0) {
  106.     // log for manual investigation
  107. }
  108. ?>

ahorita estoy probando en sandbox pero ya lo probe en paypal y no me actualiza la tabla ni me inserta en txn_id en mi base de datos..