#lyubo_api
1 messages · Page 1 of 1 (latest)
👋 Welcome to your new thread!
⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1415828735390777355
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi there!
I recommended using the auto pagination provided by stripe-php library to iterate through the list: https://docs.stripe.com/pagination?lang=php#auto-pagination
Just a reminder - charge list will also contain both successful and failed ones. You'd still need to filter manually yourself
so by using the auto paginator I don't need to do a while loop? Basically it will figure the logic itself? It's not a problem to create my own filter.
Yes, autoPagingIterator will iterate the list itself and handle the pagination automatically.
Alternatively, you can follow the guide here to do manual pagination: https://docs.stripe.com/pagination#manual-pagination
Is this better for performing large data like 300 sales like I mentioned before?
I mean is this method autoPagingIterator() optimised or something?
Do you have an Stripe Charge ID (ch_123) or Payment Intent ID (pi_123) linked to the order in your system?
I need the succesfull charges. Because if somebody creates a payment intent on 5-th of September, then they can pay for it on the 20-th of September. In my XML, it shows that the succesfull date is 5-th (date of creation, not finalization of the payment)
Thats why I am using $transactions = $stripe->charges->all();
I need all the charges made for the month and then filter out the succesfull ones.
Inside these succesfull charges is the data of the user - names, products bought, prices, email, everything I need
You should use Webhook to listen to the events of the Payment Intent instead of retrieving them manually. Stripe will send any update through the event if there is any change to the Payment Intent: https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=elements#web-post-payment
Depending on which integration type you used, you can listen to its respective events for the updates
Ok but I am not sure if you understand what I need exactly, so here's the whole method I have as well as the XML file. #1 method: https://pastebin.com/2e9pc0FC #2 XML file: https://pastebin.com/eY4QdbJh. When the calendar turns 1-st of each month, I need to get all the sales from last month and put them in this XML and download it thats it. So I am retrieving all succesfull charges. The code I have works, I was just wondering if this is optimal, because some clients might have 500 or even 1000 sales a month with stripe. So If I try to download the XML, is it going to break due to the big data? That's my concern
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
I understand you would like to list of the charge data you're looking for using the List Charges API. Both manual and automatic pagination will work for your case. The only difference with auto pagination is that you don't have to manage the cursor yourself.
What I'm proposing another alternative to get the data you're looking for using the Webhook events. You can listen to the changes on the charges and update your database accordingly. Then use it to generate the XML file you need.
If you're going to run the same listing API on multiple clients at the same time, you might hit the rate limit: https://docs.stripe.com/rate-limits
"What I'm proposing another alternative to get the data you're looking for using the Webhook events. You can listen to the changes on the charges and update your database accordingly. Then use it to generate the XML file you need" - I am not using the database at all. I retrieve the charges and download the file thats all. Is there a big difference between retrieving the payment_intents and using the customers like this: $customers = $stripe->customers->all(); foreach ($customers->autoPagingIterator() as $customer) {
}
?
and btw the $stripe->customers->all() retrieves in general all the customers. I do not need all the customers. I need the successfull charges and the details with that successfull charge - names of client, email, amount, products bought.
Therefore I assume there is no point of using autoPagingIterator();, because it doesn't work with charges
autoPagingIterator also works for charge list. The example code is just to show you how to list the customers
autoPagingIterator works for all the List API, including Charges, Payment Intents and Customers
In general, I'd recommend listing Payment Intents / Charges to check the payment outcome and the necessary information. It's also recommended to include created filter to list the data from the last time you retrieved, since the list will only grow longer. If you have retrieved the data before, there shouldn't be a need to do it again
Well, that's why I mentioned that I want to retrieve the data from the previous month specifically.
$startOfLastMonth = strtotime('first day of last month 00:00:00');
$endOfLastMonth = strtotime('last day of last month 23:59:59');
$successfulPayments = [];
$hasMore = true;
$startingAfter = null;
$params = [
'limit' => 100, // no quotes needed
'created' => [
'gte' => $startOfLastMonth,
'lte' => $endOfLastMonth,
],
];
is this a good way to do it with 'gte' and 'lte' ?
This looks fine to me. Just a reminder that Stripe uses UTC / GMT in our system. If you're using a different timezone, you will have to convert the timestamp into UTC
so basically I can add autoPagingIterator() for my method and there is no point to touch the rest of the code from here: https://pastebin.com/2e9pc0FC
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
When autoPagingIterator() is used, while loop against $hasMore is not necessary
FYI - list of charges doesn't mean that the payment is successful. The list can also can contain the failed one.
If you're looking for the successful charges, then status field should be checked: https://docs.stripe.com/api/charges/object?api-version=2025-08-27.basil#charge_object-status
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yup
if ($transaction->status === 'succeeded') {
// Carbon makes this much simpler
$dateTime = Carbon::createFromTimestamp($transaction->created, 'Europe/Sofia');
$transaction->human_date = $dateTime->toDateString(); // e.g. 2025-09-11
$transaction->human_time = $dateTime->toTimeString(); // e.g. 14:35:22
// Since invoices aren’t needed for single products, remove that logic
$transaction->invoice_number = null;
$transaction->payment_interval = null;
$successfulPayments[] = $transaction;
}
I am checking the status here
they need to be on 'succeeded' from what I saw?
Yes, that's right!
btw how many years of experience do you have with PHP lol? Just curious what it takes to become part of Stripe Discord support
I don't have anymore questions work related. Thanks so much for your help
We are mostly full stack across different languages and frameworks, not limited to PHP
Happy to help! Let me know if you have any follow up question
Thanks for everything, I think I'll try to handle it from here 🙂