Creating a Stripe Summary Report

我是研究僧i 提交于 2019-12-09 16:14:02

问题


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:

  • Transaction Count
  • Transaction Amount
  • Refund Count
  • Refund Amount
  • Fees
  • Net

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?


回答1:


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.




回答2:


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.




回答3:


I received confirmation from a Stripe employee that the only two options are in fact the ones described in the answers from @dwhalen and @Saikat Chakrabarti.

Quoting from the Stripe employee to the same question I asked on Stripe:

Other than the options you described (retrieving all charges, or tracking in your database as charges come in) there isn't any alternative way of producing the stats that you want there.




回答4:


Realize this is old-ish, but.. this is now possible, a php example:

$charges=Stripe_Charge::all(array("created" => array("gt" => $unix_time),"limit" => 100));



回答5:


You can use offset like

$return = Stripe_Charge::all(array("count" => 100, 'offset' => 0)); // set count
$return = Stripe_Charge::all(array("count" => 100, 'offset' => 100));   // set count
$return = Stripe_Charge::all(array("count" => 100, 'offset' => 200));   // set count


来源:https://stackoverflow.com/questions/13182874/creating-a-stripe-summary-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!