How to get status value string from razorpay array - php

Razorpay\Api\Payment Object ( [attributes:protected] => Array ( [id] => pay_IOx1H64JMSEFAv [entity] => payment [amount] => 100 [currency] => INR [status] => captured [order_id] => order_IOx0xic60K6TZi [invoice_id] => [international] => [method] => wallet [amount_refunded] => 0 [refund_status] => [captured] => 1 [description] => [card_id] => [bank] => [wallet] => payzapp [vpa] => [email] => sudiptobain8#gmail.com [contact] => +919134322935 [notes] => Razorpay\Api\Payment Object ( [attributes:protected] => Array ( [shopping_order_id] => 3456 ) ) [fee] => 2 [tax] => 0 [error_code] => [error_description] => [error_source] => [error_step] => [error_reason] => [acquirer_data] => Razorpay\Api\Payment Object ( [attributes:protected] => Array ( [transaction_id] => ) ) [created_at] => 1637649968 ) )
help to get [status] => captured From This in php

You need to capture objects using object (arrow) notation
<?php
echo $result->status;
?>

Related

How to get values from array object in PHP

I have the following array and when I do print("<pre>".print_r($term_arr,true)."</pre>");, I get:
Array
(
[0] => Array
(
[status] => 1
[message] => Charge attempted
[data] => Array
(
[amount] => 1000000
[currency] => NGN
[transaction_date] => 2021-05-04T03:18:03.000Z
[status] => success
[reference] => tbhlnqs9elbcoth
[domain] => test
[metadata] =>
[gateway_response] => Approved
[message] =>
[channel] => card
[ip_address] =>
[log] =>
[fees] => 25000
[authorization] => Array
(
[authorization_code] => AUTH_z260f8cskt
[bin] => 408408
[last4] => 4081
[exp_month] => 12
[exp_year] => 2030
[channel] => card
[card_type] => visa
[bank] => TEST BANK
[country_code] => NG
[brand] => visa
[reusable] => 1
[signature] => SIG_TyzxLul2N9M3RSX5MJIY
[account_name] =>
)
[customer] => Array
(
[id] => 43591782
[first_name] =>
[last_name] =>
[email] => ele48#gmail.com
[customer_code] => CUS_rs2vvoeo7pe6f1b
[phone] =>
[metadata] =>
[risk_action] => default
[international_format_phone] =>
)
[plan] =>
[id] => 1112036335
)
)
[1] => Array
(
[status] => 1
[message] => Charge attempted
[data] => Array
(
[amount] => 100000
[currency] => NGN
[transaction_date] => 2021-05-04T03:18:03.000Z
[status] => success
[reference] => fxi85hsbg2u8jwi
[domain] => test
[metadata] =>
[gateway_response] => Approved
[message] =>
[channel] => card
[ip_address] =>
[log] =>
[fees] => 1500
[authorization] => Array
(
[authorization_code] => AUTH_bn008ru8rq
[bin] => 408408
[last4] => 4081
[exp_month] => 12
[exp_year] => 2030
[channel] => card
[card_type] => visa
[bank] => TEST BANK
[country_code] => NG
[brand] => visa
[reusable] => 1
[signature] => SIG_TyzxLul2N9M3RSX5MJIY
[account_name] =>
)
[customer] => Array
(
[id] => 43746063
[first_name] =>
[last_name] =>
[email] => gabwebby#gmail.com
[customer_code] => CUS_d4r1mko8twyc6vg
[phone] =>
[metadata] =>
[risk_action] => default
[international_format_phone] =>
)
[plan] =>
[id] => 1112036343
)
)
I am trying to get the value of customer, so I did the following:
foreach($term_arr as $value){
echo 'Title: ' . $value->customer->customer_code .'<br/>';
}
But I have this error:
PHP Notice: Trying to get property 'customer' of non-object in PHP
Notice: Trying to get property 'customer_code' of non-object in
How can I get the values of array object?
Firstly your inner array is associatve array so if we want values to get we need to traverse using key.
Solution you tried to get customer code where hierarchy is not proper
When you iterate over you parent index array hierarchy is data->customer->customer code
so your customer resides under data array thats why you are getting notice that customer is non object of value.
So solution or you can iterate like will give you customer code,
foreach($term_arr as $value){
print_r($value["data"]["customer"]["customer_code"]."\n");
}

Getting just one value from an array (php) [duplicate]

This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
Closed 3 years ago.
When I print print_r($event_json); it gives me the array below. I need to get just one value from it [type] as in [type] => charge.succeeded (see the top of the array). I tried echo $event_json[0]['type']; but I am getting nothing.
stdClass Object
(
[created] => 1326853478
[livemode] =>
[id] => charge.succeeded_00000000000000
[type] => charge.succeeded
[object] => event
[request] =>
[pending_webhooks] => 1
[api_version] => 2018-10-31
[data] => stdClass Object
(
[object] => stdClass Object
(
[id] => ch_00000000000000
[object] => charge
[amount] => 500
[amount_refunded] => 0
[application] =>
[application_fee] =>
[application_fee_amount] =>
[balance_transaction] => txn_00000000000000
[billing_details] => stdClass Object
(
[address] => stdClass Object
(
[city] =>
[country] =>
[line1] =>
[line2] =>
[postal_code] =>
[state] =>
)
[email] =>
[name] => someemail#yahoo.com
[phone] =>
)
[captured] =>
[created] => 1553691107
[currency] => usd
[customer] => cus_00000000000000
[description] =>
[destination] =>
[dispute] =>
[failure_code] => card_declined
[failure_message] => Your card was declined.
[fraud_details] => stdClass Object
(
[stripe_report] => fraudulent
)
[invoice] =>
[livemode] =>
[metadata] => stdClass Object
(
)
[on_behalf_of] =>
[order] =>
[outcome] => stdClass Object
(
[network_status] => not_sent_to_network
[reason] => merchant_blacklist
[risk_level] => highest
[risk_score] => 98
[seller_message] => Stripe blocked this payment.
[type] => blocked
)
[paid] => 1
[payment_intent] =>
[payment_method_details] => stdClass Object
(
[card] => stdClass Object
(
[brand] => visa
[checks] => stdClass Object
(
[address_line1_check] =>
[address_postal_code_check] =>
[cvc_check] => unavailable
)
[country] => US
[exp_month] => 1
[exp_year] => 2022
[fingerprint] => Gawa768Trrk4fEmb
[funding] => credit
[last4] => 0019
[three_d_secure] =>
[wallet] =>
)
[type] => card
)
[receipt_email] =>
[receipt_number] =>
[receipt_url] => https://pay.stripe.com/receipts/acct_1DU4J1IcP22cq9aQ/ch_1EIbENIcP22cq9aQk7r9xN3u/rcpt_Em9Xy3Ambv1b8QZISOsIHdbxCnLdgup
[refunded] =>
[refunds] => stdClass Object
(
[object] => list
[data] => Array
(
)
[has_more] =>
[total_count] => 0
[url] => /v1/charges/ch_1EIbENIcP22cq9aQk7r9xN3u/refunds
)
[review] =>
[shipping] =>
[source] => stdClass Object
(
[id] => card_00000000000000
[object] => card
[address_city] =>
[address_country] =>
[address_line1] =>
[address_line1_check] =>
[address_line2] =>
[address_state] =>
[address_zip] =>
[address_zip_check] =>
[brand] => Visa
[country] => US
[customer] => cus_00000000000000
[cvc_check] => unavailable
[dynamic_last4] =>
[exp_month] => 1
[exp_year] => 2022
[fingerprint] => Gawa768Trrk4fEmb
[funding] => credit
[last4] => 0019
[metadata] => stdClass Object
(
)
[name] => someemail#yahoo.com
[tokenization_method] =>
)
[source_transfer] =>
[statement_descriptor] =>
[status] => failed
[transfer_data] =>
[transfer_group] =>
)
)
)
What you are seeing is an stdClass Object and not an array. Do like below:
<?php
echo $event_json->type;

How to retrieve object from xml

I am trying to get the value of bank_name in php. Can't get it to display.
stdClass Object ( [account_id] => 43726384 [name] => Account Name [state] => action_required [description] => [owner_user_id] =>[type] => personal [create_time] => 1477684534 [disablement_time] => [country] => US [currencies] => Array ( [0] => USD ) [action_reasons] => Array ( [0] => kyc [1] => bank_account ) [disabled_reasons] => Array ( ) [image_uri] => [supported_card_types] => Array ( [0] => visa [1] => mastercard [2] => american_express [3] => discover [4] => jcb [5] => diners_club ) [gaq_domains] => Array ( [0] => ) [balances] => Array ( [0] => stdClass Object ( [balance] => 0 [currency] => USD [disputed_amount] => 0 [incoming_pending_amount] => 0 [outgoing_pending_amount] => 0 [reserved_amount] => 0 [bank_name] => Bank Of America [withdrawal_next_time] => [withdrawal_period] => [withdrawal_type] => ) ) [statuses] => Array ( [0] => stdClass Object ( [currency] => USD [incoming_payments_status] => ok [outgoing_payments_status] => paused [account_review_status] => not_requested ) ) )
It's not very clear if you display data that way, but I think this would be the way to access to bank_name:
$bankName = $object->balances[0]->bank_name;
(If it doesn't work, please show the XML before parsing it to an object)

PHP5.3 json_encode is outputting bad json

I am attempting to json_encode an array in php5.3.
json_encode($paperwork_info[0])
The result is bad json. The array is as follows:
[paperwork_guid] => c5bfe512-908d-c513-5a5e-e3a2fbb5548b
[name] => recycle
[sections] => Array
(
[0] => header
[1] => customer
[2] => scope_bullets
[3] => product
[4] => signature
[5] => installer
[6] => order_data
)
[data] => Array
(
[header] => Array
(
[image] => Array
(
[src] => recycle.png
[format] => float:left
)
)
[customer] => Array
(
[f_name] => TEST ONLY
[l_name] => NEIMEIER
[middle_name] => none
[title] => none
[address1] => 28 OEHMAN BLVD
[address2] =>
[address3] =>
[zip] => 14225
[city] => BUFFALO
[state_abbrev] => NY
[email_address] => DALE.NEIMEIER#INSTALLS.COM
[phones] => Array
(
[alt] =>
[cell] =>
[work] =>
[home] => 7165551212
)
)
[scope_bullets] => Array
(
[sku_3001] => Array
(
[bullet_0] => Array
(
[paperwork_bullet_obj_guid] => 2ebefa96-6f6b-069e-e194-245d138b9845
[ordering] => 1
[bullet_text] => This is bullet point #1
[child_level] => 1
[formatting] => Array
(
[0] => Array
(
[start_word] => 2
[num_words] => 0
[tag] => b
[href] =>
)
[1] => Array
(
[start_word] => 2
[num_words] => 1
[tag] => a
[href] => http://www.cnn.com
)
)
)
[bullet_1] => Array
(
[paperwork_bullet_obj_guid] => 734db3f4-01a0-b025-9624-cc52a1845dff
[ordering] => 1
[bullet_text] => Sub-point #1.1
[child_level] => 2
)
[bullet_2] => Array
(
[paperwork_bullet_obj_guid] => ebf5ef02-906e-2005-e499-27eae2edefe9
[ordering] => 1
[bullet_text] => Sub point #1.1.1
[child_level] => 3
)
[bullet_3] => Array
(
[paperwork_bullet_obj_guid] => 447997c1-fd9c-25be-b9bf-39257009fb8b
[ordering] => 1
[bullet_text] => This is bullet point #2
[child_level] => 1
)
[bullet_4] => Array
(
[paperwork_bullet_obj_guid] => 5def2d9c-d322-788c-0afe-d13707004b97
[ordering] => 1
[bullet_text] => Sub point #2.1
[child_level] => 2
)
[bullet_5] => Array
(
[paperwork_bullet_obj_guid] => 84936151-65a3-bcca-951f-b69ff16d34ec
[ordering] => 2
[bullet_text] => Sub point #2.2
[child_level] => 2
)
)
[sku_4405] =>
)
[product] => Array
(
[0] => Array
(
[model] => Paperwork Test abc123
[serial] => 777333
[weight] => 26
[size] =>
[width] =>
[height] => 32
[num_boxes] => 1
[product_name] =>
[sku] =>
[model_number] =>
[part_number] =>
[serial_number] =>
[cat_value] => Best Buy Equipment
[product] =>
[product_type] =>
[product_size] =>
[category] =>
)
)
[signature] => Array
(
[date] => 2016-06-15
[need_customer] => 1
[need_tech] => 1
[need_store] =>
[need_warehouse] =>
)
[installer] => Array
(
[anum] => 45455
[inst_obj_guid] => fb91cf85-381c-b740-e063-775151743da2
[phone] => (317) 519-0481
[tech_f_name] =>
[tech_l_name] =>
[company_name] => ZICO LLC
[email_address] => ZICOLLC#GMAIL.COM
)
[order_data] => Array
(
[assigned_date] => 2016-06-07 22:24:47-04
[purchased_date] => 2016-06-06
[creation_date] => 2016-06-06
[install_date] => 2016-06-10
[install_time] => 19:00:00
[prescheduled_date] => 1969-12-31
[prom_start_time] => 2016-06-10 08:06:00
[prom_end_time] => 2016-06-10 11:06:00
[client_order_id] => 12365478996325412
[job_num] => 4043269
[campaign_wkord_obj_guid] => a9a8cc0b-d7ef-ac0e-df61-dad41c023cb0
[pos_obj_guid] => 096e38c2-55c3-80cf-0778-23f81f1cf2f6
[inst_obj_guid] => fb91cf85-381c-b740-e063-775151743da2
[client_obj_guid] => 247e893a-3ea4-c544-47b2-f23ff16017c6
[ord_obj_guid] => ae55e034-d7d0-5d13-3dd3-22f99df8ead4
[skus] => Array
(
[0] => Array
(
[job_type_obj_guid] => 8234ca2c-e40e-c48c-befc-7ceac5e9de32
[job_sku] => 3001
[client_sku] =>
[sku_name] => Site Survey
)
[1] => Array
(
[job_type_obj_guid] => a3f60c3b-ad3c-d828-9898-fa200edcd3cd
[job_sku] => 4405
[client_sku] =>
[sku_name] => Home Delivery
)
)
[client_specific_data] =>
)
)
)
The resultant json string is as follows:
{"paperwork_guid":"c5bfe512-908d-c513-5a5e-e3a2fbb5548b","name":"recycle","sections":{"0":"header","1"
:"customer","2":"scope_bullets","3":"product","4":"signature","5":"installer","6":"order_data"},"data"
:{"header":{"image":{"src":"recycle.png","format":"float:left"}},"customer":{"f_name":"TEST ONLY","l_name"
:"NEIMEIER","middle_name":"none","title":"none","address1":"28 OEHMAN BLVD","address2":"","address3"
:null,"zip":"14225","city":"BUFFALO","state_abbrev":"NY","email_address":"DALE.NEIMEIER#INSTALLS.COM"
,"phones":{"alt":"","cell":"","work":"","home":"7165551212"}},"scope_bullets":{"sku_3001":{"bullet_0"
:{"paperwork_bullet_obj_guid":"2ebefa96-6f6b-069e-e194-245d138b9845","ordering":"1","bullet_text":"This
is bullet point #1","child_level":"1","formatting":{"0":{"start_word":"2","num_words":"0","tag":"b"
,"href":""},"1":{"start_word":"2","num_words":"1","tag":"a","href":"http:\/\/www.cnn.com"}}},"bullet_1"
:{"paperwork_bullet_obj_guid":"734db3f4-01a0-b025-9624-cc52a1845dff","ordering":"1","bullet_text":"Sub-point
#1.1","child_level":"2"},"bullet_2":{"paperwork_bullet_obj_guid":"ebf5ef02-906e-2005-e499-27eae2edefe9"
,"ordering":"1","bullet_text":"Sub point #1.1.1","child_level":"3"},"bullet_3":{"paperwork_bullet_obj_guid"
:"447997c1-fd9c-25be-b9bf-39257009fb8b","ordering":"1","bullet_text":"This is bullet point #2","child_level"
:"1"},"bullet_4":{"paperwork_bullet_obj_guid":"5def2d9c-d322-788c-0afe-d13707004b97","ordering":"1","bullet_text"
:"Sub point #2.1","child_level":"2"},"bullet_5":{"paperwork_bullet_obj_guid":"84936151-65a3-bcca-951f-b69ff16d34ec"
,"ordering":"2","bullet_text":"Sub point #2.2","child_level":"2"}},"sku_4405":null},"product":{"0":{"model"
:"Paperwork Test abc123","serial":"777333","weight":"26","size":null,"width":null,"height":"32","num_boxes"
:"1","product_name":null,"sku":null,"model_number":null,"part_number":null,"serial_number":null,"cat_value"
:"Best Buy Equipment","product":null,"product_type":null,"product_size":null,"category":null}},"signature"
:{"date":"2016-06-15","need_customer":true,"need_tech":true,"need_store":false,"need_warehouse":false
},"installer":{"anum":"45455","inst_obj_guid":"fb91cf85-381c-b740-e063-775151743da2","phone":"(317) 519-0481"
,"tech_f_name":null,"tech_l_name":null,"company_name":"ZICO LLC","email_address":"ZICOLLC#GMAIL.COM"
},"order_data":{"assigned_date":"2016-06-07 22:24:47-04","purchased_date":"2016-06-06","creation_date"
:"2016-06-06","install_date":"2016-06-10","install_time":"19:00:00","prescheduled_date":"1969-12-31"
,"prom_start_time":"2016-06-10 08:06:00","prom_end_time":"2016-06-10 11:06:00","client_order_id":"12365478996325412"
,"job_num":"4043269","campaign_wkord_obj_guid":"a9a8cc0b-d7ef-ac0e-df61-dad41c023cb0","pos_obj_guid"
:"096e38c2-55c3-80cf-0778-23f81f1cf2f6","inst_obj_guid":"fb91cf85-381c-b740-e063-775151743da2","client_obj_guid"
:"247e893a-3ea4-c544-47b2-f23ff16017c6","ord_obj_guid":"ae55e034-d7d0-5d13-3dd3-22f99df8ead4","skus"
:{"0":{"job_type_obj_guid":"8234ca2c-e40e-c48c-befc-7ceac5e9de32","job_sku":"3001","client_sku":null
,"sku_name":"Site Survey"},"1":{"job_type_obj_guid":"a3f60c3b-ad3c-d828-9898-fa200edcd3cd","job_sku"
:"4405","client_sku":null,"sku_name":"Home Delivery"}},"client_specific_data":""}}}
It appears as though new line feeds are being inserted randomly throughout the josn string. I am not sure if it is just how firebug is outputting the string, but copying-and-pasting the string into jsonLINT produces errors.
Any help would be appreciated.

Store a variable from the array of object php

I have a php variabl $purchase_data which when I did
print_r('purchase_data');
I got the output as
Array
(
[downloads] => Array
(
[0] => Array
(
[id] => 28
[options] => Array
(
)
[quantity] => 1
)
)
[fees] => Array
(
)
[subtotal] => 1
[discount] => 0
[tax] => 0
[price] => 1
[purchase_key] => a8d14e34ba425f9de6afe3ad4809587e
[user_email] => esh#test.com
[date] => 2014-05-11 20:07:22
[user_info] => Array
(
[id] => 1
[email] => eshtest.com
[first_name] => esh
[last_name] =>
[discount] => none
[address] =>
)
[post_data] => Array
(
[edd_email] => esh#test.com
[edd_first] => esh
[edd_last] =>
[edd_phone] => 919995871693
[edd-user-id] => 1
[edd_action] => purchase
[edd-gateway] => sample_gateway
)
[cart_details] => Array
(
[0] => Array
(
[name] => Shirt
[id] => 28
[item_number] => Array
(
[id] => 28
[options] => Array
(
)
[quantity] => 1
)
[item_price] => 1
[quantity] => 1
[discount] => 0
[subtotal] => 1
[tax] => 0
[price] => 1
)
)
[gateway] => sample_gateway
[card_info] => Array
(
[card_name] =>
[card_number] =>
[card_cvc] =>
[card_exp_month] =>
[card_exp_year] =>
[card_address] =>
[card_address_2] =>
[card_city] =>
[card_state] =>
[card_country] =>
[card_zip] =>
)
)
How can i store the value to edd_phone [edd_phone] into variable $mobileNo ?
Sorry for ths kind of a question.But badly need help
If you want to assign the value of [edd_phone] to $mobileNo , use this :
$mobileNo = $purchase_data['post_data']['edd_phone'];
As a side note : Your array is very complexly nested. If I were you, I would avoid such complex arrays.

Categories