|Adding PayPal IPN to site|
I am relatively new to PHP and I am trying to integrate PayPal's IPN into my website. Needless to say I am struggling. I have built a shopping cart which works exactly as I need it to and the paypal <form> dynamically updates with it so that clicking the "checkout" button takes users to paypal where they can complete the transaction. However, my product is registration for a sports league and as I have it, I will need to manually update my database based on the transaction info I will need to get from paypal for EVERY transaction. Obviously, this would be very labor intensive and it seems that PayPals IPN has exactly what I need. I have read most of the articles on PayPals website, but I just can't seem to get it to work successfully. I currently have PayPal's example code, but I can't seem to figure out how to test it. Basically what I am looking for is someone to help me understand the process and/or a good starting point for integrating and testing IPN on my site.
I am considering adding a cart myself, but thought why re-invent the wheel. So I'm looking at <snip>
This may help you if you can work through his code.
[edited by: dreamcatcher at 7:08 am (utc) on Mar 6, 2010]
[edit reason] no urls please, see T.O.S [/edit]
Thanks for the post. I read through the code and it is helpful to see it. I guess my problem is, I don't quite understand what is going on. Maybe if I just explain what "I think" needs to happen, someone can help me fill in the blanks? My understanding of the Chechout/IPN process:
1. User decides what to get on my site.
2. User clicks paypal checkout button
3. Paypal form with item info is sent to paypal
4. User clicks "Pay now" and IPN is sent to specified address(ie. www.mysite.com/ipn_handler.php)
5. ipn_handler.php reads ?and verifies? info sent by paypal
6. ipn_handler.php appends <'cmd=_notify-validate'> to URL string of all $_POST data received by Paypal and immediately sends it back to paypal(How does it get sent back to paypal?)
7. Paypal gets message(URL) sent by ipn_handler.php and verifies that it is a match of what it had previously sent.
8. If it is, then it sends another ?message? ?URL? back to ipn_handler.php saying either "VERIFIED" or "INVALID"
9. The ipn_handler.php does whatever I code it to do based on response(ie AUTOMATICALLY UPDATE DATABASE!)
10.All the while, the user in on PayPal's site ending up on a page saying "Transaction complete/payment received, etc" with the option to "Return to Merchant Site" (the URL of which I specify)
This is how I understand the process to go, but for the life of me I can't seem to perform a successful test. I feel like I must have something wrong and/or completely ignorant to some aspect or code.
Any and all help is seriously appreciated.
Welcome aboard amature_php, sounds like you have it exactly correct.
Here is what you do: In your IPN "listener" script, create a logging function. When dealing with transactions, you should do this anyway. In some location off the public domain, define a location for the log file. Then at each step in the receipt of the IPN, concatenate to a log variable:
$log_data = NULL;
$log_data .= " first request from payapal (put incoming data here";
$log .= " sending $this_data back to paypal ";
$log .= " writing to the database ";
... and so on, throughout your script. Then at the end of the script, open the log file and append to it with $log. Since you're working "blind," this is a good way to see if the listener is listening.
Run your test, check the log. If you get nothing at all, there's something going on, check your server logs for errors, etc.
Thanks a ton for the info. I ran through it like you said and, what do you know, I am successfully testing the IPN from PayPal's sandbox. I've got my work cut out for me in fully integrating to my site, but now that I've got the idea, I should be able to get through it.
If I have new questions pop up related to PayPal's IPN, should I just add on to this post or create a new one?
Thanks a bunch
Either/or . . if the new questions deviate significantly from the original, I think the mods would prefer a new thread.