我已經設置了一個webhook,其中處理從條紋發送的事件。然而,我注意到,並非所有事件都具有相同的結構。如何從條紋事件中獲取客戶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": "[email protected]",
"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"
}
}
}
我所問的是,我可以看到所有可能的事件結構的一個例子,這樣我可以確保我的網絡掛接不返回Could not determine which URL to request: Stripe\Customer instance has invalid ID: (500 Internal Server Error)?
注:我做看到這個問題 - How to get a customer ID from event object in stripe,但唯一給出的方法是$event_json->data->object->customer
它是'$ event_json-> object-> sources-> data [0] - > customer' – Farkie
在這個特定的例子中 - 是的。但它並不包括所有的事件類型。 –