如何从条带事件获取客户 ID



我已经设置了一个网络钩子来处理从条纹发送的事件。但是,我注意到并非所有事件都具有相同的结构。

我目前正在以这种方式检索客户:

$input = @file_get_contents("php://input");
$event_json = json_decode($input);
$customerId = $event_json->data->object->customer

一两天后,我发现并非所有事件都包含客户$event_json->data->object->customer。下面是一个示例响应:

{
"object": {
"id": "cus_Ac3Sx3Bn7cuvqB",
"object": "customer",
"account_balance": -3099,
"created": 1494163341,
"currency": "usd",
"default_source": "card_1AGpL4ByNDe65wcFOfqQZGCc",
"delinquent": false,
"description": "John John",
"discount": null,
"email": "john.john@john.com",
"livemode": false,
"metadata": {
},
"shipping": null,
"sources": {
"object": "list",
"data": [
{
"id": "card_1AGpL4ByNDe65wcFOfqQZGCc",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_Ac3Sx3Bn7cuvqB",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 7,
"exp_year": 2017,
"fingerprint": "lI2tl3FOGKOG7PcZ",
"funding": "credit",
"last4": "4242",
"metadata": {
},
"name": "John John",
"tokenization_method": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_Ac3Sx3Bn7cuvqB/sources"
},
"subscriptions": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_Ac3Sx3Bn7cuvqB/subscriptions"
}
}
}

我要问的是在哪里可以看到所有可能的事件结构的示例,以便我可以确保我的 webhook 不会返回Could not determine which URL to request: StripeCustomer instance has invalid ID: (500 Internal Server Error)?

注意:我确实看到了这个问题 - 如何从条纹中的事件对象获取客户 ID,但唯一给出的方法是$event_json->data->object->customer

条带 Webhook 与相关对象的 API 端点共享相同的结构。 在上面的示例中,object字段设置为customer,因此您可以在 https://stripe.com/docs/api#customer_object 的 API 文档中看到结构。 如果您转到 https://dashboard.stripe.com/account/webhooks 并添加端点,然后选择"选择要发送的类型",则可以看到将发送给您的所有类型的 Webhook。

在很多事件中,查找事件customer并没有真正的意义,因此仅订阅所需的事件类型可能会很有用。

最新更新