PHP PAYPAL IPN INTEGRATION CLASS
For a PayPal customer, having an IPN enables you to stay on top of all the transactions conducted in your account. You get to know when money gets in and when it goes out and this helps you better manage your finances.
How Does it Work?
It starts with someone sending money to you. The site then sends a message to you to a location you prefer and once you get hold of the text, you decide on the way forward.
Enabling IPN
Seeing how important this application is in making your transactions a breeze, it feels like a good idea to get started, doesn’t it? Start by signing into your account. If you do not have one yet, creating one is easy as there are very few details required. It will be over within some moments and you can start enjoying convenience.
Having logged in, head to your ‘profile’. You will see an option labeled ‘Instant Payment Notification Preferences’ which you should click. The first thing necessary for this process to be successful is choosing where the notifications will get sent. For now, we can call it example.com/paypal_ipn.php. The destination you decide on is vital; so ensure that you keep note of it by taking a picture or writing it down.
Creating the Script
It is essential that we come up with a 'script' to handle the back and forth between you and PayPal. The version I am writing is made up of two PHP files. Start by copying paypal.class.php to your web server.
<?php include("paypal.class.php"); $p = new paypal_class; $p->ipn_log_file = 'paypal.log'; // testing only - $p->paypal_url = 'domain.com/cgi-bin/webscr'; if( $p->validate_ipn() ) { } ?>
Upload paypal_ipn.php to your server after which you can head to the testing stage to figure out whether it works. My advice to you is that you should take a lot of time when examining the effectiveness of your set-up. The best way to go about it is to enter some fake data so that if it goes wrong you can start again. In this way, you get to know whether you did the right thing. The alternative is to use a site which does this for you. Though the latter option is simpler, the former is more straightforward and effective. If you have set it up the right way, you should get notified soon afterwards.
One way to tell that you are successful is by checking whether the log file receives data as this will help you in troubleshooting problems that arise in future.
Failure to get a text probably means that the files were not the right ones or the location has an issue. Once you complete the test, comment in paypal_ipn.php as //$p->paypal_url = ‘domain.com/cgi-bin/webscr’;
Successful completion of this stage ensures your script contacts the server as opposed to the site used.
Processing
After validation, data gets stored in $p->ipn_data.
Now you have reached the end of the procedure and you can now rest assured that you will get notifications whenever any money comes in or out.