0

I am trying to access a value in my JSON Array. This is my PHP code to get the JSON content:

$input = @file_get_contents("php://input");
$event_json = json_decode($input);
$event = \Stripe\Event::retrieve($event_id);

This is the output:

Stripe\Event JSON: {
"id": "evt_6WV8LzHBPwRYW4",
"created": 1435683755,
"livemode": false,
"type": "charge.succeeded",
"data": {
"object": {
"id": "ch_6WV8a3Sdj3ihE2",
"object": "charge",
"created": 1435683755,
"livemode": false,
"paid": true,
"status": "succeeded",
"amount": 5000,
"currency": "usd",
"refunded": false,
"source": {
"id": "card_6WV8kV4c36X1Gl",
"object": "card",
"last4": "4242",
"brand": "Visa",
"funding": "credit",
"exp_month": 2,
"exp_year": 2022,
"fingerprint": "QXn7Az3ZTTaLBbhx",
"country": "US",
"name": "[email protected]",
"address_line1": null,
"address_line2": null,
"address_city": null,
"address_state": null,
"address_zip": null,
"address_country": null,
"cvc_check": "pass",
"address_line1_check": null,
"address_zip_check": null,
"tokenization_method": null,
"dynamic_last4": null,
"metadata": [],
"customer": "cus_6WV87uyazq5L64"
},
"captured": true,
"balance_transaction": "txn_6WV8Bz6aZSB3tb",
"failure_message": null,
"failure_code": null,
"amount_refunded": 0,
"customer": "cus_6WV87uyazq5L64",
"invoice": null,
"description": null,
"dispute": null,
"metadata": {
"product": "deposit"
},
"statement_descriptor": null,
"fraud_details": [],
"receipt_email": null,
"receipt_number": null,
"shipping": null,
"destination": null,
"application_fee": null,
"refunds": {
"object": "list",
"total_count": 0,
"has_more": false,
"url": "\/v1\/charges\/ch_6WV8a3Sdj3ihE2\/refunds",
"data": []
}
}
},
"object": "event",
"pending_webhooks": 1,
"request": "iar_6WV8y99x1gReuF",
"api_version": "2015-06-15"
}

To be specific, I wish to access the data->metadata->product value - which in this example is "deposit"

This is how I am trying to access it:

$event->data->metadata->product; 

Although that returns blank.

What am I doing wrong?

2
  • There is an object property under data: $event->data->object->metadata->product. Do a print_r() on $event to see the structure. Commented Jun 30, 2015 at 17:10
  • @AbraCadaver Don't know how I could miss that. That's the solution. Do you mind submitting it as an answer? Commented Jun 30, 2015 at 17:11

1 Answer 1

1

There is an object property under data. Do a print_r() on $event to see the structure.

Use: $event->data->object->metadata->product

You can see in the print_r():

stdClass Object
(
    [id] => evt_6WV8LzHBPwRYW4
    .....
    [data] => stdClass Object
        (
            [object] => stdClass Object
                (
                    .....
                    [metadata] => stdClass Object
                        (
                            [product] => deposit
                        )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.