Jump to content

Database Query Function, combined with IPN script


MasterACE14

Recommended Posts

I am using a IPN script I found after awhile of google searching, and it works perfectly, except I have one problem, I have a function that runs on success of a paypal payment, and it is suppose to run once the IPN script has confirmed

the payment has been made. The function that runs on success of a paypal payment, updates information in a user table in my database. I had it working earlier, when I was testing this on paypal sandbox, but now for some reason it doesn't do the function, or atleast doesn't do the queries in the function.

 

would anyone be able to identify a problem in my function? Keeping in mind that the IPN script 'Does' work. just the function doesn't.

 

here is the IPN script with the function near the top called donate1() :

 

<?php
if (file_exists('install.php')) { die("Please delete <b>install.php</b> from your Shadow Lords directory before continuing."); }
include('lib.php');
include('cookies.php');
$link = opendb();
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");
$controlrow = mysql_fetch_array($controlquery);
// Login (or verify) if not logged in.
$userrow = checkcookies();
if ($userrow == false) { 
    if (isset($_GET["do"])) {
        if ($_GET["do"] == "verify") { header("Location: users.php?do=verify"); die(); }
    }
    header("Location: login.php?do=login"); die(); 
}
// Close game.
if ($controlrow["gameopen"] == 0) { display("The game is currently closed for maintanence. Please check back later.","Game Closed"); die(); }
// Force verify if the user isn't verified yet.
if ($controlrow["verifyemail"] == 1 && $userrow["verify"] != 1) { header("Location: users.php?do=verify"); die(); }
// Block user if he/she has been banned.
if ($userrow["authlevel"] == 2) { die("Your account has been blocked. Please try back later."); }
?>
<?php
//SS Account Updating 
function donate1() {

    global $userrow;

if($userrow["charname"] == '$userrow["charname"] ~SS~'){
$redd = '';
}
elseif($userrow["charname"] !== '$userrow["charname"] ~SS~'){
$redd = ' ~SS~';
}    
    $charn = '$userrow["charname"]';
    $bank = '$userrow["bank"]';
    $maxmp = '$userrow["maxmp"]';
    $maxtp = '$userrow["maxtp"]';
    $maxhp = '$userrow["maxhp"]';
$strengthh = '$userrow["strength"]';
$dexterityy = '$userrow["dexterity"]';
$experiencee = '$userrow["experience"]';

    if ($userrow["verify"] == 1) {
        $charn = $userrow["charname"] . $redd;
        $bank = ceil($userrow["bank"]+2500);
        $maxmp = ceil($userrow["maxmp"]+25);
        $maxtp = ceil($userrow["maxtp"]+25);
        $maxhp = ceil($userrow["maxhp"]+25);
	$strengthh = ceil($userrow["strength"]+25);
	$dexterityy = ceil($userrow["dexterity"]+25);
	$experiencee = ceil($userrow["experience"]+100);
        //echo("Transaction Successful!"); 
	}

    elseif ($userrow["verify"] !== 1) { die("This Page is restricted to people that have verified their accounts"); }

    doquery("UPDATE {{table}} SET charname='$charn' WHERE id='".$userrow["id"]."' ", "users");
    doquery("UPDATE {{table}} SET bank='$bank' WHERE id='".$userrow["id"]."' ", "users");
    doquery("UPDATE {{table}} SET maxmp='$maxmp' WHERE id='".$userrow["id"]."' ", "users");
    doquery("UPDATE {{table}} SET maxtp='$maxtp' WHERE id='".$userrow["id"]."' ", "users");
    doquery("UPDATE {{table}} SET maxhp='$maxhp' WHERE id='".$userrow["id"]."' ", "users");
doquery("UPDATE {{table}} SET strength='$strengthh' WHERE id='".$userrow["id"]."' ", "users");
doquery("UPDATE {{table}} SET dexterity='$dexterityy' WHERE id='".$userrow["id"]."' ", "users");
doquery("UPDATE {{table}} SET experience='$experiencee' WHERE id='".$userrow["id"]."' ", "users");
doquery("UPDATE {{table}} SET authlevel='3' WHERE id='".$userrow["id"]."' ", "users");
};
?>
<?php

/*  PHP Paypal IPN Integration Class Demonstration File
*  4.16.2005 - Micah Carrick, [email protected]
*
*  This file demonstrates the usage of paypal.class.php, a class designed  
*  to aid in the interfacing between your website, paypal, and the instant
*  payment notification (IPN) interface.  This single file serves as 4 
*  virtual pages depending on the "action" varialble passed in the URL. It's
*  the processing page which processes form data being submitted to paypal, it
*  is the page paypal returns a user to upon success, it's the page paypal
*  returns a user to upon canceling an order, and finally, it's the page that
*  handles the IPN request from Paypal.
*
*  I tried to comment this file, aswell as the acutall class file, as well as
*  I possibly could.  Please email me with questions, comments, and suggestions.
*  See the header of paypal.class.php for additional resources and information.
*/

