【问题标题】:how to get the paypal adaptive payments IPN posts?如何获得paypal自适应支付IPN帖子?
【发布时间】:2013-09-24 02:02:35
【问题描述】:

所以我有我的 PHP IPN 脚本工作,现在我只是不确定如何获取帖子值? Paypal 将帖子作为这样的数组返回。

transaction[0].is_primary_receiver=false
&transaction[0].id_for_sender_txn=50E02759CC687801U
&log_default_shipping_address_in_transaction=false
&transaction[0].receiver=xxxxxxxxxx@gmail.com
&action_type=PAY
&transaction[1].status=Completed

显然还有更多,但你明白了,我尝试访问帖子以获得这样的状态。

$payment_status = $_POST['transaction'][1]['status']

但这不起作用,它返回第一个字母 C。 那么如何访问所有这些值。

【问题讨论】:

    标签: php paypal paypal-sandbox paypal-ipn


    【解决方案1】:

    经过一番搜索,我发现此链接很有帮助:https://developer.paypal.com/webapps/developer/docs/classic/ipn/ht_ipn/

    页面最相关的部分:

    // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.
    // Instead, read raw POST data from the input stream. 
    $raw_post_data = file_get_contents('php://input');
    $raw_post_array = explode('&', $raw_post_data);
    $myPost = array();
    foreach ($raw_post_array as $keyval) {
        $keyval = explode ('=', $keyval);
        if (count($keyval) == 2)
            $myPost[$keyval[0]] = urldecode($keyval[1]);
    }
    

    【讨论】:

    • 我必须在上面的脚本中添加一个额外的东西。在它对 $keyval[1] 进行 urldecode 的地方,我还必须对索引 $keyval[0] 进行 urldecode。原因是对于像 transaction[1].status 这样的东西,如果没有 urldecoding,它会将其设置为 transaction%5B1%5D.status 。除了它很好用之外,我只是使用 for 语句来遍历每笔交易以将价格相加并检查它并获取 txn_id 和其他东西。
    • 太棒了!你说对了。 ;)
    猜你喜欢
    • 2014-06-23
    • 2013-11-03
    • 2013-03-20
    • 2012-05-05
    • 2012-04-22
    • 2012-06-10
    • 2014-04-30
    • 2011-08-27
    • 2012-07-18
    相关资源
    最近更新 更多