Jump to content
MakeWebGames

ipn_donator help


adivirus

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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..

Link to comment
Share on other sites

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);
}
?>
Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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);
}
?>
Link to comment
Share on other sites

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 by jedigunz
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...