Jump to content
MakeWebGames

IPN help


Tonka

Recommended Posts

I'm having some trouble getting my both my donator pack and will potion IPN's to work, I've edited the ipn_donator.php to give out my item DP's. if anyone could help that would be great.

ipn_donator.php

<?php
include "removed";
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(""); }
if($db->num_rows($db->query("SELECT * FROM dps_accepted WHERE dpTXN='{$txn_id}'")) > 0) { fclose ($fp);die(""); }
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
if($receiver_email != $set['paypal']) { fclose ($fp);die(""); }
// check that payment_amount/payment_currency are correct
if($payment_currency != "USD") { 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(""); }
if($packr[1] != "DP") { fclose($fp);die(""); }
$pack=$packr[2];
if( $pack != 1 and $pack != 2 and $pack != 3 and $pack != 4) { fclose($fp);die(""); }
if($pack == 1 && $payment_amount != "3.00") { fclose ($fp);die(""); }
if($pack == 2 && $payment_amount != "5.00") { fclose ($fp);die(""); }
if($pack == 3 && $payment_amount != "10.00"){ fclose ($fp);die(""); }
if($pack == 4 && $payment_amount != "20.00"){ fclose ($fp);die(""); }

// grab IDs
$buyer=$packr[3];
$for=$buyer;
// all seems to be in order, credit it.
if($pack==1)
{
$db->query("INSERT INTO inventory VALUES('',5,{$for},1)");
$d=DP1;
$t="threedollars";
}
else if($pack==2)
{
$db->query("INSERT INTO inventory VALUES('',6,{$for},1)");
$d=DP2;
$t="fivedollars";
}
else if($pack==3)
{
$db->query("INSERT INTO inventory VALUES('',7,{$for},1)");
$d=DP3;
$t="tendollars";
}
else if($pack==4)
{
$db->query("INSERT INTO inventory VALUES('',8,{$for},1)");
$d=DP4;
$t="twentydollars";
}

// process payment
event_add($for, "Your \${$payment_amount} Pack {$pack} Donator Pack has been successfully credited to you.", $c);

$db->query("INSERT INTO dps_accepted VALUES('', {$buyer}, {$for}, '$t', unix_timestamp(), '$txn_id')");
}
else if (strcmp ($res, "INVALID") == 0) {
}}
fclose ($fp);
}
?>

 

ipn_wp.php

<?php
include "removed";
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(""); }
if($db->num_rows($db->query("SELECT * FROM dps_accepted WHERE dpTXN='{$txn_id}'", $c)) > 0) { fclose ($fp);die(""); }
if($db->num_rows($db->query("SELECT * FROM willps_accepted WHERE dpTXN='{$txn_id}'", $c)) > 0) { fclose ($fp);die(""); }
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
if($receiver_email != $set['paypal']) { fclose ($fp);die(""); }
// check that payment_amount/payment_currency are correct
if($payment_currency != "USD") { 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(""); }
if($packr[1] != "WP") { fclose($fp);die(""); }
$pack=$packr[2];
if( $pack != 1 and $pack != 5) { fclose($fp);die(""); }
if(($pack == 1) && $payment_amount != "1.00") { fclose ($fp);die(""); }
if($pack == 5 && $payment_amount != "4.50") { fclose ($fp);die(""); }
// grab IDs
$buyer=$packr[3];
$for=$buyer;
// all seems to be in order, credit it.
if($pack==1)
{
item_add($for, $set['willp_item'], 1);
}
else if($pack==5)
{
item_add($for, $set['willp_item'], 5);
}
// process payment
event_add($for, "Your \${$payment_amount} worth of Will Potions ($pack) has been successfully credited.", $c);
$db->query("INSERT INTO willps_accepted VALUES('', {$buyer}, {$for}, '$pack', unix_timestamp(), '$txn_id')", $c);
}
else if (strcmp ($res, "INVALID") == 0) {
fwrite($f,"Invalid?");
}}
fclose ($fp);
}
?>
Link to comment
Share on other sites

Re: IPN help

And have you tested in the sandbox?

I had to do extensive testing in the sandox in order to get mine to work. (Which by the way only uses one IPN script to credit an unlimited number of item types. Only limited by the number of donor item types in the database)

 

I used events to show me which parts of the file held the correct values in variables. For instance you can var_dump all of the post vars sent by pay pal so you can see just what is being sent. And it tells you if script execution made it to the point where the event add was placed.

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