turt2live

Untitled

Jun 25th, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.57 KB | None | 0 0
  1. <?php
  2.  
  3. //to init db
  4. include 'class.php';
  5. $class = new account($_GET['debug']);
  6.  
  7.  
  8. // read the post from PayPal system and add 'cmd'
  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.paypal.com', 443, $errno, $errstr, 30);
  21.  
  22. // assign posted variables to local variables
  23. $item_name = $_POST['item_name'];
  24. $item_number = $_POST['item_number'];
  25. $payment_status = $_POST['payment_status'];
  26. $payment_amount = $_POST['mc_gross'];
  27. $payment_currency = $_POST['mc_currency'];
  28. $txn_id = $_POST['txn_id'];
  29. $receiver_email = $_POST['receiver_email'];
  30. $payer_email = $_POST['payer_email'];
  31.  
  32. if (!$fp) {
  33.     // HTTP ERROR
  34. } else {
  35.     fputs ($fp, $header . $req);
  36.     while (!feof($fp)) {
  37.     $res = fgets ($fp, 1024);
  38.         if (strcmp ($res, "VERIFIED") == 0) {
  39.             //Check if completed
  40.             if($payment_status == "Completed"){
  41.                 if($payment_amount==$class->getCostForItem($item_name)&&$payment_currency=="CAD"){ //If valid
  42.                     if($receiver_email==$class->getAdminEmail()){
  43.                         $class->doActionForItem($item_name,$payer_email,$item_number);
  44.                     }
  45.                 }
  46.             }else{
  47.                 $class->doActionForFailedItem($item_name,$payer_email,$item_number);
  48.             }
  49.         }
  50.         else if (strcmp ($res, "INVALID") == 0) {
  51.             // log for manual investigation
  52.         }
  53.     }
  54.     fclose ($fp);
  55. }
  56. ?>
Advertisement
Add Comment
Please, Sign In to add comment