View Full Version : Automated Paypal reward

09-05-2007, 12:04 AM
I run an online game, and what i have now, is a donation system, where i say donate $10 and get an in-game reward.. but i have to do that manually right now, i have to check paypal, verify their email, and give out the reward... I KNOW there is a way to do this automatically.. but i dont know how.. how do i get paypal to redirect to one of my pages, and how do i carry variables through paypal to that page(ie: how much they paid)... Help would be greatly appreciated

09-05-2007, 01:08 AM
Sounds like you want to use Paypal's IPN system (instant payment notification). It's a simple process in theory-- when a user uses your donate button and pays you a donation, Paypal will send a "post" http request to a designated PHP script (that you specify in your Paypal account profile) and that request contains detailed information about the donation. Inside that PHP script you can insert all the processing you need to in order to give the user the ingame reward.

Paypal has tons of documentation on IPN... look in their help center for the details.

09-05-2007, 01:26 AM
alright, i know how to set it up now, thanks.. but.. how do i know what the variables are called? like.. is it $_POST['amount'] for the amount? or is it something else?

09-05-2007, 01:36 AM
They are listed in the help center. And you can test them out in your sandbox.

09-05-2007, 05:01 AM
I just happen to be working on this currently so I had this link handy:


09-05-2007, 07:24 PM
ok, i got what i needed... sort of.. when it redirects to the link.. whats to stop someone from changing the stuff around.. like.. i couldnt get it to work using the POST stuff in that page, so i had to resort to the GET values given in the link..

The link:

http://playsovereignty.com/donated.php?tx=2UC44761HK104574L&st=Completed&amt=100.00&cc=USD&cm=&sig=ku2mN%2bqozkf4nYtvu3%2fvKvM3KMS%2fRCuu6cLbgPnxfVpoNl6DRCl1oKut%2bGqMaLbsAQCg8%2f5l9ZkHlAcdDNzrG% 2b5bF2swzVbSg9iJodT%2bjDmTeNCDoxuoUlohlyO02yH3qEeMZhvq018GYrjqy6QnnDVsvG67zf1el%2f7j6y%2fLgiI%3d

and the code to go along with(just for testing, not complete):

if($_GET['st'] == "Completed"){

$amount = $_GET['amt'];

$getitem = floor($amount/10);

echo "You would get $getitem items!";

This is to make it so that for every 10 dollars donated, you get an item... but.. whats to stop someone from simply refreshing, or changing then 'amt' value to '10000000'?

09-05-2007, 08:41 PM
Well that query string in the return URL is the PDT (Payment Data Transfer), not the IPN (Instant Payment Notification). Yes someone could monkey with the return URL, that's why it's more secure to use IPN.

09-05-2007, 09:00 PM
but... how do you use it.. i tried the snippet:


echo "This works";


and when it redirected to the page, nothing showed

09-05-2007, 09:28 PM
IPN is a separate POST request. It is outside the loop of the payment process. The POST request gets sent to a different script that you have to write to accept the IPN and process it. It has nothing to do with the return URL coming from Paypal.

Read this page completely:


Then click on the "script generator" to get examples of how to handle the IPN request. (The scripts are terribly written but they do work.)

Also this link may help:


And I just found this Paypal Summary which is pretty awesome: