我正试图弄清楚如何从Paypal访问第三方用户(包括在仪表板中)的交易信息。
理想情况下,我需要能够提取交易数据,而无需每次都手动授权应用程序,因为很多需要在后台进行。到目前为止,使用测试帐户,我可以看到我如何获得API用户名,密码和签名,我想我需要使用它。
我将使用哪种API(Classic / Rest)以及哪种身份验证方法最安全?
答案 0 :(得分:5)
经过一段时间的努力,我发现了一个简单但粗略的实现 - 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];
}
for($i=0; $i<(count($temp)/11)-1; $i++){
$returned_array[$i] = array(
"timestamp" => urldecode($temp["L_TIMESTAMP".$i]),
"timezone" => urldecode($temp["L_TIMEZONE".$i]),
"type" => urldecode($temp["L_TYPE".$i]),
"email" => urldecode($temp["L_EMAIL".$i]),
"name" => urldecode($temp["L_NAME".$i]),
"transaction_id" => urldecode($temp["L_TRANSACTIONID".$i]),
"status" => urldecode($temp["L_STATUS".$i]),
"amt" => urldecode($temp["L_AMT".$i]),
"currency_code" => urldecode($temp["L_CURRENCYCODE".$i]),
"fee_amount" => urldecode($temp["L_FEEAMT".$i]),
"net_amount" => urldecode($temp["L_NETAMT".$i]));
}
var_dump($returned_array);
这显然不是生产代码,但它足以从后面工作。