#subhrajeet99

1 messages · Page 1 of 1 (latest)

swift kelpBOT
hot marsh
#

Yes it's the pagination api and each of our SDK has support for auto pagination

spark sluice
#

I am using Node.js, I am using the has_more parameter to implement pagination but still getting all the charges as results

hot marsh
#

Node would have the autopagination like this


// In other environments:
stripe.customers.list({limit: 3})
  .autoPagingEach(function(customer) {
    // Do something with customer
  });
swift kelpBOT
spark sluice
#

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);
    }
  });
dim hound
#

Hi @spark sluice I'm taking over

spark sluice
#

Hello Jack

dim hound
#

Why are you using auto pagination if you just want to retrieve 10 charges?

spark sluice
#

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

dim hound
#

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?

spark sluice
#

So what you are saying is I should implement the pagination from my side rather depending on stripe pagination?

dim hound
#

Yes you are right

spark sluice
#

Ok I got it, but is there any way to reduce the response time?

dim hound
#

Have you tested without auto pagination?

spark sluice
#

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

dim hound
#

I mean have you removed the auto pagination so that it won't list all charges?

spark sluice
#

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

dim hound
#

Ok, is it slow?

#

And do you really need 100 in one go?

spark sluice
#

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?

dim hound
#

sure, change the limit to 10

spark sluice
#

Ok let me check and try this and get back to you

#

Hi Jack, now it takes double the time

hot marsh
#

Yes but did it give you 10 records at a time?

spark sluice
#

Actually it gave me all the records, may be I cannot figure it out properly, I'll do some R&D

#

Thanks for the help Jack and nice profile picture😁

#

Thanks to you too Orakaro