php – list all Stripe events for a customer-ThrowExceptions

Exception or error:

I have WordPress connected to Stripe and would like to show a Stripe event history for each user in their WordPress admin User page. Essentially, I would like the same view that is available inside the Stripe admin when selecting a customer and clicking: “View more events” which results here:**********

I cannot find a way to solve this anywhere in the Stripe API docs, so I’m currently attempting to get ALL events, then return any event that belongs to the current customer. This seems unnecessarily complicated, so I’m hoping there is a better way. Thanks for the help.


$stripe_customer = \Stripe\Customer::retrieve($stripe_customer_id);
$all_stripe_events = \Stripe\Event::all(['limit' => 10000]);

$event_data = $all_stripe_events->data;

foreach($event_data as $event) {
... compare every event against the current customer ...
How to solve:

This isn’t documented in the API docs, but you should be able to pass the same related_object param when retrieving the events that the Stripe dashboard uses.

I don’t know PHP, but this works from the Ruby client:

Stripe::Event.list(related_object: "cus_SOMEUNIQUEID", limit: 10000)

So I’d expect something like this to work, if this happens to be valid PHP syntax:

\Stripe\Event::all(['related_object' => 'cus_SOMEUNIQUEID', 'limit' => 10000]);

Leave a Reply

Your email address will not be published. Required fields are marked *