Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php/* Script de récupération et de vérification des données IPN de Paypal
- Avi here: https://cms.paypal.com/cms_content/US/en_US/files/developer/IPN_PHP_41.txt */
- // read the post from PayPal system and add 'cmd'
- $req = 'cmd=_notify-validate';
- foreach ($_POST as $cle => $valeur)
- {
- $valeur = urlencode(stripslashes($valeur));
- $req .= "&$cle=$valeur";
- }
- // post back to PayPal system to validate
- $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
- $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
- $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
- $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);// Connect via SSL.
- // assign posted variables to local variables
- $item_name = $_POST['item_name'];
- $item_number = $_POST['item_number'];
- $payment_status = $_POST['payment_status'];
- $payment_amount = $_POST['mc_gross'];
- $payment_currency = $_POST['mc_currency'];
- $txn_id = $_POST['txn_id'];
- $receiver_email = $_POST['receiver_email'];
- $payer_email = $_POST['payer_email'];
- if (!$fp) // If we cannot connect to paypal, we display an error
- {
- echo "Error, cannot connect to paypal, IPN datas haven't been reposted";
- }
- else
- {
- fputs ($fp, $header . $req);// fputs=fwrite | We throw back $req via the previous connexion (called $fp)
- while (!feof($fp))// Until it's not done : $fp
- {
- $res = fgets ($fp, 1024);
- if (strcmp ($res, "VERIFIED") == 0)// If we find the word VERIFIED (if datas received match with data from transaction)
- {
- 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
- {
- // What to do after the order (update database,...)
- }
- }
- else if (strcmp ($res, "INVALID") == 0) // If we find the word INVALID (datas received != datas from transaction)
- {
- echo "Error with IPN datas";
- }
- }
- fclose ($fp);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement