How to get a customer ID from event object in stripe

可紊 提交于 2019-12-11 04:42:47

问题


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

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