Advertisement
mamouth

paypal

Aug 23rd, 2012
1,671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. <?php/* Script de récupération et de vérification des données IPN de Paypal
  2.         Avi here:  https://cms.paypal.com/cms_content/US/en_US/files/developer/IPN_PHP_41.txt */
  3.  
  4. // read the post from PayPal system and add 'cmd'
  5. $req = 'cmd=_notify-validate';
  6.  
  7. foreach ($_POST as $cle => $valeur)
  8. {
  9.     $valeur = urlencode(stripslashes($valeur));
  10.     $req .= "&$cle=$valeur";
  11. }
  12.  
  13. // post back to PayPal system to validate
  14. $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
  15. $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  16. $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  17. $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);// Connect via SSL.
  18.  
  19. // assign posted variables to local variables
  20. $item_name = $_POST['item_name'];
  21. $item_number = $_POST['item_number'];
  22. $payment_status = $_POST['payment_status'];
  23. $payment_amount = $_POST['mc_gross'];
  24. $payment_currency = $_POST['mc_currency'];
  25. $txn_id = $_POST['txn_id'];
  26. $receiver_email = $_POST['receiver_email'];
  27. $payer_email = $_POST['payer_email'];
  28.  
  29. if (!$fp) // If we cannot connect to paypal, we display an error
  30. {
  31.     echo "Error, cannot connect to paypal, IPN datas haven't been reposted";
  32. }
  33. else
  34. {
  35.     fputs ($fp, $header . $req);// fputs=fwrite | We throw back $req via the previous connexion (called $fp)
  36.     while (!feof($fp))// Until it's not done : $fp
  37.     {
  38.         $res = fgets ($fp, 1024);
  39.         if (strcmp ($res, "VERIFIED") == 0)// If we find the word VERIFIED (if datas received match with data from transaction)
  40.         {
  41.             if ($payment_status=="Completed" AND $receiver_email=="adresse@domaine.com" AND $payment_amount==5 AND $payment_currency=="EUR")// If every parameters are good, we can process the order
  42.             {
  43.                 // What to do after the order (update database,...)
  44.             }
  45.         }
  46.         else if (strcmp ($res, "INVALID") == 0) // If we find the word INVALID (datas received != datas from transaction)
  47.         {
  48.             echo "Error with IPN datas";
  49.         }
  50.     }
  51. fclose ($fp);
  52. }
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement