Paypal Instant Payment Notification (IPN)
This is continuation of the previous post how to setup Paypal Express Checkout in your website. You do not necessarily need to setup Paypal Instant Payment Notification (IPN), but if want to automate tasks and keep track of customer actions back in their PayPal account, you should create and setup an IPN listener script.
How IPN works
Lets say, a customer has pending transaction, after few days he authorizes the payment using PayPal, how will you know? will you wait for PayPal to send you email? or have IPN script setup. PayPal can send $_POST variables to your script, containing various information about your customer transaction, your script should collect these values and use them to update database records, email user etc.
In this tutorial, we will store information received from PayPal using IPN listener script, but you can program your own script to do lot more than just store information.
Let’s say we want to create a list of history by inserting received info in the database, we need to create a table similar to below:
PHP script ipn_paypal.php below stores any incoming message from Paypal in MySql table. Just put this file somewhere in your website and point IPN Url to this script from your Paypal IPN settings.
To test this script in Paypal sandbox mode, just create an account in Paypal Developer website, once you are logged in to the site, click ‘test tools‘ on sidebar, and click “Instant Payment Notification (IPN) Simulator” and enter this script URL in “IPN handler URL” field, choose Web Accept from “Transaction type” dropdown.
That’s it! you just wait and let script store any information received in the database. Remember you can extend this script functionality to do lot more. Good luck!
Saran Chamling. (He loves the web technology, and enjoys designing, exploring and writing about it @saaraan.com).