2013-12-08 100 views
0

我正在做一个网站,我已经在沙箱模式下集成了贝宝付款。我想通过php文件列出我通过沙箱商户帐户所做的所有交易。我是paypal API的初学者,但我有我的沙盒商人帐户的用户名,密码和签名。我想这个代码,我在List of PayPal transactions列出所有贝宝交易ID

<?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

我有点困惑。我将你的代码粘贴到我的编辑器中,我只显示了总共33行,没有报告任何语法错误。由于你正在使用PHP,我建议查看我的[PayPal类库](http://www.angelleye.com/download-angell-eye-php-class-library-for-paypal/)。它将使您对PayPal的API调用变得非常简单。 –

+0

@AndrewAngell没有人,它的52行代码。我会尝试你的。 :) –

+0

@AndrewAngell我和你的班级一起尝试过。但它的返回错误'安全标题无效',但我确信我的凭据。 –

回答

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]) 
);