Jump to content

IPN for paypal


ShaolinF

Recommended Posts

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 ?

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ...)

 

 

Link to comment
Share on other sites

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";
}

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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&notify_version=2.4

 

Now the variables are there, but why can't I grab them is the question  :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.