简体   繁体   中英

store php variables of complex json return array from paypal api

I am using the PayPal API to give me information about specific transactions. I am using PHP and curl and everything is working fine. PayPal returns the result which is a JSON object.

Here is a sample of the output that the JSON object gives me when I send it to print_r($JSON) after $JSON = json_decode($result, true);

Array ( [transaction_details] => Array ( [0] => Array ( [transaction_info] => Array ( [paypal_account_id] => U*****8W [transaction_id] => 0EC********3404V [transaction_event_code] => T0006 [transaction_initiation_date] => 2020-11-24T04:22:32+0000 [transaction_updated_date] => 2020-11-24T04:22:32+0000 [transaction_amount] => Array ( [currency_code] => USD [value] => 364.71 ) [fee_amount] => Array ( [currency_code] => USD [value] => -10.88 ) [transaction_status] => S [transaction_subject] => Payment to Seller [custom_field] => seller_e*******1-4d4c-90d1-51e0eae77f2c_1 [protection_eligibility] => 01 ) [payer_info] => Array ( [account_id] => UWM*****28W [email_address] => s******@networkcowboy.org [address_status] => Y [payer_status] => Y [payer_name] => Array ( [given_name] => Scott [surname] => D******e [alternate_full_name] => S*************e ) [country_code] => US ) [shipping_info] => Array ( [name] => S*t Do**le [address] => Array ( [line1] => 8** St [city] => La**od [state] => CO [country_code] => US [postal_code] => 80215 ) ) [cart_info] => Array ( [item_details] => Array ( [0] => Array ( [item_code] => LUMI23398 [item_name] => Samsung Galaxy S10e (T-Mobile) [SM-G970U] - Black, 128 GB, 6 GB [item_quantity] => 1 [item_unit_price] => Array ( [currency_code] => USD [value] => 349.00 ) [item_amount] => Array ( [currency_code] => USD [value] => 349.00 ) [tax_amounts] => Array ( [0] => Array ( [tax_amount] => Array ( [currency_code] => USD [value] => 15.71 ) ) ) [total_item_amount] => Array ( [currency_code] => USD [value] => 364.71 ) ) ) ) [store_info] => Array ( ) [auction_info] => Array ( ) [incentive_info] => Array ( ) ) ) [account_number] => PR6L***PXQN [start_date] => 2020-11-01T07:00:00+0000 [end_date] => 2020-11-29T21:59:59+0000 [last_refreshed_datetime] => 2020-11-29T21:59:59+0000 [page] => 1 [total_items] => 1 [total_pages] => 1 [links] => Array ( [0] => Array ( [href] => https://api.paypal.com/v1/reporting/transactions?end_date=2020-11-29T23%3A59%3A59-0700&transaction_id=0EC78****43404V&fields=all&start_date=2020-11-01T00%3A00%3A00-0700&page_size=100&page=1 [rel] => self [method] => GET ) ) )

As you can see the JSON object is extremply complex... for me at least. I need to extract some of the values and save them to variables.

I need to extract values for transaction_initiation_date, item_code, alternate_full_name, line1, city, state, postal_code, email_address, and other SUPER COMPLICATED things like price, etc which are several layers deep.

I am not asking for anyone to write the code for me but if someone can explain how I can traverse this to get to what I need...

Thanks so much in advance.

I am using the PayPal API to give me information about specific transactions. I am using PHP and curl and everything is working fine. PayPal returns the result which is a JSON object.

Here is a sample of the output that the JSON object gives me when I send it to print_r($JSON) after $JSON = json_decode($result, true);

Array ( [transaction_details] => Array ( [0] => Array ( [transaction_info] => Array ( [paypal_account_id] => U*****8W [transaction_id] => 0EC********3404V [transaction_event_code] => T0006 [transaction_initiation_date] => 2020-11-24T04:22:32+0000 [transaction_updated_date] => 2020-11-24T04:22:32+0000 [transaction_amount] => Array ( [currency_code] => USD [value] => 364.71 ) [fee_amount] => Array ( [currency_code] => USD [value] => -10.88 ) [transaction_status] => S [transaction_subject] => Payment to Seller [custom_field] => seller_e*******1-4d4c-90d1-51e0eae77f2c_1 [protection_eligibility] => 01 ) [payer_info] => Array ( [account_id] => UWM*****28W [email_address] => s******@networkcowboy.org [address_status] => Y [payer_status] => Y [payer_name] => Array ( [given_name] => Scott [surname] => D******e [alternate_full_name] => S*************e ) [country_code] => US ) [shipping_info] => Array ( [name] => S*t Do**le [address] => Array ( [line1] => 8** St [city] => La**od [state] => CO [country_code] => US [postal_code] => 80215 ) ) [cart_info] => Array ( [item_details] => Array ( [0] => Array ( [item_code] => LUMI23398 [item_name] => Samsung Galaxy S10e (T-Mobile) [SM-G970U] - Black, 128 GB, 6 GB [item_quantity] => 1 [item_unit_price] => Array ( [currency_code] => USD [value] => 349.00 ) [item_amount] => Array ( [currency_code] => USD [value] => 349.00 ) [tax_amounts] => Array ( [0] => Array ( [tax_amount] => Array ( [currency_code] => USD [value] => 15.71 ) ) ) [total_item_amount] => Array ( [currency_code] => USD [value] => 364.71 ) ) ) ) [store_info] => Array ( ) [auction_info] => Array ( ) [incentive_info] => Array ( ) ) ) [account_number] => PR6L***PXQN [start_date] => 2020-11-01T07:00:00+0000 [end_date] => 2020-11-29T21:59:59+0000 [last_refreshed_datetime] => 2020-11-29T21:59:59+0000 [page] => 1 [total_items] => 1 [total_pages] => 1 [links] => Array ( [0] => Array ( [href] => https://api.paypal.com/v1/reporting/transactions?end_date=2020-11-29T23%3A59%3A59-0700&transaction_id=0EC78****43404V&fields=all&start_date=2020-11-01T00%3A00%3A00-0700&page_size=100&page=1 [rel] => self [method] => GET ) ) )

As you can see the JSON object is extremply complex... for me at least. I need to extract some of the values and save them to variables.

I need to extract values for transaction_initiation_date, item_code, alternate_full_name, line1, city, state, postal_code, email_address, and other SUPER COMPLICATED things like price, etc which are several layers deep.

I am not asking for anyone to write the code for me but if someone can explain how I can traverse this to get to what I need...

Thanks so much in advance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM