home |  
Sell Downloads - Ejunkie
open db network by 19.5 degrees
LYRICS | FREE E-BOOKS | SELL DOWNLOADS WITH PAYPAL
 in   
contribute for fun & profit
brink

PayPal IPN Handler
-PayPal IPN Agen..
-PayPal IPN hand..
-Image to ASCII ..
-Image to ASCII ..
-PayPal IPN hand..
All Resources > Server Scripts > PHP
spread the word around  send this page to a friend   read/write comments/corrections/additions comments  rate this 

PayPal IPN handler

by 19.5 Degrees
 
 
views: 59531 | rating: 6/10 | downloads: 13070 download
 


PayPal IPN handler is a set of 2 PHP scripts that can handle the IPN sent by PayPal for every transaction. Instant Payment Notification (IPN) is PayPal's interface for handling real-time purchase confirmation and server-to-server communications. IPN delivers immediate notification and confirmation of PayPal payments you receive and provides status and additional data on pending, cancelled, or failed transactions.

Instant Payment Notification (IPN) allows you to integrate your PayPal payments with your website's back-end operations, so you get immediate notification and authentication of the PayPal payments you receive. IPN can be used for many purposes but the primary reason people use it, is for providing instant download of their downloadable products or registration codes etc. to their customers.

If you don't want to bother with coding yourself and are looking for a PayPal IPN handler service for doing automated downloads/online fulfillment, you should consider e-junkie.com.

Process

IPN process is quite simple. PayPal send all the transaction data as POST to any script you specify on your web server. This script has to post all the data back to PayPal as it is. If the transaction is valid, PayPal will return a response "VERIFIED". Then you can perform few more checks to see if it is not a duplicate transaction, the payment amount is same as the price of your product, the currency is same as you expect and last but not the least, if the payment made to your account :)

Code

I have provided the PHP scripts and SQL files for all this. You do NOT require cURL or SSL or any other fancy thing. You should just have plain old PHP and mySQL running on your webserver. I have written some code, picked up some code from some places, modified and added to it, tested a LOT. Finally, this works perfect. Please let me know if you need any installation help or if you find any bug. Please note, this code will do all the verification for you, you can modify ipn_res.php to add code for anything that you want to happen after the payment is successfully verified.

Instructions

1. Open ipn_res.php and change the configuration settings.
2. Copy ipn_res.php and ipn_cls.php in your web folder.
3. Create paypal_table and item_table using the SQL files provided.
4. Enter your product price and item_number in item_table.
5. Login to your PayPal account and create the "Buy Now" button for your product.
6.

For IPN to work, either put the complete link to ipn_res.php as your IPN URL in your PayPal account settings OR in your "Buy Now" button code, specify

<input type="hidden" name="notify_url" value="http://your.domain/path.to.ipn_res.php">

   
NOTE: Your PayPal account must be verified to accept credit cards.
 
How to test?
   

In your "Buy Now" button code, specify

<input type="hidden" name="return" value="http://your.domain/path.to.ipn_res.php">
<input type="hidden" name="rm" value="2">

This will make PayPal post all the transaction data (that it sends as IPN) to ipn_res.php in the browser window so you can see any error message etc., if things are not working for you.



download


« PREVIOUS
  INDEX
NEXT »

spread the word around
read comments

IPN notifications
posted by: ian
on: Aug 24, 08 11:24 am

IPN technology is typically hard to get working and is especially painful to test. If you don't feel like reinventing the wheel (and you are obviously considering doing that if you are checking this page out) just have a quick look at a prebuilt solution such as http://www.scrobbld.com.

post reply | read replies (0)



How I got this script to work for me...
posted by: Bill Platt
on: Aug 1, 08 4:17 am

First off, there are two changes that need to be made to run this script in paypal sandbox mode:

1. The original code of ipn_cls.php has the following:

$fp = @fsockopen( "www.paypal.com", 80, &$errno, &$errstr, 120 );

In order to test this software in the paypal sandbox, one has to change the above line to read:

$fp = @fsockopen( "www.sandbox.paypal.com", 80, &$errno, &$errstr, 120 );

2. Change $paypal_email to your sandbox business email address.


