【问题标题】:List of PayPal transactions贝宝交易清单
【发布时间】:2013-07-11 05:27:51
【问题描述】:

设置如下:

我有一个客户的网站设置。客户:

  1. 访问网站
  2. 为我们的记录输入基本信息
  3. 通过“立即购买”按钮转到 PayPal
  4. 通过 PayPal 付款
  5. 返回网站

我想知道的是如何获得所有交易的清单?我有 PayPal 登录名以及 API 用户名、密码和签名,但在我的一生中,我无法在互联网上找到一个地方提供了如何通过 PHP 或从 PayPal 中提取交易列表的示例jQuery/Javascript/Ajax。

有人有什么想法吗?例子?

提前致谢。

更新:

我能够为这个问题制定解决方案。请参阅下面的代码和 cmets 答案。

【问题讨论】:

    标签: php javascript jquery json paypal


    【解决方案1】:

    他们有一个 TransactionSearch API:

    https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/TransactionSearch_API_Operation_NVP/

    我使用我的发票号码提取来检索交易 ID 以进行退款。

    【讨论】:

    • 感谢您的帮助和代码,但如果没有您使用的 PHP 类,您发布的所有内容都只是一堆变量。您是否有正在使用的类的代码或代码链接?
    • 您可以使用 Angell EYE 类。
    【解决方案2】:

    好的,所以我终于能够开发出一些可行的东西。代码发布在下面,其中包含指向 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 错误
    • 这似乎是一个 PHP 错误,就好像你有一个不合适的字符或什么的。重新检查您的代码,因为没有看到您的代码,我什至不知道从哪里开始。
    • 我编写了您在此答案中给出的第一个编码解决方案,以 &lt;?php $info = 'USER=[API_USERNAME]' .'&amp;PWD=[API_PASSWORD]' .'&amp;SIGNATURE=[API_SIGNATURE]' .'&amp;VERSION=94' .'&amp;METHOD=GetTransactionDetails' .'&amp;TRANSACTIONID=[TRANSACTION_ID]' 开头我更改了我的用户名、密码和签名,但它不起作用。
    • 上面第一个代码sn-p有两个错误。将从 paypal 返回的数据汇集在一起​​的返回数组数组应使用“key”=>“value”而不是“key”=“value”构造。此外,该数组的值应取自 $temp 而不是 $result。然后,您的脚本会使用来自 paypal 的正确交易数据创建交易数组。
    • 你真的是公爵!我在这里发布了更正的代码 - stackoverflow.com/questions/24561873/…
    【解决方案3】:
      <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 元素一样插入元素(例如 &lt;p&gt;)。

    【讨论】:

      猜你喜欢
      • 2012-08-31
      • 2015-10-13
      • 1970-01-01
      • 2015-08-11
      • 2017-06-29
      • 2014-03-16
      • 1970-01-01
      • 2014-07-25
      • 2015-12-30
      相关资源
      最近更新 更多