Test PayPal ipn to file


/ Published in: PHP
Save to your folder(s)

Writes to a text file, test.txt, instead of email for the purposes of testing.


Copy this code and paste it in your HTML
  1. <?php
  2. $req = 'cmd=_notify-validate';
  3.  
  4. foreach ($_POST as $key => $value) {
  5. $value = urlencode(stripslashes($value));
  6. $req .= "&$key=$value";
  7. }
  8.  
  9. // post back to PayPal system to validate
  10. $header .= "POST /cgi-bin/webscr HTTP/1.0
  11. ";
  12. $header .= "Content-Type: application/x-www-form-urlencoded
  13. ";
  14. $header .= "Content-Length: " . strlen($req) . "
  15.  
  16. ";
  17. $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
  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) {
  30.  
  31. // HTTP ERROR
  32.  
  33. } else {
  34. fputs ($fp, $header . $req);
  35. while (!feof($fp)) {
  36. $res = fgets ($fp, 1024);
  37. if (strcmp ($res, "VERIFIED") == 0) {
  38. $fh = fopen("test.txt","w");
  39. fwrite($fh, $payer_email);
  40. }else if (strcmp ($res, "INVALID") == 0) {
  41. //Send Email To You
  42. }
  43. }
  44.  
  45. fclose ($fp);
  46. }
  47. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.