#mauriver21

1 messages · Page 1 of 1 (latest)

agile flumeBOT
cedar heath
opal jolt
#

I also checked that but it wasn't clear how to implement it.

#

It's also tied to the limit

cedar heath
#

If you select node there's an example

#

Only difference is you'll pass charges instead of customers

opal jolt
#

Honestly I don't understand the purpose of this function, It iterates over every record, but what does the limit parameter?

#

I don't see any difference, it prints each record individually

cedar heath
#

Pagination allows you to see all records

#

If you just use limit then you get that many results and just 1 page of results

#

Auto pagination will automatically page through all the results fetching limit number per page

opal jolt
#

So you mean, the limit is specific of the list method,
and the autoPage is for iterating over all the records?

It's like a combination of both processes, autoPage helps me to intercept any existing charge object, with this I can sum the total amount, and in the other hand, the list method will return an array with the configured limit?

#

Is there another alternative? I'm seeing autoPage is a very slow process

cedar heath
#

There's not really an alternative. When you have a very large number of charges, fetching them via the api is going to be slow. Autopagination just allows you to get all charges in 1 request instead of manually making many requests to parse through all your charges (since the api is limited to retrieving 100 charges in 1 list request)

opal jolt
#

autoPage didn't work, it takes too long giving a timeout error 😦

cedar heath
#

Can you share your code?

opal jolt
#
app.get('/balance', async (_, res) => {
  try {
    let payment_total = 0;
    let fee_total = 0;
    let net_total = 0;

    await stripe.charges
      .list({
        captured: true,
        expand: ['data.balance_transaction'],
      })
      .autoPagingEach((charge) => {
        fee_total += charge.balance_transaction.fee;
        net_total += charge.balance_transaction.net;
      });

    payment_total = fee_total + net_total;

    res.send({ payment_total, fee_total, net_total });
  } catch (error) {
    handleError(res, error);
  }
});
cedar heath
#

Are you in Node 10+ ?

opal jolt
#

Node v16.14.0

cedar heath
#

ie:

  // Do something with customer
}```
#

And you'd need to switch to charge instead of customer

opal jolt
#

this one is slower

#

timeout error too

#

there is no way to convert a report into a JSON response?

fleet moat
#

Hi, stepping in here and catching up..

#

What you're ultimately trying to do it to see the sum of all of your charges on your account, is that correct?

opal jolt
#

right

fleet moat
opal jolt
#

I will check, yes you are right, the balance gives me directly the net and fee, let me try

#

I wasn't aware of this API

fleet moat
#

Sure!

opal jolt
#

a balance object only is created when the payment was captured?

#

or I need to filter by some specific status,
I was listing charges because I needed to filter only the captured payments

fleet moat
#

That is my understanding, let me see if I can find the document on this. You should not have to filter anything