[RELEASE]Automatic Coin Delivery from PayPal IPN payment messages
Here is a script to automatically send coins to your players based on payments made through PayPal. This does require a good amount of setup and I would recommend testing it before going live.
Note: This script is using the older mysql / mssql PHP functions. I highly recommend using PDO, and that you use this code only as a reference for getting your PayPal IPN setup.
Important!
This script assumes that you sent the users account name through PayPal IPN's 'custom' field when they made the payment. You have to edit your PayPal provided button code to add an input field with the name custom and value account name. This can be hidden if you have the information already by having the user logged into your website, or you can have the user enter their account name by having the field not hidden.
Requirements
- PayPal account that can make payment buttons
- Web server with mssql and mysql php extensions enabled
- MySQL database, for logging payments
- Patience
Setup Setup on your sever side
- Open paypalipnconfig.php and fill out for your server information and what packages you will offer
- Open paypalDB.sql and copy it into your MySQL Database and run it, this creates a table called 'paypal_logs' which will store paypal payments and coins sent out.
- Done on your server's end...
PayPal Setup
- Create a button
- make sure to set a fixed donation amount
- click "Step 3: Customize advanced features
- click add advanced variables and add the following line to the text area with your path to the script
Error Logging
If there is an error with a payment, either an invalid IPN, or email, or user name, anything... it will be output to a file _paypal_error_log.txt in the same directory that holds the script. All error messages are timestamped so you can review errors and see what's going on with them.
Make sure to test the system before making it live on your server!
<?php
// PaypalIPNConfig.php
// --- MYSQL CONFIG ---
define('MYSQL_HOST', '127.0.0.1'); // Mysql host address
define('MYSQL_USER', 'user'); // User name
define('MYSQL_PASS', 'password'); // User password
define('MYSQL_DB', 'paypal'); // Database name
// --- MSSQL CONFIG ---
define('MSSQL_HOST', '127.0.0.1'); // Mssql host address
define('MSSQL_USER', 'user'); // User name
define('MSSQL_PASS', 'password'); // User password
// --- PAYPAL CONFIG ---
define('PAYPAL_EMAIL', ''); // Your paypal email on which you recieve payments
define('CURRENCY', 'USD'); // The type of currency you set up in paypel
$paypal_packages = array(
// $ Price , Coin amount -- delimit arrays with a comma to add more
array(5.99, 1000),
array(9.99, 2000),
array(20.00, 5000)
);
?>
<?php
// If configuration not loaded, quit
if(!defined('MSSQL_HOST'))
die;
// If server does not have the mssql extension enabled, quit
if(!extension_loaded('mssql'))
die;
/////////////////////////////////////////////
// CLASS: mssql
//
// DESCRIPTION: a class used to connect to
// and communicate with a mssql database
// with the mssql extension
/////////////////////////////////////////////
class mssql
{
private $conn;
private $db;
private $is_connected = false;
// connect() : connect to mssql server
public function connect($host='', $user='', $pass='')
{
if(!$host)
{
$host = MSSQL_HOST;
$user = MSSQL_USER;
$pass = MSSQL_PASS;
}
$this->conn = mssql_connect($host, $user, $pass);
//if(!$conn)
// return error('ERROR : Cannot connect to MSSQL Server at '.$host);
$this->db = mssql_select_db('account', $this->conn);
//if(!$this->db)
// return error('ERROR : Cannot connect to MSSQL Database at '.$host);
$this->is_connected = true;
return true;
}
// query() : send a query to mssql server
public function query($query)
{
if(!$this->isConnected())
connect();
$r = mssql_query($query);
//if(!$r)
// error($query.' : '.mssql_get_last_message());
return $r;
}
// use() : change the database context
public function useDB($dbname)
{
if(!$this->isConnected())
connect();
$this->db = mssql_select_db($dbname, $this->conn);
//if(!$this->db)
// error('ERROR : Cannot connect to MSSQL Database at '.$host);
}
// error() : prints an error message and quits
public function error($err)
{
return "<p style='color:#ce0000'><em>$err</em></p>";
}
// isConnected() : returns true is connected to mssql, false if not
public function isConnected()
{
return $this->is_connected;
}
public function get_last_message(){
return mssql_get_last_message();
}
public function numrows($r){
return mssql_num_rows($r);
}
public function numfields($r){
return mssql_num_fields($r);
}
public function fetch_row($r){
return mssql_fetch_row($r);
}
public function fetch_array($r){
return mssql_fetch_array($r);
}
public function rows_affected($r){
return mssql_rows_affected($r);
}
};
?>
<?php
// debuglogger.php
// used to log time stamped strings to a file
function dbg_log($msg, $logfile='_paypal_error_log.txt')
{
$buff = '';
if(!file_exists($logfile))
$buff = '<?php die; ?>'."\n";
$buff .= sprintf("%s %s\n\n", date("Y-m-h H:i"), $msg);
$f = fopen($logfile, 'a');
fwrite($f, $buff);
fclose($f);
}
?>
Edit:Added new file below.
paypalipn.php -> this one stores your paypal logs in mssql. Just make a table with the same layout as the mysql example above in your mssql "cash" db.
Excellent tutorial, shouldn't be charging so much for installing this for others (I understand it's a service, but it doesn't take too long to configure IPN).
Excellent tutorial, shouldn't be charging so much for installing this for others (I understand it's a service, but it doesn't take too long to configure IPN).
Thank you, and about charging that much... it's for time. Which is the reason I explained it well, if they can follow the majority of the tutorial and need help for like 30 mins they only owe me for 30 mins. But tech savvy people shouldn't really need any help if they google how to test IPN with paypal's sandbox.
Also, going to add a second paypalipn.php that stores the data in mssql and not in mysql for people that aren't running mysql for their website. Just make a table with the same fields as explained in the mysql one and you'll be set.
hello free i would like for you to set up the auto coin delivery system on my server.i tryed my best to do it my self and cant do it.. you can find me on skype as bocc1337 please i really need this to work. thx i will be watching for your reply.
Yes, you configure the dollar amount to coin amount in paypalipnconfig.php and when an IPN message is received it looks at the received dollar amount and gives coins based on the array you set up.
Also, you can use the paypal sandbox to test sending payments without actually sending real money. So you don't have to send an actual penny back and forth.
Hey add me on skype: Mystra-Shaiya
I am trying to set this up for Shaiya server i just need help with the IPN setup because i am sure that i did everyting right ;o
Thanks!
Hey add me on skype: Mystra-Shaiya
I am trying to set this up for Shaiya server i just need help with the IPN setup because i am sure that i did everyting right ;o
Thanks!
Question: Automatic server messages?? 07/11/2012 - Shaiya Private Server - 3 Replies What i am looking for is how to add or change server messages.. Ex: guild ranking battle messages and messages sent when relics are taken....
release: KSF radio messages 12/31/2010 - Soldier Front Hacks, Bots, Cheats & Exploits - 17 Replies good day troopers..
want to feel like playing in KSF,,
hear KSF radio messages and announcement in-game..
download this..
sound_001.rar
paste this on..