以下是设置:
我有一个客户端的站点设置。客户:
- 访问网站
- 输入我们记录的基本信息
- 通过"立即购买"按钮将收益转入PayPal
- 通过PayPal付款
- 返回网站
我想知道的是如何获得所有交易的列表?我有PayPal登录以及API用户名、密码和签名,但就我而言,我在互联网上找不到一个地方可以提供如何通过PHP或jQuery/Javascript/Ajax从PayPal获取交易列表的示例。
有人有什么想法吗?示例?
提前谢谢。
更新:
我想出了一个解决这个问题的办法。请参阅下面的代码和注释。
好的,所以我终于能够开发出一些有效的东西。代码发布在下面,链接到PayPal 的TransactionSearch API选项
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/TransactionSearch_API_Operation_NVP/
<?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($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]));
}
?>
此外,我还想出了一个漂亮的小而简单的脚本来获取有关特定事务的更多细节:
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/GetTransactionDetails_API_Operation_NVP/
<?php
$info = 'USER=[API_USERNAME]'
.'&PWD=[API_PASSWORD]'
.'&SIGNATURE=[API_SIGNATURE]'
.'&VERSION=94'
.'&METHOD=GetTransactionDetails'
.'&TRANSACTIONID=[TRANSACTION_ID]'
.'&STARTDATE=2013-07-08T05:38:48Z'
.'&ENDDATE=2013-07-12T05:38:48Z';
$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);
parse_str($result, $result);
foreach($result as $key => $value){
echo $key.' => '.$value."<BR>";
}
?>
他们有一个TransactionSearch API:
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/TransactionSearch_API_Operation_NVP/
我使用我的按发票号码提取交易ID进行退款。
<script
data-env="sandbox"
data-tax="0.00"
data-shipping="0.00"
data-currency="USD"
data-amount="0.00"
data-quantity="0"
data-name="No Item Selected"
data-button="buynow" src="https://www.paypalobjects.com/js/external/paypal-button.min.js?merchant=ben4xfer@gmail.com" async="async"></script>
这是一个html元素,当点击按钮时,它会连接到贝宝API进行交易。请勿更改data-button
、src
或async
属性。完成测试后,完全移除data-env
节点(data-env
节点可防止在测试时进行实际充电)。根据名称更改所有其他属性(例如,您可以将data-name
更改为您正在销售的产品的名称)。像插入任何其他html元素一样插入该元素(例如<p>
)。