首页 > 解决方案 > GoCardless API - 列出订阅

问题描述

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

正如您在下面看到的那样,我已按照说明进行操作,但是当我运行此脚本时根本没有显示任何内容 - 有人知道我可能做错了什么吗?

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

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

标签: phpapigocardless

解决方案


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

正如RiggsFolly所说(并记录在 GoCardless 的 API 文档中),调用$client->subscriptions()->list()返回一个光标分页的响应对象。所以你需要对这个结果做点什么。那是什么,我不知道,因为这是您的应用程序的业务逻辑,只有您知道。

<?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
}

推荐阅读