如何从paypal IPN调用自定义变量?

时间:2015-05-10 03:19:08

标签: php paypal

所以我使用php设置我的按钮发送自定义变量:

    $vars = array(
            'cmd' => '_s-xclick',
            'hosted_button_id' => 'xxxxxxxxx',
            'custom' => $lastId,
    );

    header('Location: https://www.sandbox.paypal.com/cgi-bin/webscr?' . http_build_query($vars));

我想在这里做的是通过Paypal将最后插入的行ID发送到我的paypal IPN。然后根据付款状态使用id修改记录。

所以在paypal IPN中,我将根据$ lastid查找表记录。 例如:

$sql = "SELECT x FROM table WHERE id = a";

a是应该从paypal返回的自定义变量。

2 个答案:

答案 0 :(得分:1)

IPN将数据的HTTP POST发送到您的脚本,因此您将像基本表单帖子一样解析它。因此,如果要将自定义变量添加到SQL查询中,您可以执行以下操作。

$lastId = isset($_POST['custom']) ? $_POST['custom'] : '';
$sql = "SELECT x FROM table WHERE id = '" . $lastId . "'";

答案 1 :(得分:0)

如果您需要在自定义中发送多个变量,可以使用implode()和explode()来检索。

发送:

$lastId = '1';
$lastDate = $insertDate;

$myCustomArr = array($lastId, $lastDate);
$myCustom = implode(',', $myCustomStrArr);

要回来:

if(isset($_POST['custom'])){
   $custom = $_POST['custom'];
   $customArr = explode(',', $custom);
   $lastId = $customArr[0];
   $lastDate = $customArr[1];
}