// Setup class
require_once('paypal.class.php');  // include the class file
$p = new paypal_class;             // initiate an instance of the class

$p->paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';   // testing paypal url

//$p->paypal_url = 'https://www.paypal.com/cgi-bin/webscr';     // paypal url  <--- UNCOMMENT THIS ONE

//$p->paypal_url = 'https://www.paypal.com/au/au/cgi-bin/webscr';     // aussie paypal url       
// setup a variable for this script (ie: 'http://www.micahcarrick.com/paypal.php')
//$this_script = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$this_script = 'http://www.crikeygames.com.au/shadowlords/purchase.php';
// if there is not action variable, set the default action of 'process'
if (empty($_GET['action'])) $_GET['action'] = 'process';  

switch ($_GET['action']) {
    
   case 'process':      // Process and order...

      // There should be no output at this point.  To process the POST data,
      // the submit_paypal_post() function will output all the HTML tags which
      // contains a FORM which is submited instantaneously using the BODY onload
      // attribute.  In other words, don't echo or printf anything when you're
      // going to be calling the submit_paypal_post() function.

      // This is where you would have your form validation  and all that jazz.
      // You would take your POST vars and load them into the class like below,
      // only using the POST values instead of constant string expressions.

      // For example, after ensureing all the POST variables from your custom
      // order form are valid, you might have:
      //
      // $p->add_field('first_name', $_POST['first_name']);
      // $p->add_field('last_name', $_POST['last_name']);
      
      $p->add_field('business', '[email protected]');
      $p->add_field('return', $this_script.'?action=success');
      $p->add_field('cancel_return', $this_script.'?action=cancel');
      $p->add_field('notify_url', $this_script.'?action=ipn');
      $p->add_field('item_name', '$20 Shadow Lords Supporter Status');
      $p->add_field('amount', '20.00');
  $p->add_field('currency_code', 'AUD'); 

      $p->submit_paypal_post(); // submit the fields to paypal
      //$p->dump_fields();      // for debugging, output a table of all the fields
      break;
      
   case 'success':      // Order was successful...
   
      // This is where you would probably want to thank the user for their order
      // or what have you.  The order information at this point is in POST 
      // variables.  However, you don't want to "process" the order until you
      // get validation from the IPN.  That's where you would have the code to
      // email an admin, update the database with payment status, activate a
      // membership, etc.  
	$returntogame = "/shadowlords/";
      echo "<html><head><title>Success</title></head><body><h3>Thank you for purchasing Supporter Status for Shadow Lords.</h3><br /><br /><a href=".$returntogame.">Return to Shadow Lords</a><br />";
      foreach ($_POST as $key => $value) //{ echo "$key: $value<br>"; }
      echo "</body></html>";
      
      // You could also simply re-direct them to another page, or your own 
      // order status page which presents the user with the status of their
      // order based on a database (which can be modified with the IPN code 
      // below).
      
      break;
      
   case 'cancel':       // Order was canceled...

      // The order was canceled before being completed.

      echo "<html><head><title>Canceled</title></head><body><h3>The payment was canceled.</h3><br /><br /><a href=".$returntogame.">Return to Shadow Lords</a><br />";
      echo "</body></html>";
      
      break;
      
   case 'ipn':          // Paypal is calling page for IPN validation...
   
      // It's important to remember that paypal calling this script.  There
      // is no output here.  This is where you validate the IPN data and if it's
      // valid, update your database to signify that the user has payed.  If
      // you try and use an echo or printf function here it's not going to do you
      // a bit of good.  This is on the "backend".  That is why, by default, the
      // class logs all IPN data to a text file.
      
      if ($p->validate_ipn()) {
          
         // Payment has been recieved and IPN is verified.  This is where you
         // update your database to activate or process the order, or setup
         // the database with the user's order details, email an administrator,
         // etc.  You can access a slew of information via the ipn_data() array.
  
         // Check the paypal documentation for specifics on what information
         // is available in the IPN POST variables.  Basically, all the POST vars
         // which paypal sends, which we send back for validation, are now stored
         // in the ipn_data() array.
       	 
	 donate1();

         // For this example, we'll just email ourselves ALL the data.
    /*    $subject = 'Shadow Lords - Instant Payment Notification - Recieved Payment';
         $to = '[email protected]';    //  your email
         $body =  "An instant payment notification was successfully recieved\n";
         $body .= "from ".$p->ipn_data['payer_email']." on ".date('m/d/Y');
         $body .= " at ".date('g:i A')."\n\nDetails:\n";
         
         foreach ($p->ipn_data as $key => $value) { $body .= "\n$key: $value"; }
         mail($to, $subject, $body); */
      }
      break;
}     

?>

 

Regards ACE

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.