我正在使用 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/