-3

I am trying to access the amount property in the below json file.

{
  "id": "evt_1EQZxID5bcg",
  "data": {
    "object": {
      "id": "cs_0G452PD7eY8ddrtuyo0KZ5sSRk",
      "display_items": [
        {
          "amount": 300,
          "currency": "gbp",
          "custom": {
            "name": "Purchase"
          },
          "type": "custom"
        }
      ],
      "livemode": false,
      "payment_method_types": [
        "card"
      ],
      "subscription": null,
      "success_url": ""
    }
  },
  "livemode": false,
  "request": {
    "idempotency_key": null
  },
  "type": "checkout.session.completed"
}

I have tried using this code to access the peroperty

$object->data->object->display_items->amount

However, this returns no data.

I am thinking this has to do with the square brackets, but when I try access that alone I get an array.

seventeen
  • 557
  • 1
  • 6
  • 21
  • 3
    `display_items` is an array _containing_ an object, so you need to access the array element first, and then the properties of the object inside it. – 04FS Apr 18 '19 at 13:27
  • If you get in the habit of `print_r($object);` it is clear. – AbraCadaver Apr 18 '19 at 13:42

1 Answers1

1

Try:

$object->data->object->display_items[0]->amount
Andrei Lupuleasa
  • 2,677
  • 3
  • 14
  • 32