Paypal IPN读取变量 - 事务[0] .amount

时间:2013-06-17 11:32:48

标签: php post paypal paypal-ipn

我正在使用Paypal Adaptive Payments,我正在尝试从我的IPN侦听器读取参数,但不是很简单。首先,这是我的IPN听众:

<?php
/**
 * This is a sample implementation of an IPN listener
 * that uses the SDK's PPIPNMessage class to process IPNs
 * 
 * This sample simply validates the incoming IPN message
 * and logs IPN variables. In a real application, you will
 * validate the IPN and initiate some action based on the 
 * incoming IPN variables.
 */
require_once("paypal/samples/PPBootStrap.php");

$ipnMessage = new PPIPNMessage();
foreach($ipnMessage->getRawData() as $key => $value) {
    error_log("IPN: $key => $value");
}


if($ipnMessage->validate()) {
    error_log("Success: Got valid IPN data");   




    $receiver_email = $_POST['transaction[0].amount']; //DOES NOT WORK

        //THIS TWO PARAMETERS ARE OK

    $payment_status = $_POST['status'];
    $sender_email = $_POST['sender_email'];


} else {
    error_log("Error: Got invalid IPN data");   
}

?>

status和sender_email被正确读取,但是奇怪的事务[0] .amount返回未定义的索引错误!我知道这是作为事务%5B0%5D.amount传递的,但即使尝试替换字符串也会返回相同的错误!

2 个答案:

答案 0 :(得分:0)

PHP存在数组数据问题,请参阅https://github.com/paypal/sdk-core-php/blob/master/lib/ipn/PPIPNMessage.php#L45。请使用urldecode相应地解码数据

答案 1 :(得分:0)

您必须在__construct中的PPIPNMessage类中修复它。为两个参数添加urldecode

$this->ipnData[urldecode($keyValue[0])] = urldecode($keyValue[1]);

它已在master分支中修复,但尚未在最后一个版本中修复