Get inner part of Array PHP - php

How do I get inner part of a long array in PHP :
Example:
print_r($array) gives:
Razorpay\Api\Collection Object
(
[attributes:protected] => Array
(
[entity] => collection
[count] => 1
[items] => Array
(
[0] => Razorpay\Api\Payment Object
(
[attributes:protected] => Array
(
[id] => payid
[entity] => payment
[amount] => 1000
[currency] => INR
[status] => captured
[order_id] => orderid
[invoice_id] =>
[international] =>
[method] => card
[amount_refunded] => 0
[refund_status] =>
[captured] => 1
[description] => D.
[card_id] => id
[bank] =>
[wallet] =>
[vpa] =>
[email] => example#example.com
[contact] => +91
[notes] => Razorpay\Api\Payment Object
(
[attributes:protected] => Array
(
[address] => add
[merchant_order_id] => orid
)
)
[fee] => 20
[tax] => 0
[error_code] =>
[error_description] =>
[created_at] => 1580641472
)
)
)
)
)
This is Razorpay Payment details returned.
How do I get id and other innermost items from this array
I want to get id and status and check if status is captured or failed to verify the payment, but, I can't get it anyway. Please help

Finally Got:
$payment = $api->order->fetch($_POST["razorpayorderid"])->payments();
$payid = $payment["items"][0]["id"];

Related

How to get status value string from razorpay array

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;
?>

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");
}

PHP paypal commerce platform(api v2) partner is not getting paid?

Paypal Commerce platform in php order capture partner is not getting paid and seller is getting full amount. What should I send in order capture?
Below is the array I am sending in 'https://api.paypal.com/v2/checkout/orders'
Array
(
[intent] => CAPTURE
[purchase_units] => Array
(
[0] => Array
(
[reference_id] =>
[description] => Darshan Shah 70099
[custom_id] => 10541
[soft_descriptor] =>
[invoice_id] => SELLERINV-70099
[amount] => Array
(
[currency_code] => USD
[value] => 105
[breakdown] => Array
(
[item_total] => Array
(
[currency_code] => USD
[value] => 100
)
[shipping] => Array
(
[currency_code] => USD
[value] => 5
)
[tax_total] => Array
(
[currency_code] => USD
[value] => 0
)
)
)
[items] => Array
(
[0] => Array
(
[name] => Test Product K
[description] => Test Product K
[unit_amount] => Array
(
[currency_code] => USD
[value] => 50
)
[tax] => Array
(
[currency_code] => USD
[value] => 0
)
[quantity] => 2
[category] => DIGITAL_GOODS
)
)
[payee] => Array
(
[merchant_id] =>
)
[shipping] => Array
(
[name] => Array
(
[full_name] => Darshan Shah
)
[address] => Array
(
[address_line_1] => 5/11 G1 Rajalakshmi Enclave
[address_line_2] =>
[admin_area_2] => Middleton Grange
[admin_area_1] => CON
[postal_code] => 111111
[country_code] => GB
)
)
[payment_instruction] => Array
(
[disbursement_mode] => INSTANT
[platform_fees] => Array
(
[0] => Array
(
[amount] => Array
(
[currency_code] => USD
[value] => 5
)
[payee] => Array
(
[merchant_id] =>
)
)
)
)
)
)
[application_context] => Array
(
[brand_name] =>
[locale] => en-US
[landing_page] => BILLING
[shipping_preference] => GET_FROM_FILE
[user_action] => PAY_NOW
[return_url] =>
[cancel_url] =>
)
)
What data should I send in order capture? 'https://api.paypal.com/v2/checkout/orders//capture'. As currently, I am not sending any data in order capture.
I am using above 2 apis to do checkout and pay both seller and parter. But Only seller is getting full amount, partner is not getting anything!
If have hoped on this kind of issue, please suggest me a solution.

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)

How to get specific array values from moltin get a product

I just started using moltin and learn to developing it.
In the getting started there is code that to show product
<?php
$product = \Product::Find(['slug' => 'baju']);
?>
documentation link https://moltin.com/getting-started/php
and the result is when I print array
<?php
print_r($product);
?>
It shows like this
Array ( [status] => 1 [result] => Array ( [0] => Array ( [id] => 1207658536885027482 [order] => [created_at] => 2016-03-17 03:08:58 [updated_at] => 2016-03-17 03:08:58 [sku] => baju-1 [title] => baju [slug] => baju [sale_price] => 0 [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [category] => Array ( [value] => Uncategorized [data] => Array ( [1134518259857490806] => Array ( [id] => 1134518259857490806 [order] => [created_at] => 2015-12-07 05:12:15 [updated_at] => 2015-12-07 05:12:15 [parent] => [slug] => uncategorized [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [title] => Uncategorized [description] => Products that do not fit into another category ) ) ) [stock_level] => 10 [stock_status] => Array ( [value] => In Stock [data] => Array ( [key] => 1 [value] => In Stock ) ) [description] => baju [requires_shipping] => Array ( [value] => Yes [data] => Array ( [key] => 1 [value] => Yes ) ) [weight] => 0 [height] => 0 [width] => 0 [depth] => 0 [catalog_only] => Array ( [value] => No [data] => Array ( [key] => 0 [value] => No ) ) [tax_band] => Array ( [value] => Default [data] => Array ( [id] => 1134518260142703561 [title] => Default [description] => [rate] => 20 [created_at] => [updated_at] => ) ) [collection] => [brand] => [price] => Array ( [value] => £1.20 [data] => Array ( [formatted] => Array ( [with_tax] => £1.20 [without_tax] => £1.00 [tax] => £0.20 ) [rounded] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) [raw] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) ) ) [is_variation] => [modifiers] => Array ( ) [images] => Array ( ) ) ) [pagination] => Array ( [total] => 1 [current] => 1 [limit] => 10 [offset] => 0 [from] => 1 [to] => 1 [offsets] => Array ( [first] => [previous] => [next] => [last] => ) [links] => Array ( [first] => [previous] => [next] => [last] => ) ) ) status = 1
How to get specific array from this list?
I already try
<?php
echo $product[0]['id'];
?>
it didn't work, show error Notice: Undefined offset: 0
you have a multidimensional array under the result key
access it the following way:
$product['result'][0]['id']
Give this a try:
echo $product['result'][0]['id'];

Categories