I've recently switched payment processing to Stripe. I now need to create a report for our finance department that shows a rollup of transactions within a specified date range. I've started to create a simple PHP web page (and using the Stripe PHP library) that will give the following summaries:
I'm having some trouble figuring out how to properly query charges with Stripe for my reporting purposes.
I know I can retrieve charges with:
$charges = Stripe_Charge::all();
And from the returned set of charges, I can compute the summary information that I need in the report. However, this will only return me a maximum of 100 charges, and I don't know how to return the charges within a specified date range.
I'm hoping more experienced Stripe developers can point me to the correct method of building the report I need.
How can I return all charges within a specified date range?
Is there a better way to get this summary information from Stripe?
You could use webhooks to be notified when a charge.succeeded
or charge.refunded
event occurs and store the relevant information in a database you control. That will give you flexibility to do the reporting you need. You can download charges that have already occurred as a CSV from the Stripe dashboard.
You can paginate through the charges by using the count and offset parameters (documented at https://stripe.com/docs/api?lang=php#list_charges). I would suggest using these to process 100 charges at a time. Then you can stop iterating through your charges once you get a charge beyond your date range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With