问题
In my application, when a user signs up, a customer is created in stripe. A subscription is also created for that customer on trial basis. When that trial period ends, the customer is charged. I have a web-hook for events happening in stripe so whenever charge.succeeded occurs, I make some changes in my database. I need to retrieve the customer id form the event object that is posted from the stripe. and I am doing it like this:
$stripeCustomerId = $event->customer;
Now when I checked in stripe dashboard, everything is fine, customer status is changed from trialing to active, and the web-hook returns the object fine. But I am unable to get customer id from that object. What am I missing here? Any help?
回答1:
If you have a look at the response object that stripe posts, it has event->data->object->customer hierarchy. so you can get the customer Id like this:
$body = @file_get_contents('php://input');
$event_json = json_decode($body);
$event_json->data->object->customer;
cheers!
来源:https://stackoverflow.com/questions/43038150/how-to-get-a-customer-id-from-event-object-in-stripe