Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Send an empty HTTP 200 OK response to acknowledge receipt of the notification
- header('HTTP/1.1 200 OK');
- // Assign payment notification values 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'];
- $txn_type = $_POST['txn_type'];
- $steamid = str_replace("STEAM_0","STEAM_1",$_POST['option_selection2']); //Custom Field
- $receiver_email = $_POST['receiver_email'];
- $payer_email = $_POST['payer_email'];
- writeMsg($txn_type . " " . $steamid . " " . $receiver_email);
- $req = 'cmd=_notify-validate'; // Add 'cmd=_notify-validate' to beginning of the acknowledgement
- foreach ($_POST as $key => $value) { // Loop through the notification NV pairs
- $value = urlencode(stripslashes($value)); // Encode these values
- $req .= "&$key=$value"; // Add the NV pairs to the acknowledgement
- }
- $header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
- $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
- $header .= "Host: www.paypal.com\r\n";
- $header .= "Connection: close\r\n";
- $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
- // Open a socket for the acknowledgement request
- $fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
- // Send the HTTP POST request back to PayPal for validation
- fputs($fp, $header . $req);
- while (!feof($fp)) { // While not EOF
- $res = fgets($fp, 1024); // Get the acknowledgement response
- $res = trim($res);
- fwrite($myfile, $res);
- if (strcmp ($res, "VERIFIED") == 0) { // Response contains VERIFIED - process notification
- $servername = "1.1.1.1";
- $username = "username";
- $password = "password";
- $dbname = "store";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error) {
- writeMsg("Connection failed: " . $conn->connect_error);
- }
- //Do Stuff
- }
- else if (strcmp ($res, "INVALID") == 0) { // Response contains INVALID - reject notification
- //Invalid
- }
- }
- function writeMsg($message) {
- $file = 'log.txt';
- $current = file_get_contents($file);
- $current .= date("D M j G:i:s") . " - " . $message . "\n";
- file_put_contents($file, $current);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement