Forums

Using JSON data in form

szabob 22 May, 2019
Hi Everyone,

I am using CF5. I have the following data in JSON. How can I access the "amount" value in line 21 from a form ?
szabob 22 May, 2019
{
"created": 000000000,
"livemode": false,
"id": "evt_00000000000000",
"type": "checkout.session.completed",
"object": "event",
"request": null,
"pending_webhooks": 1,
"api_version": "2019-03-14",
"data": {
"object": {
"id": "cs_00000000000000",
"object": "checkout.session",
"billing_address_collection": null,
"cancel_url": "https://example.com/cancel",
"client_reference_id": null,
"customer": null,
"customer_email": null,
"display_items": [
{
"amount": 1500,
"currency": "usd",
"custom": {
"description": "Comfortable cotton t-shirt",
"images": null,
"name": "T-shirt"
},
"quantity": 2,
"type": "custom"
}
],
"livemode": false,
"locale": null,
"payment_intent": "pi_00000000000000",
"payment_method_types": [
"card"
],
"subscription": null,
"success_url": "https://example.com/success"
}
}
}
szabob 23 May, 2019
Any clue? I am trying the following code but it does not work:
$event->data->object->display_items["amount"];
healyhatman 23 May, 2019
Need to use json_decode on display_items first
szabob 24 May, 2019
Answer
Thanks, I figured it out. This worked:
$event->data->object["display_items"][0]["amount"]
This topic is locked and no more replies can be posted.