I am using the following code to get the json from Paypal.
$url =("https://api.sandbox.paypal.com/v2/checkout/orders/$orderID");
$headers=array("Content-Type: application/json",
"Authorization: Bearer " .$access_token
);
$curl = curl_init();
$options = [
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_SSL_VERIFYPEER =>false,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CUSTOMREQUEST=> 'GET',
CURLOPT_HTTPAUTH => CURLAUTH_BEARER,
CURLOPT_XOAUTH2_BEARER => $access_token,
];
curl_setopt_array($curl, $options);
$response=curl_exec($curl);
//$response = json_decode(curl_exec($curl));
curl_close($curl);
$response=json_decode($response, true); //array
//$array = get_object_vars($response);
I get back the following when I print out the response.
object(stdClass)#10 (8) { ["id"]=> string(17) "4SG92296D12008253" ["intent"]=> string(7) "CAPTURE" ["status"]=> string(9) "COMPLETED" ["purchase_units"]=> array(1) { [0]=> object(stdClass)#11 (5) { ["reference_id"]=> string(7) "default" ["amount"]=> object(stdClass)#12 (2) { ["currency_code"]=> string(3) "USD" ["value"]=> string(4) "5.00" } ["payee"]=> object(stdClass)#13 (2) { ["email_address"]=> string(30) "midel-facilitator@model.com" ["merchant_id"]=> string(13) "QUZE7DB6LP5EG" } ["shipping"]=> object(stdClass)#15 (2) { ["name"]=> object(stdClass)#14 (1) { ["full_name"]=> string(10) "test buyer" } ["address"]=> object(stdClass)#16 (5) { ["address_line_1"]=> string(9) "1 Main St" ["admin_area_2"]=> string(8) "San Jose" ["admin_area_1"]=> string(2) "CA" ["postal_code"]=> string(5) "95131" ["country_code"]=> string(2) "US" } } ["payments"]=> object(stdClass)#27 (1) { ["captures"]=> array(1) { [0]=> object(stdClass)#17 (9) { ["id"]=> string(17) "24F97831B4310422F" ["status"]=> string(9) "COMPLETED" ["amount"]=> object(stdClass)#18 (2) { ["currency_code"]=> string(3) "USD" ["value"]=> string(4) "5.00" } ["final_capture"]=> bool(true) ["seller_protection"]=> object(stdClass)#19 (2) { ["status"]=> string(8) "ELIGIBLE" ["dispute_categories"]=> array(2) { [0]=> string(17) "ITEM_NOT_RECEIVED" [1]=> string(24) "UNAUTHORIZED_TRANSACTION" } } ["seller_receivable_breakdown"]=> object(stdClass)#21 (3) { ["gross_amount"]=> object(stdClass)#20 (2) { ["currency_code"]=> string(3) "USD" ["value"]=> string(4) "5.00" } ["paypal_fee"]=> object(stdClass)#22 (2) { ["currency_code"]=> string(3) "USD" ["value"]=> string(4) "0.66" } ["net_amount"]=> object(stdClass)#23 (2) { ["currency_code"]=> string(3) "USD" ["value"]=> string(4) "4.34" } } ["links"]=> array(3) { [0]=> object(stdClass)#24 (3) { ["href"]=> string(69) "https://api.sandbox.paypal.com/v2/payments/captures/24F97831B4310422F" ["rel"]=> string(4) "self" ["method"]=> string(3) "GET" } [1]=> object(stdClass)#25 (3) { ["href"]=> string(76) "https://api.sandbox.paypal.com/v2/payments/captures/24F97831B4310422F/refund" ["rel"]=> string(6) "refund" ["method"]=> string(4) "POST" } [2]=> object(stdClass)#26 (3) { ["href"]=> string(67) "https://api.sandbox.paypal.com/v2/checkout/orders/4SG92296D12008253" ["rel"]=> string(2) "up" ["method"]=> string(3) "GET" } } ["create_time"]=> string(20) "2022-05-18T03:05:09Z" ["update_time"]=> string(20) "2022-05-18T03:05:09Z" } } } } } ["payer"]=> object(stdClass)#29 (4) { ["name"]=> object(stdClass)#28 (2) { ["given_name"]=> string(4) "test" ["surname"]=> string(5) "buyer" } ["email_address"]=> string(24) "midel-buyer@model.com" ["payer_id"]=> string(13) "ZG835WK7PCQH4" ["address"]=> object(stdClass)#30 (1) { ["country_code"]=> string(2) "US" } } ["create_time"]=> string(20) "2022-05-18T03:05:02Z" ["update_time"]=> string(20) "2022-05-18T03:05:09Z" ["links"]=> array(1) { [0]=> object(stdClass)#31 (3) { ["href"]=> string(67) "https://api.sandbox.paypal.com/v2/checkout/orders/4SG92296D12008253" ["rel"]=> string(4) "self" ["method"]=> string(3) "GET" } } }
I am trying to get the value i.e. $5.00 as a value from the response and have the following code to pull the data.
print_r($response['purchase_units'][0]['amount'][2]['value'][4]);
I get the following notice messages
Notice line 78: Undefined index: value Notice line 78: Trying to access array offset on value of type null
This is the closest I have come to getting it right without massive fatal flaw errors or other error messages. What am I doing wrong? I been banging my head on this for weeks. Any help on this will be great.
Thanks