【问题标题】:How to Call Custom variable from paypal IPN?如何从贝宝 IPN 调用自定义变量?
【发布时间】:2015-05-10 03:19:07
【问题描述】:

所以我已经使用 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 将 Last Inserted Row id 发送到我的 paypal IPN。然后根据支付状态使用id修改记录。

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

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

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

【问题讨论】:

  • 你能详细说明你的问题吗?

标签: php paypal


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    如果您需要在自定义中发送多个变量,您可以使用 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];
    }
    

    【讨论】:

      猜你喜欢
      • 2010-12-22
      • 2011-11-23
      • 2015-05-16
      • 2012-06-29
      • 2019-06-08
      • 2013-02-01
      • 1970-01-01
      • 2011-09-15
      • 2013-05-07
      相关资源
      最近更新 更多