#xfechx
1 messages ยท Page 1 of 1 (latest)
๐ happy to help
all our API List calls return the list ordered by created descending
if I am using pagination, how can I count
all the results, so that then I can print PDFs from balance transactions in an ordered numbered by date.
I need to add a index number to each of them
i.e 1, 2, 3 ordered from older to newer
you can use https://stripe.com/docs/api/pagination/auto and the order you get is already from older to newer
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Here is what i am using
foreach ($balance_transactions->autoPagingIterator() as $balance_transaction) {
// Do something with $balance_transaction
$i++;```
but then my results are backwards
from older to newer
๐คฆ my bad, sorry I thought you said the opposite
and afaik I cannot php count with auto paging
you can use array_unshift() to add each element on the top the array
hmm where would I use this?
inside the foreach
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
or you can use array_reverse https://www.php.net/manual/en/function.array-reverse.php
but that won't work with the paging
there are multiple ways of achieving this
I need more than 100 results at a time
auto-paging will go over all pages
can you help me?
if I add it inside the foreach , then it will already have the iteration how it is fetched from Stripe (i.e backwards). I don't know where I should use these functions you shared
taking a look please give me a few more minutes
thanks a lot
you can start by doing this
[
'created' => [
'gte' => strtotime($startDate),
'lt' => strtotime($endDate) + 86400 // Add 1 day to include payments on the end date
],
'limit' => 100,
'expand' => [
'data.source.customer',
'data.source.payment_intent',
'data.source.invoice',
]
],
$connected_account
)->autoPagingIterator();
$balance_transactions = [];
foreach ($balance_transactions_iterator as $balance_transaction) {
array_unshift($balance_transactions, $balance_transaction);
}```
which will get you an array $balance_transactions in the reverse order, then you can loop over $balance_transactions and do whatever you want
thanks a lot, I will try it
Hi there ๐ apologies, but my teammate stepped away and there are a fair number of Stripe-api related questions in the channel that I need to tend to currently. If time permits I'll circle back and see if I can lend a hand with this.
ok
anyone?
please help... I cannot order the balance transactions from older to newer