Sunday, May 29, 2016

Solved Integrate Paypal IPN in PHP

in this post we will see how to use PayPal IPN in PHP. PayPal IPN (instant payment notification) allows you to integrate PayPal payments with web application backend. As the name suggests it sends instant notification of the payment processed so that you can use the data for further use. An example would be when you want to allow users to download something immediately after successful payment.

When a user sends money to your PayPal, you will get instant response/notification from PayPal and then you can save it in your website’s backend (database) for further use. Another use would be to set up a recurring payment system so that IPN script updates the transaction table automatically for you.

Let’s break this into simple steps to make it easier:
  • User click on buy button and makes payment.
  • PayPal processes that payment and sends back you response with transaction detail to a PHP page in your website (IPN script).
  • User will see payment successful page.
Live DEMO


Now, in order to make IPN payments work you need to enable IPN in the seller’s PayPal account settings. Login to your PayPal account and go to profile option and enable it. Also you need to enter IPN script URL in settings:
in our example this url would be http://codeglamour.com/ipntest/ipn.php replace  your domain url here 








 In our demo we have used sandbox account you just need to replace the email id’s in index.php file .
and change the username and password in dbconnect.php file . First create a transaction table in your database to store the transaction details sent by PayPal:

 you will get sql file in zip file restore it on your server


Now we have two main files index.php which will show a “Pay Now” button to make purchase and inform paypal about the action, then another file we have is ipn.php which would receive response from paypal and store the transaction detail and status in database table.

You can download the source code and host it on your server to see it working. Its ready to use code just add your Paypal merchant email ID and set product prize etc, then you are all good to go





No comments:

Post a Comment