In order to actually pass values to paypal sql table, you must do the following 3 steps:

1. Add a function to your ipn_res.php file or include it through a separate script:


function process_mysql($sql)
{

$dbhost = DB_HOST;
$dbuser = DB_USER;
$dbpasswd = DB_PASSWORD;
$dbname = DB_NAME;


$link = mysql_connect($dbhost, $dbuser, $dbpasswd) or die ("Could not connect to mysql because ".mysql_error());

mysql_select_db($dbname) or die ("Could not select database because ".mysql_error());

$result1 = mysql_query($sql) or die(mysql_error());


mysql_close($link);
return $result1;
}


2. Near the top of the ipn_res.php script, change the following:

foreach ($paypal_ipn->paypal_post_vars as $key=>$value) {
if (getType($key)=="string") {
eval("\$key=\$value;");
}
}


to:

$insert_array = array();
foreach ($paypal_ipn->paypal_post_vars as $key=>$value) {
if (getType($key)=="string") {
$insert_array [$key] = $value;
eval("\$key=\$value;");
}
}


3. Change the INSERT structure and mysql processing structure. Change it from:

$qry="INSERT INTO paypal_table VALUES (0 , '$payer_id', '$payment_date', '$txn_id', '$first_name', '$last_name', '$payer_email', '$payer_status', '$payment_type', '$memo', '$item_name', '$item_number', $quantity, $mc_gross, '$mc_currency', '$address_name', '".nl2br($address_street)."', '$address_city', '$address_state', '$address_zip', '$address_country', '$address_status', '$payer_business_name', '$payment_status', '$pending_reason', '$reason_code', '$txn_type')";


if (mysql_query($qry)) {


To:


$qry="INSERT INTO paypal_table VALUES (0 , '$insert_array[payer_id]', '$insert_array[payment_date]', '$insert_array[txn_id]', '$insert_array[first_name]', '$insert_array[last_name]', '$insert_array[payer_email]', '$insert_array[payer_status]', '$insert_array[payment_type]', '$insert_array[memo]', '$insert_array[item_name]', '$insert_array[item_number]', '$insert_array[quantity]', '$insert_array[mc_gross]', '$insert_array[mc_currency]', '$insert_array[address_name]', '".nl2br($insert_array[address_street])."', '$insert_array[address_city]', '$insert_array[address_state]', '$insert_array[address_zip]', '$insert_array[address_country]', '$insert_array[address_status]', '$insert_array[payer_business_name]', '$insert_array[payment_status]', '$insert_array[pending_reason]', '$insert_array[reason_code]', '$insert_array[txn_type]')";

$mysql_result = process_mysql ($qry);


if ($mysql_result) {



You should find that this enables this script to operate as advertised.

I hope this helps.

Bill Platt
Stillwater, Oklahoma

post reply | read replies (0)



Having problem with fsockopen ( "www.paypal.com")
posted by: gil
on: May 29, 08 11:16 am

I'm testing using sandbox, do I need to change this to 'www.sandbox.paypal.com' or with 'https://' ? any help is appreciated.

this is my error by the way

Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of fsockopen(). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in /home/content/k/e/n/kendra1/html/dev/ipn_class.php on line 18

post reply | read replies (4)



Strange problem with ereg not finding verified
posted by: mark
on: Jun 6, 08 2:02 pm

if (ereg("VERIFIED",$this->paypal_response))
always returns false.

However when the email is sent I get it telling me that
Bad order (PayPal says it's invalid) but inside in the email the content of paypal_response is listed as:

payer_status: verified

I'm using the sandbox to test btw.

Anyone any ideas, why I'm not getting the verification as true ?
Its driving me nuts :)

TIA!

post reply | read replies (0)



re: having problems displaying ipn on webpage
posted by: Rorie
on: Jun 6, 08 2:12 am

hello
i'm all new to this. anyway i have done all the instructions that this guide has told me. but the script still is not displaying on the page

http://www.rorboy1983.com/new/index.shtml

i don't know if someone has to make a donation or what?

somebody please help!

post reply | read replies (0)



read more commentsread more comments   |   read more commentspost comment 



home | contact | contribute | terms of use | privacy policy |