简体   繁体   English

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

[英]Code example using PHP library to retrieve payments from stripe account

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. 我不知道如何将PHP条带api库包含到我的php文件中,以便从我的条带帐户中获取事务列表。 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:- 我已经下载了lib源并将内容解压缩到一个文件夹中,我在其中保存了一个名为getStripeTransList.php的文件,其中包含以下代码: -

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中找不到'Stripe \\ ApiResource'。 Charge.php looks like this:- Charge.php看起来像这样: -

<?php

namespace Stripe;

class Charge extends ApiResource

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

with class APIResource declared in APIResource.php. 在APIResource.php中声明的类APIResource。 I get the feeling that I have not installed or configured the stripe PHP API library correctly with all these dependencies appearing? 我觉得我没有正确安装或配置条带PHP API库,所有这些依赖项出现了吗? How should the library be installed. 应该如何安装库。 I try not to use Composer, but will if that is the only way. 我尽量不使用Composer,但如果这是唯一的方法。

You're not including the Stripe PHP bindings correctly. 您没有正确包含Stripe PHP绑定。

If you're using Composer, you'd simply include Composer's autoload.php file: 如果你正在使用Composer,你只需要包含Composer的autoload.php文件:

require_once("vendor/autoload.php");

If you installed the library manually, you'd need to include the init.php file: 如果手动安装库,则需要包含init.php文件:

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. 请注意,所有“list”API调用仅返回有限数量的资源。 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. 要检索整个列表,您可能需要使用分页参数发出多个API调用,以便在上一个调用停止的位置进行选择。

If you're using the latest versions of the bindings (3.9.0), you can also use the new auto-pagination feature: 如果您使用的是最新版本的绑定(3.9.0),您还可以使用新的自动分页功能:

$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. 这将自动迭代所有费用,根据需要查询新页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM