列出所有Paypal交易ID

时间:2013-12-08 19:35:54

标签: php paypal transactions

我正在建立一个网站,我在沙盒模式下整合了paypal付款。我想通过php文件列出我对 sandbox 商家帐户所做的所有交易。我是paypal API的初学者,但我有沙盒商家帐户的用户名,密码和签名。我尝试了在List of PayPal transactions

中找到的代码
<?php 
$info = 'USER=[API_USERNAME]'
        .'&PWD=[API_PASSWORD]'
        .'&SIGNATURE=[API_SIGNATURE]'
        .'&METHOD=TransactionSearch'
        .'&TRANSACTIONCLASS=RECEIVED'
        .'&STARTDATE=2013-01-08T05:38:48Z'
        .'&ENDDATE=2013-07-14T05:38:48Z'
        .'&VERSION=94';

$curl = curl_init('https://api-3t.paypal.com/nvp');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl, CURLOPT_POSTFIELDS,  $info);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);

$result = curl_exec($curl);

# Bust the string up into an array by the ampersand (&)
# You could also use parse_str(), but it would most likely limit out
$result = explode("&", $result);

# Loop through the new array and further bust up each element by the equal sign (=)
# and then create a new array with the left side of the equal sign as the key and the right side of the equal sign as the value
foreach($result as $value){
    $value = explode("=", $value);
    $temp[$value[0]] = $value[1];
}

# At the time of writing this code, there were 11 different types of responses that were returned for each record
# There may only be 10 records returned, but there will be 110 keys in our array which contain all the different pieces of information for each record
# Now create a 2 dimensional array with all the information for each record together
for($i=0; $i<count($temp)/11; $i++){
    $returned_array[$i] = array(
        "timestamp"         =    urldecode($result["L_TIMESTAMP".$i]),
        "timezone"          =    urldecode($result["L_TIMEZONE".$i]),
        "type"              =    urldecode($result["L_TYPE".$i]),
        "email"             =    urldecode($result["L_EMAIL".$i]),
        "name"              =    urldecode($result["L_NAME".$i]),
        "transaction_id"    =    urldecode($result["L_TRANSACTIONID".$i]),
        "status"            =    urldecode($result["L_STATUS".$i]),
        "amt"               =    urldecode($result["L_AMT".$i]),
        "currency_code"     =    urldecode($result["L_CURRENCYCODE".$i]),
        "fee_amount"        =    urldecode($result["L_FEEAMT".$i]),
        "net_amount"        =    urldecode($result["L_NETAMT".$i]));
}
?>

但是这是说Parse error: syntax error, unexpected '=', expecting ')' in C:\wamp\www\all_transactions.php on line 40 认为上面的代码提供了所有细节,我只需要事务ID。

1 个答案:

答案 0 :(得分:0)

您使用array的错误语法。它应该是$key => $value

$returned_array[$i] = array(
    "timestamp"         =>    urldecode($result["L_TIMESTAMP".$i]),
    "timezone"          =>    urldecode($result["L_TIMEZONE".$i]),
    "type"              =>    urldecode($result["L_TYPE".$i]),
    "email"             =>    urldecode($result["L_EMAIL".$i]),
    "name"              =>    urldecode($result["L_NAME".$i]),
    "transaction_id"    =>    urldecode($result["L_TRANSACTIONID".$i]),
    "status"            =>    urldecode($result["L_STATUS".$i]),
    "amt"               =>    urldecode($result["L_AMT".$i]),
    "currency_code"     =>    urldecode($result["L_CURRENCYCODE".$i]),
    "fee_amount"        =>    urldecode($result["L_FEEAMT".$i]),
    "net_amount"        =>    urldecode($result["L_NETAMT".$i])
);