#subhrajeet99
1 messages · Page 1 of 1 (latest)
Yes it's the pagination api and each of our SDK has support for auto pagination
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 am using Node.js, I am using the has_more parameter to implement pagination but still getting all the charges as results
Node would have the autopagination like this
// In other environments:
stripe.customers.list({limit: 3})
.autoPagingEach(function(customer) {
// Do something with customer
});
Give me a mintue to check, thank you
I may share the request id
Hii, unfortunately it seems like it didn't work
Here is the code snippet-
// Fetch transactions for the current broker using auto-pagination
await stripe.charges.list({ customer: broker.stripe_customer_id, limit: 10 })
.autoPagingEach(async (charge) => {
const transaction = {
date: charge.created,
amount: charge.amount / 100,
status: charge.status,
};
if (!status || transaction.status === status) {
brokerTransactions.push(transaction);
}
});
Hi @spark sluice I'm taking over
Hello Jack
Why are you using auto pagination if you just want to retrieve 10 charges?
Let me explain it to you briefly but quickly
In my app I list all the transactions of a broker, who is a customer on my platform as well as connected account, the broker has his end customers, I want to list all the charges of that particular broker as customer and all the charges in his connect account too and show it in my frontend app 10 charges at a time, then next 10 charges on page 2 and so on
I understand what you want to achieve, what I don't understand is why you use auto pagination (which will return all records) if you just want to display x items per page?
So what you are saying is I should implement the pagination from my side rather depending on stripe pagination?
Yes you are right
Ok I got it, but is there any way to reduce the response time?
Have you tested without auto pagination?
Yupp, to list all the charges it takes around 15 seconds, which is quite a time
It may increase in future when the number of brokers in my app increase
I mean have you removed the auto pagination so that it won't list all charges?
Yes, this was the previous code-
// Fetch transactions for the current broker
const brokerAllTransactions = await stripeInstance.charges.list({
customer: broker.stripe_customer_id,
limit: 100,
});
// Extract only the required fields from each transaction
const requiredBrokerTransactions = brokerAllTransactions.data.map(transaction => ({
date: transaction.created,
amount: transaction.amount / 100,
status: transaction.status,
}));
// Filter broker transactions based on status
const filteredBrokerTransactions = status ?
requiredBrokerTransactions.filter(transaction => transaction.status === status) :
requiredBrokerTransactions;
// Add the transactions of the current broker to the aggregated list
brokerTransactions.push(...filteredBrokerTransactions);
Where I list 100 transactions of a single broker
Not really, I want to show first 10 on page 1, next 10 on page 2 and so on
Is there any way to achieve this?
sure, change the limit to 10
also set start_after (https://stripe.com/docs/api/charges/list#list_charges-starting_after ) to the last item of the prevoius list.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Ok let me check and try this and get back to you
Hi Jack, now it takes double the time
Yes but did it give you 10 records at a time?