如何在Stripe Invoice中获取此Json值?

时间:2013-02-01 04:07:12

标签: php json parsing stripe-payments

我能够很好地检索前4个值,但是$item_name正在逃避我。我用来检索计划的语法有什么问题:名称:“LITE”值

这是我的php - 前4个返回正常但$ item_name返回无效。

    $customer = $event_json->data->object->customer;
    $amount = $event_json->data->object->total;
    $period_end = $event_json->data->object->period_end;
    $paid = $event_json->data->object->paid;
    $item_name = $event_json->data->object->lines->data->plan->name;

这就是Stripe发送的内容

{
  "id": "evt_1CTCF3tibBeC2y",
  "created": 1359565368,
  "livemode": false,
  "type": "invoice.payment_succeeded",
  "data": {
    "object": {
      "period_end": 1359565367,
      "charge": "ch_1CTCMvOgHE1Q9K",
      "discount": null,
      "period_start": 1359565367,
      "livemode": false,
      "customer": "cus_1CTCYQNoghibwb",
      "amount_due": 7500,
      "lines": {
        "count": 1,
        "object": "list",
        "url": "/v1/invoices/in_1CTCCBbENUpsE6/lines",
        "data": [
          {
            "type": "subscription",
            "livemode": false,
            "period": {
              "end": 1391101367,
              "start": 1359565367
            },
            "object": "line_item",
            "proration": false,
            "plan": {
              "trial_period_days": null,
              "livemode": false,
              "interval": "year",
              "object": "plan",
              "name": "LITE",
              "amount": 7500,
              "currency": "usd",
              "id": "LITE",
              "interval_count": 1
            },

1 个答案:

答案 0 :(得分:6)

数据是一个数组:

$item_name = $event_json->data->object->lines->data[0]->plan->name;

右?