dongningce9075 2016-02-15 06:15
浏览 49
已采纳

使用PHP库从条带帐户检索付款的代码示例

I am not sure how to include the PHP stripe api library into my php file in order to get a list of transactions from my stripe account. I have downloaded the lib source and extracted the contents to a folder into which I saved a file called getStripeTransList.php with the following code inside:-

The error I get is

Class Stripe not found

I have adjusted the code as follows:-

<?php

require "Stripe.php";
require "Charge.php";

Stripe\Stripe::setApiKey("sk_test_...");
$transList = Stripe\Charge::all(array("limit" => 3));
var_dump($transList);

The error I now get is 'Stripe\ApiResource' not found in Charge.php. Charge.php looks like this:-

<?php

namespace Stripe;

class Charge extends ApiResource

{
    /**
     * @param string $id The ID of the charge to retrieve.

with class APIResource declared in APIResource.php. I get the feeling that I have not installed or configured the stripe PHP API library correctly with all these dependencies appearing? How should the library be installed. I try not to use Composer, but will if that is the only way.

  • 写回答

1条回答 默认 最新

  • dongle0396 2016-02-15 10:41
    关注

    You're not including the Stripe PHP bindings correctly.

    If you're using Composer, you'd simply include Composer's autoload.php file:

    require_once("vendor/autoload.php");
    

    If you installed the library manually, you'd need to include the init.php file:

    require_once("/path/to/stripe-php/init.php");
    

    Once the library has been included, you will be able to list all charges like this:

    $charges = \Stripe\Charge::all();
    foreach ($charges->data as $charge) {
        // Do something with $charge
    }
    

    Note that all "list" API calls only return a finite number of resources. To retrieve the entire list, you might need to issue several API calls with pagination parameters to pick up where the previous call left off.

    If you're using the latest versions of the bindings (3.9.0), you can also use the new auto-pagination feature:

    $charges = \Stripe\Charge::all();
    foreach ($charges->autoPagingIterator() as $charge) {
        // Do something with $charge
    }
    

    This will automatically iterate over all charges, querying new pages as needed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 android报错 brut.common.BrutException: could not exec (exit code = 1)
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!