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

时间:2017-05-07 23:06:39

标签: php stripe-payments

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

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

$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: 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

0 个答案:

没有答案