GoCardless API - 列表订阅

GoCardless API - List Subscriptions

我正在使用 GoCardless 文档 here 来尝试列出客户的所有订阅。

我已经按照您在下面看到的说明进行操作,但是当我 运行 这个脚本时什么也没有显示 - 有谁知道我可能做错了什么?

require 'vendor/autoload.php';    
$client = new \GoCardlessPro\Client(array(
  'access_token' => 'XXXXXx',
  'environment'  => \GoCardlessPro\Environment::LIVE
));

     $client->subscriptions()->list([
  "params" => ["customer" => "CU000R3B8512345"]
]);

单独调用一个方法不会做任何事情。它会执行给定的方法,但不会自行在浏览器屏幕上打印任何内容。

作为RiggsFolly says (and is documented in GoCardless’s API documentation), calling $client->subscriptions()->list() will return a cursor-paginated response对象。所以你需要对这个结果做些什么。那是什么,我不知道,因为这是您应用程序的业务逻辑,只有您知道。

<?php

use GoCardlessPro\Client;
use GoCardlessPro\Environment;

require '../vendor/autoload.php';

$client = new Client(array(
    'access_token' => 'your-access-token-here',
    'environment' => Environment::SANDBOX,
));

// Assign results to a $results variable
$results = $client->subscriptions()->list([
    'params' => ['customer' => 'CU000R3B8512345'],
]);

foreach ($results->records as $record) {
    // $record is a variable holding an individual subscription record
}

使用 Gocardless 进行分页:

function AllCustomers($client)
{
    $list = $client->customers()->list(['params'=>['limit'=>100]]);
    $after = $list->after;
    // DO THINGS
    print_r($customers);

    while ($after!="")
    {
        $customers = $list->records;
        // DO THINGS
        print_r($customers);
        
        // NEXT
        $list = $client->customers()->list(['params'=>['after'=>$after,'limit'=>100]]);
        $after = $list->after;
    }
}