PayPal交易列表

14

以下是设置:

我为客户设置了一个网站,客户:

  1. 访问网站
  2. 输入基本信息供我们记录
  3. 通过“购买”按钮进入PayPal
  4. 通过PayPal进行付款
  5. 返回网站

我想知道如何获取所有交易的列表?我有PayPal登录名以及API用户名,密码和签名,但我无法在互联网上找到任何一个示例,说明如何通过PHP或jQuery / Javascript / Ajax从PayPal检索交易列表。

有人有什么想法? 示例?

提前致谢。

更新:

我已经开发出了解决此问题的方案。请参见我的答案,其中包括代码和注释。

3个回答

18

好的,我最终成功开发出了可行的东西。在下面发布了代码,并提供了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>";
}
?>

嗨,我尝试了第一个编程来显示交易,但我收到了SCREAM:Error suppression ignored for Parse error: syntax error, unexpected '=', expecting ')' in C:\wamp\www\all_transactions.php on line 40错误。 - Isham Mohamed
这似乎是一个 PHP 错误,好像你的代码中有一个字符错位了或者其他什么问题。请重新检查你的代码,因为如果没有看到你的代码,我甚至不知道从哪里开始。 - The Duke Of Marshall שלום
我编写了你在这个答案中给出的第一个编码解决方案,从 <?php $info = 'USER=[API_USERNAME]' .'&PWD=[API_PASSWORD]' .'&SIGNATURE=[API_SIGNATURE]' .'&VERSION=94' .'&METHOD=GetTransactionDetails' .'&TRANSACTIONID=[TRANSACTION_ID]' 开始。我更改了我的用户名、密码和签名,但它没有起作用。 - Isham Mohamed
以上第一个代码片段中有两个错误。从PayPal返回并汇总数据的returned_array数组应该是用“key” => “value”而不是“key” = “value”构建的。此外,这个数组中的值应该来自$temp而不是$result。您的脚本然后使用来自PayPal的正确交易数据创建交易数组。 - paj
1
你真的是大牛!我已经在这里发布了修正后的代码 - http://stackoverflow.com/questions/24561873/how-to-access-3rd-party-transaction-information-in-paypal/24562130#24562130 - thatguy

0
  <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元素,它连接到PayPal API,当按钮被点击时进行交易。请勿更改data-buttonsrcasync属性。在测试完成后完全删除data-env节点(data-env节点在测试期间防止实际收费)。根据其名称更改所有其他属性(例如,您将更改data-name为您正在销售的产品名称)。像任何其他HTML元素一样插入该元素(例如,<p>)。


0

我很感激你的帮助和代码,但是如果没有你使用的PHP类支持,你发布的所有内容只是一堆变量。你有这个类的代码或链接吗? - The Duke Of Marshall שלום
你可以使用Angell EYE类。 - Matthew Camp

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接