本文介绍了如何从条带中的事件对象获取客户 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,当用户注册时,会在 stripe 中创建一个客户.还会以试用方式为该客户创建订阅.当该试用期结束时,向客户收费.我有一个 web-hook 用于在条带中发生的事件,所以每当 charge.succeeded 发生时,我都会对我的数据库进行一些更改.我需要从条带中 posted 的事件对象中检索客户 ID.我是这样做的:

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;

现在,当我检查 Stripe 仪表板时,一切正常,客户状态从试用更改为活动状态,并且网络钩子很好地返回了对象.但我无法从该对象获取客户 ID.我在这里缺少什么?有什么帮助吗?

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?

推荐答案

如果你看看 stripe 发布的响应对象,它有 event->data->object->customer层次结构.所以你可以得到这样的客户 ID:

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;

干杯!

这篇关于如何从条带中的事件对象获取客户 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 01:15