2013-12-08 145 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]) 
);