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 cocos的js代码调用wx.createUseInfoButton问题!
  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!
  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥35 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型
  • ¥15 Todesk 远程写代码 anaconda jupyter python3
  • ¥15 我的R语言提示去除连锁不平衡时clump_data报错,图片以下所示,卡了好几天了,苦恼不知道如何解决,有人帮我看看怎么解决吗?