传递和解析PayPal IPN自定义字段 [英] Passing and Parse PayPal IPN Custom field

查看:250
本文介绍了传递和解析PayPal IPN自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了PayPal IPN文件.当用户在站点上并按提交时,有关事务的详细信息将上载到数据库.相关ID通过PayPal作为自定义字段发送.付款完成时,IPN用于更新数据库,作为基于ID的事务完成.

一切都很好.

但是,这有点棘手.我还需要更新另一个表-折扣/优惠券代码数据库.更新基于输入的代码以及该代码仍然可以使用的次数.基本上,如果是50次,则使用一次后,数据库将被更新为49.因此,我需要传递代码,并允许其余使用,因此可以说更新表,其中code = XXXX(更新新值49,等等).

我可以算出如何在自定义字段中传递所有这些值,但不能算出如何再次解析它们?阅读有关用:等分隔它们的信息,但需要一些以前做过的人的建议.

这是IPN详细信息当前返回的方式:

$ custom = $ _POST ['custom'];

谢谢.

解决方案

我最近刚刚做过此事,
将您的贝宝自定义字段发送到数据,您可以在该自定义字段内使用分隔符拆分数据. 在下面的示例中,使用"|"分隔值,您可以使用任何希望在字符集中使用的字符.

$member_id = 1;
$some_other_id = 2;
<input type="hidden" name="custom" value="<?php echo $member_id.'|'.$some_other_id ?>"/>

这将输出:

<input type="hidden" name="custom" value="1|2"/>

当您从贝宝(IPN响应)获取信息时,将其处理如下:

$ids = explode('|', $_POST['custom']); // Split up our string by '|'
// Now $ids is an array containing your 2 values in the order you put them.
$member_id = $ids[0]; // Our member id was the first value in the hidden custom field
$some_other_ud = $ids[1]; // some_other_id was the second value in our string.

因此,基本上,我们发送一个带有自定义定界符的字符串,我们选择该字符串为paypal,paypal会将其返回给IPN响应.然后,我们需要将其拆分(使用explode()函数),然后按照自己的意愿进行操作.

当您从数据库中获取值时,可以使用常规方法将其选中,然后使用以下方法将其减1:

$val_from_db--; // Thats it!, Takes the current number, and minus 1 from it.

I have setup a PayPal IPN file. When the user is at the site and press submit details about the transaction is uploaded to the db. The relevant id is sent via PayPal as the custom field. When payment complete IPN used to update DB as transaction completed based on id.

All is fine.

However, this is the tricky bit. I also need to update another table - a discount/coupon code db. The update is based on the code entered and also the number of times the code can still be used. Basically if it was 50 times, after used once the db would be updated with 49. So I need to pass the code and the remaining uses allowed so can say update table where code = XXXX (update new value of 49 etc).

I can work out how to pass all these values in the custom field, but cannot work out how to parse them out again? Read about separating them with : etc, but need some advice from someone who has done before.

This is how IPN details currently comes back:

$custom = $_POST['custom'];

Thank you.

解决方案

I did just this recently,
Send your paypal custom field to data as your would, inside that custom field, use a separator to split your data. In the below example, the values are split using a "|", you can use any character you want available in your charset.

$member_id = 1;
$some_other_id = 2;
<input type="hidden" name="custom" value="<?php echo $member_id.'|'.$some_other_id ?>"/>

This will output:

<input type="hidden" name="custom" value="1|2"/>

When you get the information from paypal (the IPN response) process it like so:

$ids = explode('|', $_POST['custom']); // Split up our string by '|'
// Now $ids is an array containing your 2 values in the order you put them.
$member_id = $ids[0]; // Our member id was the first value in the hidden custom field
$some_other_ud = $ids[1]; // some_other_id was the second value in our string.

So basically, we send a string with a custom delimiter that we choose to paypal, paypal will return it to us in the IPN response. We then need to split it up (using the explode() function) and then do what you would like with it.

When you get your value from the database your select it using normal methods, then just decrement it by 1 using:

$val_from_db--; // Thats it!, Takes the current number, and minus 1 from it.

这篇关于传递和解析PayPal IPN自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