【发布时间】:2013-12-25 19:38:15
【问题描述】:
我正在做一个网站,我在沙盒模式下集成了贝宝支付。我想列出我通过 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。
【问题讨论】:
-
我有点困惑。我将您的代码粘贴到我的编辑器中,我只显示了 33 行,没有报告任何语法错误。由于您使用的是 PHP,我建议您查看我的 class library for PayPal。它将使您对 PayPal 的 API 调用变得非常简单。
-
@AndrewAngell 没有人,它有 52 行代码。我会试试你的。 :)
-
@AndrewAngell 我试过你的课。但它返回错误“安全标头无效”,但我非常确定我的凭据。
-
哦,是的,哈,我没有向下滚动,所以我没有看到你的脚本的底部。正如@machavity 解释的那样,您对数组使用了错误的语法。
-
至于您从我的库中获得的安全标头,如果您确定凭据是正确的,那么您一定不能按照您的想法设置 $sandbox,因此您正在发送沙盒凭据到实时服务器,反之亦然。无论如何,安全标头总是意味着您的凭据不正确。
标签: php paypal transactions