ShaolinF Posted January 25, 2008 Share Posted January 25, 2008 Hey Guys, I'm using paypal for payments, and I am using IPN as the method of processing. Once paypal have processed and redirected the customer back to my website, the next step for me is to insert the data into my DB. The only problem is how do I know which record to update ? Should I use sessions ? or is there a way I can carry my userid/purchaseid variables over through the paypal process ? Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/ Share on other sites More sharing options...
resago Posted January 25, 2008 Share Posted January 25, 2008 paypal posts back info in $_POST variables. if its subsription, they send username and password along with other info. if you want to know exactly what they are sending, run a test and in the php file that receives their post, put: file_put_contents("paypal.txt",print_r($POST)); then look at the text file. then you know what you can store into your database. make sense? Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-449302 Share on other sites More sharing options...
ShaolinF Posted January 26, 2008 Author Share Posted January 26, 2008 Thanks. I wanted to know, what do I have to do with the following piece of code: // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } I've read the tutorials and asked on the their developer forums to no avail. Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-449874 Share on other sites More sharing options...
ShaolinF Posted January 26, 2008 Author Share Posted January 26, 2008 Btw, when I run the line of code you posted, I get only "1" as output. Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-449880 Share on other sites More sharing options...
tinker Posted January 26, 2008 Share Posted January 26, 2008 that what you've shown just remakes the post elements to send back so that PayPal can check nothing was changed during transit and that they actually sent that request. However what I think you need to do is send through a variable with some kind of reference to what you've stored in your database! Have a look at the variable reference list to see what your allowed to send, 'invoice' might be a good choice... Most things that you send will be returned! Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-449918 Share on other sites More sharing options...
dolcezza Posted January 26, 2008 Share Posted January 26, 2008 I just did something like this.. you are allowed a variable named "custom" So I had each rows unique identifier be the "custom" variable, then brought it back as what I needed it to be: in button: <input type="hidden" name="custom" value="<? echo $id ?>"> in IPN: id = $_POST['custom']; Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-449920 Share on other sites More sharing options...
amites Posted January 26, 2008 Share Posted January 26, 2008 A method I've had success with is using the Paypal IPN Class by Micah Carrick at http://www.micahcarrick.com/04-19-2005/php-paypal-ipn-integration-class.html verifies the paypal information, verifies it's coming from paypal and leaves with you all variables ready to be tossed into a database via class references Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-449926 Share on other sites More sharing options...
ShaolinF Posted January 26, 2008 Author Share Posted January 26, 2008 Thanks for the responses guys. dolcezza: Excellent, I wasn't too sure if making my own custom variables would work. Is it only one variable though ? Ideally I would to create 3 custom variables. I was reading the documentation for IPN on the following link: http://www.pdncommunity.com/pdn/board/message?board.id=basicpayments&thread.id=368 it says: 4. You post back a form with cmd=_notify-validate and all fields you received from PayPal. PayPal responds with a single word VERIFIED or INVALID What fields do I include and how ? The send me over 30+ variables. Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-449958 Share on other sites More sharing options...
dolcezza Posted January 26, 2008 Share Posted January 26, 2008 I'm pretty sure there is one called "custom", and one called "invoice" that you can define and the user doesn't see. You can't create your own though. There is also (If you don't mind the users seeing the data) the options fields on0, os0, on1, and os1. They will display in the cart as IPN (option_name0 / option_selection0 ...) Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-449982 Share on other sites More sharing options...
ShaolinF Posted January 26, 2008 Author Share Posted January 26, 2008 Thanks, I'm using buy now buttons with the IPN, so don't know if options fields is still an option ? How did you configure the following piece of code, as it looks like I need to send back some variables but I don't know how: // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-450027 Share on other sites More sharing options...
dolcezza Posted January 27, 2008 Share Posted January 27, 2008 I did not touch that part... it's exactly as it is in my script. You need to put them in the buy it now button.:<input type="hidden" name="custom" value="<? whatever you want the variable to be?>"> Then in the IPN script you put: $whatever = $_POST['custom']; same thing with invoice if you want to use it Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-450251 Share on other sites More sharing options...
ShaolinF Posted January 27, 2008 Author Share Posted January 27, 2008 Thanks. The problem is, is that everytime I run the script and try to get $_POST['etc'], all the variables are blank. It;s confused the hell out of me. Now, I ran the following code: // get post received and write to log file $fplog = fopen('ipnlog.txt','a'); fwrite($fplog,"GOT-IT $req\n"); fclose($fplog); // end code. // log $fplog = fopen('ipnlog.txt','a'); fwrite($fplog,"$res: $req\n"); fclose($fplog); // end log And I got the following output: GOT-IT cmd=_notify-validate&payment_date=17%3A53%3A39+Jan+26%2C+2008+PST&txn_type=web_accept&last_name=User&residence_country=GB&item_name=Fundraising+Event&payment_gross=&mc_currency=GBP&business=uoc_1201232233_biz%40gmail.com&payment_type=instant&verify_sign=ACXkfRJdfLOcvnBOS7BD.1JV6UGUApbEDRqge..dUH21s0qd6FBldyhr&payer_status=unverified&test_ipn=1&tax=0.00&payer_email=buyer_1201242695_per%40gmail.com&txn_id=1FP10185VD597525S&quantity=1&receiver_email=uoc_1201232233_biz%40gmail.com&first_name=Test&payer_id=LY3FNWL22YF8E&receiver_id=SD6KEDPH8ES6N&item_number=&payment_status=Completed&payment_fee=&mc_fee=0.32&shipping=0.00&mc_gross=3.50&custom=&charset=windows-1252¬ify_version=2.4 Now the variables are there, but why can't I grab them is the question Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-450298 Share on other sites More sharing options...
dolcezza Posted January 27, 2008 Share Posted January 27, 2008 this is how I grab them in the IPNVerify file: $item_name = $_POST['item_name']; $caregivers_id = $_POST['custom']; Quote Link to comment https://forums.phpfreaks.com/topic/87718-ipn-for-paypal/#findComment-450306 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.