[英]Stripe API: List all Charges
我正在使用https://stripe.com/docs/api?lang=php#list_charges獲取列出所有費用,但此處指定
count可選-默認值為10。要返回的對象數限制。 計數范圍是1到100。
我有成千上萬的條目,現在我該如何獲得全部。 雖然如果我將count設置為100,它會返回110條記錄。
您可以使用offset
參數。
一旦獲得100筆交易,然后通過在URL中添加offset=100
進行另一個調用。
這將帶來下100個事務,然后使offset=200
,依此類推。
更新:部分棄用了offset
參數: API更新日志-2015-09-23
$charges = \Stripe\Charge::all();
foreach ($charges->autoPagingIterator() as $charge) {
// Do something with $charge
}
是的,我可以抵消所有記錄。
這是一個PHP示例: \\Stripe\\Charge::all(array("limit" => 3, "offset" => 10));
一個Ruby示例: Stripe::Charge.all(limit: 3, offset:3)
與Stripe API文檔一樣,它們在過濾方面可能更加清晰。
來源: https : //stripe.com/docs/api/php#list_charges,https : //stripe.com/docs/api/ruby#list_charges
如果不建議使用偏移量
$result = [];
$created_at = strtotime($request->end_data);
//created_at should be today's date epoch. search google for epoch
$has_more = false;
$a = 0;
do{
print_r($a);
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$temp = \Stripe\BalanceTransaction::all( array(
'limit' => 100,
'created' => array(
'lte' => $created_at,
)
));
$result = array_merge($temp->data,$result);
$created_at = $temp->data[99]->created_at;
//api returns a parameter has_more(boolean), which means there is more
//data or not so you can also put that in while condition, for ex.
// $has_more = $temp->has_more;
$a++;
}while($a < 5);
dd($result);
這對我有用,我能夠一次獲得500條記錄,因為$ a <5 api命中5次,並且每次創建的參數都是te(小於等於)更改每個api請求並返回比當前請求提供的先前記錄。 我也將每個api調用的結果附加到另一個結果數組
不幸的是你不能。
我可以看到這種功能在哪些方面對記賬目的或其他方面都比較好,但是在向用戶顯示大量數據時,實現某種分頁通常是更好的用戶體驗。
如果您需要一次控制要顯示多少條記錄的絕對控制權,建議您在charge.succeeded事件上設置一個webhook,並將您的費用存儲在本地。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.