Advertisement
Guest User

listener.php

a guest
Apr 10th, 2016
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.53 KB | None | 0 0
  1. <?php
  2.  
  3.   // Send an empty HTTP 200 OK response to acknowledge receipt of the notification
  4.   header('HTTP/1.1 200 OK');
  5.   // Assign payment notification values to local variables
  6.   $item_name        = $_POST['item_name'];
  7.   $item_number      = $_POST['item_number'];
  8.   $payment_status   = $_POST['payment_status'];
  9.   $payment_amount   = $_POST['mc_gross'];
  10.   $payment_currency = $_POST['mc_currency'];
  11.   $txn_id           = $_POST['txn_id'];
  12.   $txn_type         = $_POST['txn_type'];
  13.   $steamid          = str_replace("STEAM_0","STEAM_1",$_POST['option_selection2']); //Custom Field
  14.   $receiver_email   = $_POST['receiver_email'];
  15.   $payer_email      = $_POST['payer_email'];
  16.   writeMsg($txn_type . " " . $steamid . " " . $receiver_email);
  17.   $req = 'cmd=_notify-validate';               // Add 'cmd=_notify-validate' to beginning of the acknowledgement
  18.  
  19.   foreach ($_POST as $key => $value) {         // Loop through the notification NV pairs
  20.     $value = urlencode(stripslashes($value));  // Encode these values
  21.     $req  .= "&$key=$value";                   // Add the NV pairs to the acknowledgement
  22.   }
  23.  
  24.   $header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
  25.   $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  26.   $header .= "Host: www.paypal.com\r\n";
  27.   $header .= "Connection: close\r\n";
  28.   $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  29.  
  30.   // Open a socket for the acknowledgement request
  31.   $fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
  32.  
  33.   // Send the HTTP POST request back to PayPal for validation
  34.   fputs($fp, $header . $req);
  35.   while (!feof($fp)) {                     // While not EOF
  36.     $res = fgets($fp, 1024);               // Get the acknowledgement response
  37.     $res = trim($res);
  38.     fwrite($myfile, $res);
  39.     if (strcmp ($res, "VERIFIED") == 0) {  // Response contains VERIFIED - process notification
  40.       $servername = "1.1.1.1";
  41.       $username = "username";
  42.       $password = "password";
  43.       $dbname = "store";
  44.      
  45.       $conn = new mysqli($servername, $username, $password, $dbname);
  46.      
  47.       if ($conn->connect_error) {
  48.         writeMsg("Connection failed: " . $conn->connect_error);
  49.       }
  50.  
  51.       //Do Stuff
  52.  
  53.     }
  54.     else if (strcmp ($res, "INVALID") == 0) { // Response contains INVALID - reject notification
  55.  
  56.       //Invalid
  57.     }
  58.   }
  59.  
  60.   function writeMsg($message) {
  61.     $file = 'log.txt';
  62.     $current = file_get_contents($file);
  63.     $current .= date("D M j G:i:s") . " - " . $message . "\n";
  64.     file_put_contents($file, $current);
  65.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement