22

I am trying to pass custom variables to paypal IPN. I can manage to pass one variable. But i don't know how to pass multiple variables.

My Process is something like this

  1. User fill up the form
  2. They click button and it goes to paypal
  3. They paid, IPN send me back the information and that ipn.php added variables that passed to the database.

My custom variables are

  1. total lines (whenever they write, i count the lines)
  2. message (their message that they wrote)
  3. advertisement id

But for now, I can only pass one variable like this

form.php

<input name="custom" type="hidden" id="custom" value="{$line_count}">

$_SESSION['line_count'] = $_POST['lines_txt'];

ipn.php

$sql="INSERT INTO `form`(`totalline`) VALUES ('" .$_POST['custom']. "');";
Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116
spotlightsnap
  • 1,095
  • 7
  • 21
  • 26

6 Answers6

22

I am not sure, if it is even possible with Paypal to send and receive multiple variables. If it is not possible due to Paypal's restrictions, you could use one of the following approaches:

  • Send the data serialized, and deserialize on return.
  • Write the data to the database in form.php (with status notpaid) and send the id. In ipn.php catch the id and set status = paid / error / whatever happened in the database.
Residuum
  • 11,878
  • 7
  • 40
  • 70
  • 1
    thanks for your reply. Currently I am checking and custom variable can only hold 200 characters, my variables are more than that value, so i cannot pass. Only one thing i can do is, like you says, first, when they submit the form, i store all the things i need to store in database, then get the IPN result, if that's success, update the status, if that's fail, remove the entry. But another one problem is, if they close the browser and never make payment, how can i remove that entry ? Does I need to run cron and delete ? :( it's alot of process and works – spotlightsnap Dec 03 '09 at 09:10
  • @spotligthsnap: If the user closes the browser while on the Paypal website, then the database entry persists, correct. You could delete them via a cronjob, but you could also leave them in the database to analyse later (payments / redirects to paypal). In the same spirit, you could write error after returning from Paypal instead of just deleting the entry. – Residuum Dec 03 '09 at 09:49
  • Thanks. This works great. Also, storing some values to db and then sending to paypal is a better idea. – codingbbq Sep 23 '10 at 09:54
  • thanks for your suggestion! i got here by google. serialize doesnt work, the string will be longer than original, but storing info in db and deleting on paypal error ofc did the trick! – Kristian Rafteseth Jan 31 '12 at 23:57
12

You can pass other information via the notify_url field, for example doing http://www.yoursite.com/notify?myvariable=value

sw.
  • 3,240
  • 2
  • 33
  • 43
2

If it is just to pas a variable that is not pertinent to paypal but more pertinent to you when it comes back, you can use the value ['custom'] to submit to paypal, paypal will simply pass it back to yuo once things are done on their side.

Martin
  • 21
  • 1
1

A vague memory tells me there are two options for sending data to PayPal. The command x_click and i thought there was something like an upload parameter. When the upload parameter is set to 1 you can send multiple lines to paypal.

Update PayPal information about this

Ben Fransen
  • 10,884
  • 18
  • 76
  • 129
0

Haven't tested, but according to documentation, you could use multiple hidden inputs with name item_number_X (X=number) inside paypal form to store variables:

<INPUT TYPE="hidden" name="item_number_1" value="value1">
<INPUT TYPE="hidden" name="item_number_2" value="value2">

From paypal docs:

Recordkeeping with passthrough variables

Some variables are exclusively for your own use, such as order management. PayPal returns the values that you send through Instant Payment Notification exactly as you sent them. For this reason, they are called passthrough variables. Their values are not recorded or used by PayPal.

The following are passthrough variables:

  • custom
  • item_number or item_number_x
  • invoice
cdalxndr
  • 1,435
  • 1
  • 15
  • 20
0

Yes, you can! You can use 'custom' variable and add in your form

<INPUT TYPE="hidden" name="custom" value="user_id=1&uname=jj">

And in your IPN.php:

$custom = $_POST['custom'];

And extract the variables from string

Fox
  • 103
  • 11