Guest User

ipn

a guest
Jul 6th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  header('Content-type: text/html; charset=utf-8');
  4.  
  5.   require_once('../config/baseDonnees.php');
  6.  
  7. // read the post from PayPal system and add 'cmd'
  8. $email_account="[email protected]";
  9. $req = 'cmd=_notify-validate';
  10.  
  11. foreach ($_POST as $key => $value) {
  12. $value = urlencode(stripslashes($value));
  13. $req .= "&$key=$value";
  14. }
  15.  
  16. // post back to PayPal system to validate
  17.     $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
  18.     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  19.     $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  20.     $fp = fsockopen ('ssl://www.sandbox.paypal.com', 80, $errno, $errstr, 30);
  21.  
  22. // assign posted variables to local variables
  23.     $item_name = $_POST['item_name'];
  24.     $item_number = $_POST['item_number']; // id commande
  25.     $payment_status = $_POST['payment_status']; // Completed,
  26.     $payment_amount = $_POST['mc_gross']; //0.01
  27.     $payment_currency = $_POST['mc_currency']; //CAD
  28.     $txn_id = $_POST['txn_id'];
  29.     $receiver_email = $_POST['receiver_email'];
  30.     $payer_email = $_POST['payer_email'];
  31.     parse_str($_POST['custom'], $custom);
  32.  
  33. if (!$fp)
  34. {
  35. }
  36. else
  37. {
  38.     fputs ($fp, $header . $req);
  39.     while (!feof($fp))
  40.     {
  41.  
  42.         $res = fgets ($fp, 1024);
  43.  
  44.         if (strcmp ($res, "VERIFIED") == 0)
  45.         {
  46.  
  47.             if ($payment_status == "Completed")
  48.             {
  49.                 if($email_account == $receiver_email)
  50.                 {
  51.    
  52.  
  53. $pseudo="1";
  54. $item_name="1";
  55.                     $req = $bdd->prepare('INSERT INTO commande(id_user, montant) VALUES(:pseudo, :offre)');
  56.                     $req -> bindParam(':pseudo', $pseudo, PDO::PARAM_STR);
  57.                     $req -> bindParam(':offre', $item_name);
  58.                     $req -> execute();     
  59.  
  60.                    
  61.                    
  62.                 }
  63.                
  64.             }
  65.         }
  66.         else if (strcmp ($res, "INVALID") == 0)
  67.         {
  68.  
  69.         }
  70.     }
  71.     fclose ($fp);
  72. }
  73. ?>
Add Comment
Please, Sign In to add comment