#lyubo_api

1 messages · Page 1 of 1 (latest)

bold heronBOT
#

👋 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.

neon lion
#

Hi there!

minor roost
neon lion
#

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.

minor roost
neon lion
#

Is this better for performing large data like 300 sales like I mentioned before?

#

I mean is this method autoPagingIterator() optimised or something?

minor roost
#

Do you have an Stripe Charge ID (ch_123) or Payment Intent ID (pi_123) linked to the order in your system?

neon lion
#

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

minor roost
#

Depending on which integration type you used, you can listen to its respective events for the updates

neon lion
#

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

minor roost
#

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.

neon lion
#

"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

minor roost
#

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

neon lion
#

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' ?

minor roost
#

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

neon lion
minor roost
#

When autoPagingIterator() is used, while loop against $hasMore is not necessary

neon lion
#

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?

minor roost
#

Yes, that's right!

neon lion
#

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

minor roost
#

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

neon lion
#

Thanks for everything, I think I'll try to handle it from here 🙂