How to get a customer ID from event object in stri

2019-07-27 06:02发布

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条回答
smile是对你的礼貌
2楼-- · 2019-07-27 07:03

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!

查看更多
登录 后发表回答