#mauriver21
1 messages · Page 1 of 1 (latest)
You could look into autopagination: https://stripe.com/docs/api/pagination/auto
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I also checked that but it wasn't clear how to implement it.
It's also tied to the limit
If you select node there's an example
Only difference is you'll pass charges instead of customers
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
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
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
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)
autoPage didn't work, it takes too long giving a timeout error 😦
Can you share your code?
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);
}
});
Are you in Node 10+ ?
Node v16.14.0
Gotcha. Then you'll need to follow the pattern for the Node 10+ example that's linked in the autopagination docs: https://stripe.com/docs/api/pagination/auto
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
ie:
// Do something with customer
}```
And you'd need to switch to charge instead of customer
this one is slower
timeout error too
there is no way to convert a report into a JSON response?
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?
right
Can I ask why you're specifically using the Charges List API, it's expanding the balance_transaction on each charge so it's more prone to timing out I believe. Could you use the Balance Transaction List API, https://stripe.com/docs/api/balance_transactions/list#balance_transaction_list-created and break them to by created so it had less load?
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
Sure!
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
That is my understanding, let me see if I can find the document on this. You should not have to filter anything