#xfechx

1 messages ยท Page 1 of 1 (latest)

steep valeBOT
summer thunder
#

๐Ÿ‘‹ happy to help

#

all our API List calls return the list ordered by created descending

vale steeple
#

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

summer thunder
vale steeple
#

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

summer thunder
#

from older to newer
๐Ÿคฆ my bad, sorry I thought you said the opposite

vale steeple
#

and afaik I cannot php count with auto paging

summer thunder
#

you can use array_unshift() to add each element on the top the array

vale steeple
#

hmm where would I use this?

summer thunder
#

inside the foreach

vale steeple
#

can you help me with an example, pleasee?

#

Here is my code:

summer thunder
vale steeple
#

but that won't work with the paging

summer thunder
#

there are multiple ways of achieving this

vale steeple
#

I need more than 100 results at a time

summer thunder
#

auto-paging will go over all pages

vale steeple
#

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

summer thunder
#

taking a look please give me a few more minutes

vale steeple
#

thanks a lot

summer thunder
#

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

vale steeple
#

thanks a lot, I will try it

vale steeple
#

one moment please

#

do I need to loop again inside that foreach loop?

main fable
#

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.

vale steeple
#

ok

vale steeple
#

anyone?

vale steeple
#

please help... I cannot order the balance transactions from older to newer

steep valeBOT