php - 如何使用 strip API 检索客户总数(没有 "limit")

标签 php api stripe-payments

我正在使用 PHP stripe API 来检索特定 stripe 帐户的所有客户的列表。我只需要客户对象的电子邮件地址。

以下函数运行良好,但仅返回 10 个客户。

  function getListOfCustomers($stripe){
        \Stripe\Stripe::setApiKey($stripe['secret_key']);
        $list_of_customers = \Stripe\Customer::all(array());
        return $list_of_customers['data']; 

    }

看完here关于 API,它告诉我“限制”参数(即 \Stripe\Customer::all(array("limit"=> 3)); )是可选的,“默认限制是 10 ”。 所以我想这就是它只返回 10 个客户的原因。

我想回馈无限数量的客户。 我想知道是否有人确切知道如何执行此操作?

我还在 same page 上阅读了以下内容:

You can optionally request that the response include the total count of all customers that match your filters. To do so, specify include[]=total_count in your request.

但是它并没有告诉我如何“将其包含在我的请求中”。 我尝试了以下操作,但收到语法错误。

$list_of_customers = \Stripe\Customer::all(array(), include[]=total_count);

我也试过:

$list_of_customers = \Stripe\Customer::all(array(include[]=total_count));

感谢您的帮助。

最佳答案

Stripe 不再支持获取对象总数,因为该功能已被弃用一段时间。

相反,他们建议遍历所有客户以对他们进行计数或找到您想要的特定客户。使用 auto-pagination 真的很容易您的代码将如下所示:

$customers = \Stripe\Customer::all(array("limit" => 100));
foreach ($customers->autoPagingIterator() as $customer){
     echo "Current customer: $customer";
}     

它不会一次将所有客户存储在 $customers 中,而只会存储一个页面。但是,当您到达该页面的最后一个页面时,迭代器会自动为您获取下一页。

关于php - 如何使用 strip API 检索客户总数(没有 "limit"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42353346/

相关文章:

php - 获取制表符分隔文件并根据与唯一字段的匹配行更新 MySQL 字段

api - 不使用 WHMCS API 插入的自定义字段

javascript - 连接injectStripe和mapDispatchToProps时出现错误: dispatch is not a function,

javascript - 新 Stripe Checkout 中的税率

php - 我如何为帐户创建定时禁令? (PHP/MySQL)

php - 创建 csv 文件时添加标题 PhP、SQL

php - Symfony 2.1 - 未捕获的 PHP 异常 Twig_Error_Runtime

api - 如何获取页面帖子列表,包括页面的幽灵/暗帖子?

api - 有openstreetmap的API吗?

javascript - 使用 Stripe 元素时如何将电子邮件传递给 Stripe ?