Paypal IPN process more than one custom variable

守給你的承諾、 提交于 2020-01-21 04:22:08

问题


So I've implemented paypal IPN in my site and I'm in the middle of the work process. Now I want to use more than 1 custom variable in the pp form currently I'm using this one only

<input type="hidden" name="custom" value="<?php echo $user_id; ?>">

So I know the variable with the name 'custom' is allowed. I want to know if I can pass more variables so I can filter the payments based on their criterias. So if for example shipping is more than $0.00 I set a variable "shipping_cost" like this:

<input type="hidden" name="shipping_cost" value="<?php echo $cost; ?>">

or for other purposes. Is this allowed? Or paypal has an already defined list of allowed variables we can use? I really want to solve this problem as there's not always one type of payment we can process... Thank you guys.


回答1:


As I (and many others I imagine) am also facing this problem, I thought I'd share some solutions I came across.

This one raised in the PayPal Community, suggests the use of the Option Variables which appear to offer a key/value pair implementation to facilitate up to 99 vars (for the record I have not actually tried this).

The most commonly accepted solution (which I also favor) is to add all of your data to a DB record, then use the custom var to store your record ID, which can obviously be used later (e.g. via IPN) to retrieve your data.




回答2:


this way you can pass more parameters

<input type="hidden" name="custom" value="variable1=234&var2=summa&etc=xyz"/>

use the above one on your paypal form.

and process through the following code.

 parse_str($_POST['custom'],$_MYVAR);

echo $_MYVAR['variable1'];
echo $_MYVAR['var2'];
echo $_MYVAR['etc'];

i hope this one help you.




回答3:


PayPal defines what fields you may use here. Any other fields will be ignored.

There is a 'shipping' field defined, and PayPal will use the value of that field to charge an extra amount for shipping. You will also be able to get that value from the IPN or PDT data.

If you need to pass other values, you could consider passing a string formatted in query-string style (var1=value1&var2=value2...) in the 'custom' field. Note that the maximum number of characters permitted in this field is 256. You would then parse this when you get the IPN or PDT response.

If the size of the custom field is too limiting, then you could try what I described in another answer here.



来源:https://stackoverflow.com/questions/11631926/paypal-ipn-process-more-than-one-custom-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!