adivirus Posted August 7, 2013 Posted August 7, 2013 Hi, i got an email from paypal saying : Merchants need to update their IPN and/or PDT scripts to use HTTP 1.1, and include the “Host” and “Connection: close” HTTP header in the IPN postback script. PHP // post back to PayPal system to validate $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\r\n"; so i have modified the ipn_donator.php script with these lines.. so now i have something like // post back to PayPal system to validate $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\r\n"; $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); but the players are not credited automatically with the packs as they used to be before with HTTP 1.0, what do i have to change to work ? i have tried to modifiy the $fp variable to $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); .. but doesnt works. anyone knows? thanks. Quote
sniko Posted August 7, 2013 Posted August 7, 2013 I had a few problems setting up a listener a few days ago. Run the process through sandbox, and dump the return headers somewhere (in a database table, or .txt file) for you to evaluate them. This helped me, as I was running into "302" and "400" errors, which stopped the crediting process. Quote
adivirus Posted August 7, 2013 Author Posted August 7, 2013 can you elaborate and tell me how to do that ? i know this is sandbox: http://www.sandobx.paypal.com .. right ? but how can i dump the result into a file? thanks Quote
sniko Posted August 7, 2013 Posted August 7, 2013 I used Developer PayPal. /* * Put this in the white loop * I think, from memory, the variable is $fp; */ $contents = $fp; $file = 'paypal_headers.txt'; $current = file_get_contents($file); $current .= $contents ."\n"; file_put_contents($file, $current); Quote
adivirus Posted August 8, 2013 Author Posted August 8, 2013 thanks, tested with a payment and got this inside the file: 'Resource id #6' :| any idea.. ? Quote
HauntedDawg Posted August 8, 2013 Posted August 8, 2013 That would mean usually a resource either from MySQL or fsockopen ready to be used. Make sure you use var_dump around what ever you are entering into the file. That will help you a little more with what the error is? Quote
adivirus Posted August 8, 2013 Author Posted August 8, 2013 i don't know where should i put var_dump ( file_put_contents($file, $current); <-- HERE ? ), do you have a working ipn with HTTP 1.1 ? :| if i switch back to HTTP 1.0 everything works.. Quote
adivirus Posted August 8, 2013 Author Posted August 8, 2013 i have also tried with this line, as i heard it's important.. but still not working: while (!feof($fp)) { $res = fgets ($fp, 1024); $res = trim($res); //NEW & IMPORTANT Quote
HauntedDawg Posted August 8, 2013 Posted August 8, 2013 file_put_contents($file, print_r($current)); Quote
adivirus Posted August 8, 2013 Author Posted August 8, 2013 well, now i get only "1" in that file .. do you use HTTP 1.1 with your ipn donator ? if yes how did u make it work ? Quote
HauntedDawg Posted August 8, 2013 Posted August 8, 2013 Post your hole ipn_donator.php here. Seems like your issue is not just with you: http://stackoverflow.com/questions/11810344/paypal-ipn-bad-request-400-error/12682872#12682872 Quote
adivirus Posted August 9, 2013 Author Posted August 9, 2013 is there anyone using the new HTTP 1.1 ? :) anyway.. we will all be forced to use it from october as paypal says.. Quote
adivirus Posted August 21, 2013 Author Posted August 21, 2013 common, nobody uses the new HTTP. 1.1 required by paypal starting october? ipn_donator will not work anymore with HTTP 1.0 as it's now, so the system will not credit users after they buy a pack unless the ipn_donator is modified to use HTTP 1.1 // post back to PayPal system to validate $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\r\n"; as i said before, this is the only change i made in the original ipn_donator so it's not working .. anyone has a working one? thanks.. Quote
rockwood Posted August 22, 2013 Posted August 22, 2013 (edited) it is very weird problem Edited August 22, 2013 by rockwood Quote
sniko Posted August 22, 2013 Posted August 22, 2013 Try this. I've run it through sandbox and live, and it worked. <?php defined('paypal_sandbox', TRUE); //It's set to sandbox.paypal.com $link = 'www.paypal.com'; if (paypal_sandbox) { $link = "www.sandbox.paypal.com"; } // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; $req .= '&' . http_build_query($_POST); // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n"; $header .= "Host: " . $link . "\r\n\r\n"; $fp = fsockopen('ssl://' . $link, 443, $errno, $errstr, 30); // assign posted variables 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']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; $site_id = $_POST['custom']; $custom = $_POST['custom']; if (!$fp) { // HTTP ERROR } else { fputs($fp, $header . $req); while (!feof($fp)) { $res = fgets($fp, 1024); if (strcmp($res, "VERIFIED") == 0) { //Paypal returned VERIFIED } } else if (strcmp($res, "INVALID") == 0) { //Paypal returned INVALID } } fclose($fp); } ?> Quote
adivirus Posted August 23, 2013 Author Posted August 23, 2013 Hello, well, it has $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; my ipn_donator works too with HTTP 1.0 but it's not working with HTTP 1.1 as paypal forces use to use from october. Have u tried with HTTP 1.1 too ? thanks. this is what they say: Action Required before the 7th of October, 2013 Merchants need to update their IPN and/or PDT scripts to use HTTP 1.1, and include the “Host” and “Connection: close” HTTP header in the IPN postback script. PHP // post back to PayPal system to validate $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\r\n"; Quote
jedigunz Posted August 23, 2013 Posted August 23, 2013 so what do i do do i add that in place off my ipn_donator.php i really need some help with this,. im using cronus's donator mod,.. could somebody recode this for me please <? //------------------------------------------------ //Mod created by Cronus. //You can find more of his mods for sale //and join his MCCode developers community here: //http://www.cronwerks.com/forum //------------------------------------------------ $primarypaypal="[email protected]"; $currency="GBP"; include "config.php"; global $_CONFIG; define("MONO_ON", 1); require "class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; require 'global_func.php'; $set=array(); $settq=$db->query("SELECT * FROM settings"); while($r=$db->fetch_row($settq)) { $set[$r['conf_name']]=$r['conf_value']; } // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); // assign posted variables 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']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // check the payment_status is Completed if($payment_status != "Completed") { fclose ($fp);die(""); } // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email if($receiver_email != $primarypaypal) { fclose ($fp);die(""); } // check that payment_amount/payment_currency are correct if($payment_currency != "GBP") { fclose ($fp);die(""); } // parse for pack $packr=explode('|',$item_name); if(str_replace("www.","",$packr[0]) != str_replace("www.","",$_SERVER['HTTP_HOST'])) { fclose($fp); die(""); } $meki=$db->query("SELECT * FROM dpacks WHERE id={$packr[1]} AND active=1"); if($db->num_rows($meki) == 0) { fclose($fp); die(""); } else { $r=$db->fetch_row($meki); } $total=$r['price']*$packr[2]; if($total != $payment_amount) { fclose($fp); die(""); } // grab IDs $buyer=$packr[3]; $number=$packr[2]; // all seems to be in order, credit it. $time=time(); $db->query("INSERT INTO dplogs VALUES('','$buyer',{$r['id']},'$number','$time', '$payment_amount')") or die(mysql_error()); $db->query("UPDATE users SET donated=donated+$payment_amount WHERE userid={$r['id']}"); $db->query("UPDATE users SET donated=donated+$payment_amount WHERE userid=1"); if($r['bogo'] > 0) { $add=floor($number/$r['bogo']); $number=$number+$add; } $db->query("INSERT INTO inventory VALUES('',{$r['id']},'$buyer','$number')",$c) or die(mysql_error()); // process payment event_add($buyer, "Your donation has been successfully credited to you. Thank you for your support.", $c); event_add(1, "ID $buyer has purchased $number {$r['name']}(s) for $$payment_amount.", $c); } else if (strcmp ($res, "INVALID") == 0) { } } fclose ($fp); } ?> Quote
jedigunz Posted August 23, 2013 Posted August 23, 2013 (edited) so do i replace this $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); With This $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 .= "Content-Length: " . strlen($req) . "\r\n"; $header .= "Connection: close\r\n\r\n"; $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); and replace this if (strcmp ($res, "VERIFIED") == 0) { with this if (strcmp (trim($res), 'VERIFIED') == 0) { ?? what are these for $site_id = $_POST['custom']; $custom = $_POST['custom']; Edited August 23, 2013 by jedigunz Quote
adivirus Posted August 23, 2013 Author Posted August 23, 2013 is this working? as i said before i did that replacement since start.. but no result. the packs were not auto-credited to the buyers. Quote
sniko Posted August 23, 2013 Posted August 23, 2013 is this working? as i said before i did that replacement since start.. but no result. the packs were not auto-credited to the buyers. Have you setup the API in PayPal? The script I posted above works, as I had to adjust it to their upgraded systems. Quote
rockwood Posted August 23, 2013 Posted August 23, 2013 so what do i do do i add that in place off my ipn_donator.php i really need some help with this,. im using cronus's donator mod,.. could somebody recode this for me please <? //------------------------------------------------ //Mod created by Cronus. //You can find more of his mods for sale //and join his MCCode developers community here: //http://www.cronwerks.com/forum //------------------------------------------------ $primarypaypal="[email protected]"; $currency="GBP"; include "config.php"; global $_CONFIG; define("MONO_ON", 1); require "class/class_db_{$_CONFIG['driver']}.php"; $db=new database; $db->configure($_CONFIG['hostname'], $_CONFIG['username'], $_CONFIG['password'], $_CONFIG['database'], $_CONFIG['persistent']); $db->connect(); $c=$db->connection_id; require 'global_func.php'; $set=array(); $settq=$db->query("SELECT * FROM settings"); while($r=$db->fetch_row($settq)) { $set[$r['conf_name']]=$r['conf_value']; } // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); // assign posted variables 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']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // check the payment_status is Completed if($payment_status != "Completed") { fclose ($fp);die(""); } // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email if($receiver_email != $primarypaypal) { fclose ($fp);die(""); } // check that payment_amount/payment_currency are correct if($payment_currency != "GBP") { fclose ($fp);die(""); } // parse for pack $packr=explode('|',$item_name); if(str_replace("www.","",$packr[0]) != str_replace("www.","",$_SERVER['HTTP_HOST'])) { fclose($fp); die(""); } $meki=$db->query("SELECT * FROM dpacks WHERE id={$packr[1]} AND active=1"); if($db->num_rows($meki) == 0) { fclose($fp); die(""); } else { $r=$db->fetch_row($meki); } $total=$r['price']*$packr[2]; if($total != $payment_amount) { fclose($fp); die(""); } // grab IDs $buyer=$packr[3]; $number=$packr[2]; // all seems to be in order, credit it. $time=time(); $db->query("INSERT INTO dplogs VALUES('','$buyer',{$r['id']},'$number','$time', '$payment_amount')") or die(mysql_error()); $db->query("UPDATE users SET donated=donated+$payment_amount WHERE userid={$r['id']}"); $db->query("UPDATE users SET donated=donated+$payment_amount WHERE userid=1"); if($r['bogo'] > 0) { $add=floor($number/$r['bogo']); $number=$number+$add; } $db->query("INSERT INTO inventory VALUES('',{$r['id']},'$buyer','$number')",$c) or die(mysql_error()); // process payment event_add($buyer, "Your donation has been successfully credited to you. Thank you for your support.", $c); event_add(1, "ID $buyer has purchased $number {$r['name']}(s) for $$payment_amount.", $c); } else if (strcmp ($res, "INVALID") == 0) { } } fclose ($fp); } ?> you should escape values Quote
adivirus Posted August 23, 2013 Author Posted August 23, 2013 Have you setup the API in PayPal? The script I posted above works, as I had to adjust it to their upgraded systems. i haven't setup the API in PayPal as HTTP 1.0 worked without API setup... Quote
jedigunz Posted August 29, 2013 Posted August 29, 2013 you should escape values Im not sure what you mean rockwood ,. can you give me an example,. ??,. and my post after this would this be a working script ?? i havnt got a second paypal to test this out with Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.