Counting array in API JSON Response
Posted
by
bryan
on Stack Overflow
See other posts from Stack Overflow
or by bryan
Published on 2014-06-10T21:08:09Z
Indexed on
2014/06/10
21:24 UTC
Read the original article
Hit count: 204
I'm trying to do a simple count of how many refunds are in my Stripe Response but count()
isn't working and I don't really know any other way of achieving this.
Could anyone point me in the right direction?
$retrieve_event = Stripe_Event::retrieve("evt_00000000000000");
$event_json_id = json_decode($retrieve_event);
$refund_array = $event_json_id->{'data'}->{'object'}->{'refunds'};
die(count($refund_array));
This is the response of $retrieve_event
{
"created": 1326853478,
"livemode": false,
"id": "evt_00000000000000",
"type": "charge.refunded",
"object": "event",
"request": null,
"data": {
"object": {
"id": "ch_00000000000000",
"object": "charge",
"created": 1402433517,
"livemode": false,
"paid": true,
"amount": 1000,
"currency": "usd",
"refunded": true,
"card": {
"id": "card_00000000000000",
"object": "card",
"last4": "0028",
"type": "Visa",
"exp_month": 8,
"exp_year": 2015,
"fingerprint": "a5KWlTcrmCYk5DIYa",
"country": "US",
"name": "First Last",
"address_line1": "null",
"address_line2": null,
"address_city": "null",
"address_state": "null",
"address_zip": "null",
"address_country": "US",
"cvc_check": null,
"address_line1_check": "fail",
"address_zip_check": "pass",
"customer": "cus_00000000000000"
},
"captured": true,
"refunds": [
{
"id": "re_104CKt4uGeYuVLAahMwLA2TK",
"amount": 100,
"currency": "usd",
"created": 1402433533,
"object": "refund",
"charge": "ch_104CKt4uGeYuVLAazSyPqqLV",
"balance_transaction": "txn_104CKt4uGeYuVLAaSNZCR867",
"metadata": {}
},
{
"id": "re_104CKt4uGeYuVLAaDIMHoIos",
"amount": 200,
"currency": "usd",
"created": 1402433539,
"object": "refund",
"charge": "ch_104CKt4uGeYuVLAazSyPqqLV",
"balance_transaction": "txn_104CKt4uGeYuVLAaqSwkNKPO",
"metadata": {}
},
{
"id": "re_4CL6n1r91dY5ME",
"amount": 700,
"currency": "usd",
"created": 1402434306,
"object": "refund",
"charge": "ch_4CL6FNWhGzVuAV",
"balance_transaction": "txn_4CL6qa4vwlVaDJ"
}
],
"balance_transaction": "txn_00000000000000",
"failure_message": null,
"failure_code": null,
"amount_refunded": 1000,
"customer": "cus_00000000000000",
"invoice": null,
"description": "this is a description",
"dispute": null,
"metadata": {},
"statement_description": "this is a description",
"fee": 0
}
}
}
© Stack Overflow or respective owner