Jump to content
MakeWebGames

User Defined DPs Auto Crediting


radio_active
 Share

Recommended Posts

Hello

I have been editing my IPN file to try and make it auto credit DPs where the number of DPs it credits is defined by the user. So i have added the little extra to paypal where the user can choose the quantity they wish to purchase.

Problem is, payment is smooth, everything works accept the Items do not credit. The code is:

 

<?php
// 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'];
$quantity = $_POST['quantity'];

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 != 'Donator Pack' ) { fclose($fp);die(""); }
if($pack == 'Donator Pack' && $payment_amount < 5.00") { fclose ($fp);die(""); }

// grab IDs
$buyer=$packr[3];
$for=$buyer;
// all seems to be in order, credit it.
if($pack==1)
{
$numLoops = (int)$_POST['quantity'];
  {

for(
$numLoops  = 0; 
$numLoops  < $payment_amount; 
++$numLoops ) 
   {
          $db2 = sprintf("INSERT INTO `inventory` (inv_id,inv_itemid,inv_userid,inv_qty) VALUES (%d,%d,%u,%d)",
  		'',
	107,
  		mysql_real_escape_string($for),
  		mysql_real_escape_string($numLoops));
 	   $db->query($db2);
   }
}

}

// process payment
?>

 

That is most of the IPN file. I have attempted to use a for() loop in this situation so it credits judging on the "quantity" they chose. I have thought that i could make it credit by making a variable which is the mc_gross / 5.. That way it also gets the quantity but i feel thats not the most efficient way.

Any help here would be greatly appreciated, its really getting annoying that i cannot see where the error is when you load the file etc.

Thanks

PS. Just so your aware, this is the form buton i am using.

 

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="notify_url" value="http://www.downtown-to.com/ipn_donator.php">
<input type="hidden" name="cn" value="{$ir['userid']}">
<input type="hidden" name="hosted_button_id" value="1818191">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="">
[img=https://www.paypal.com/en_AU/i/scr/pixel.gif]
</form>
Link to comment
Share on other sites

Re: User Defined DPs Auto Crediting

if thats all your form i see why its not working, you have remvoe the return information...so it has no idea if its cancelled. and if not canceled it dont know what the donator pack name is...

look back over the orignal form...you have removed alot of it...i think that might be the problem

Link to comment
Share on other sites

Re: User Defined DPs Auto Crediting

 

        <?php
   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'];
   $quantity = $_POST['quantity'];

   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 != 'DonatorPack' ) { fclose($fp);die(""); }
   if($pack == 'DonatorPack' && $payment_amount < '5.00') { fclose ($fp);die(""); }

   // grab IDs
   $buyer=$packr[3];
   $for=$buyer;
   // all seems to be in order, credit it.
   if($pack==1)
   {
       $numLoops = (int)$_POST['quantity'];
      {

   for(
   $numLoops  = 0; 
   $numLoops  < $payment_amount; 
   ++$numLoops ) 
       {
              $db2 = sprintf("INSERT INTO `inventory` (inv_id,inv_itemid,inv_userid,inv_qty) VALUES (%d,%d,%u,%d)",
              '',
           107,
              mysql_real_escape_string($for),
              mysql_real_escape_string($numLoops));
            $db->query($db2);
       }
   }

   }

   // process payment
   event_add($for, "Thankyou for you \${$payment_amount} donation, your Donator pack(s) should have been credited to you!

   Contact one of the admins if you have not received your Donation Packs.", $c);

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

   fclose ($fp);
   }
   ?>

 

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="item_name" value="DonatorPack">
<input type="hidden" name="notify_url" value="http://www.downtown-to.com/ipn_donator.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="hosted_button_id" value="1818191">
<input type="hidden" name="return" value="http://www.downtown-to.com/donatordone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://www.downtown-to.com/donatordone.php?action=cancel">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="">
[img=https://www.paypal.com/en_AU/i/scr/pixel.gif]
</form>


 

Update on the code and form..

 

Basically what happens is user can specify how many DPs they want, pay the amount and get taken t donatordone success if they complete. However they do not receive an event or any DPs into there inventory meaning the IPN must be faulting somewhere or the transaction is failing.

Link to comment
Share on other sites

Re: User Defined DPs Auto Crediting

Yes i understood that, the question i was posing was whether i need to change all the DonatorPack's to Donator Pack because that is the ingame item name. =) Ill have to test it out when im online with one of my staff members again who i send the money to and they send it back in a donation. Thats how i have to test it so it costs a but of money with the fee's so im just making certainly sure before i test.

Link to comment
Share on other sites

Re: User Defined DPs Auto Crediting

On a new note, i still cannot get this to work, not to mention its costing me to test it each time. (Paypal Fee's)

 

    <?php
   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'];
   $quantity = $_POST['quantity'];

   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 != 'DonatorPack' ) { fclose($fp);die(""); }
   if($pack == 'DonatorPack' && $payment_amount < '5.00') { fclose ($fp);die(""); }

   // grab IDs
   $buyer=$packr[3];
   $for=$buyer;
   // all seems to be in order, credit it.
   if($pack=='DonatorPack')
   {
       $numLoops = (int)$_POST['quantity'];
      {

   for(
   $numLoops  = 0; 
   $numLoops  < $payment_amount; 
   ++$numLoops ) 
       {
              $db2 = sprintf("INSERT INTO `inventory` (inv_id,inv_itemid,inv_userid,inv_qty) VALUES (%d,%d,%u,%d)",
              '',
           107,
              mysql_real_escape_string($for),
              mysql_real_escape_string($numLoops));
            $db->query($db2);
       }
   }

   }

   // process payment
   event_add($for, "Thankyou for you \${$payment_amount} donation, your Donator pack(s) should have been credited to you!

   Contact one of the admins if you have not received your Donation Packs.", $c);

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

   fclose ($fp);
   }

   ?>

 

And this button

 

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="item_name" value="DonatorPack">
<input type="hidden" name="notify_url" value="http://www.downtown-to.com/ipn_donator.php">
<input type="hidden" name="cn" value="Your Player ID">
<input type="hidden" name="hosted_button_id" value="1818191">
<input type="hidden" name="return" value="http://www.downtown-to.com/donatordone.php?action=done&type=standard">
<input type="hidden" name="cancel_return" value="http://www.downtown-to.com/donatordone.php?action=cancel">
<input type="image" src="https://www.paypal.com/en_AU/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="">
[img=https://www.paypal.com/en_AU/i/scr/pixel.gif]
</form>

 

Please, this is quite urgent.

Thanks

Link to comment
Share on other sites

Re: User Defined DPs Auto Crediting

i didnt mean to take that line out...I ment that you needed to make it where that line gives the amout to them...

example if your using say... $_GET['amout'] as the amount of them they are buying...

<input type="hidden" name="no_shipping" value="{$_GET['amount']}">

That would be that line...Honestly it takes more to do what your doing than edidting the IPN and the donator page itself. I made onewhere they could by for any person in game. I had to make a predonator.php that let the send the user id they wanted to use. so maybe an idea would be this. Hope this helps you get back in right direction.

I know who frustating this can be cause i have had to do that ot...

Link to comment
Share on other sites

Re: User Defined DPs Auto Crediting

Hmmmm its an interesting idea but its not worth it if donation packs are Items. they can just buy themselves then send them.

What im trying to do is by using a Add To Cart button, the user can choose the amount of the product they wish to purchase, after choosing for example, 3, they pay $15 and three donation packs are sent to there inventory.

Link to comment
Share on other sites

Re: User Defined DPs Auto Crediting

You should be passing a `quantity` value, and an `amount` field which is the cost per pack. eg

 

<input type="hidden" name="quantity" value=" -- whatever they choose --" />
<input type="hidden" name="amount" value="5" />

 

Then when they pay they'll have to pay $5 times the quantity, and paypal will send you back the quantity amount

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.

 Share

×
×
  • Create New...