How to retrieve object from xml - php

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)

Related

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.

Get a specific value from a multidimensional array provided by AgileCRM

I'm trying to get the first deal ID from AgileCRM.
When using:
$test = json_decode($deal, true);
print_r($test);
I get the following result:
Array (
[0] => Array (
[colorName] => WHITE
[id] => 5686812383117312
[apply_discount] =>
[discount_value] => 0
[discount_amt] => 0
[discount_type] => Value
[name] => New Home Loan
[contact_ids] => Array (
[0] => 5645056174194688
)
[custom_data] => Array (
)
[products] => Array (
)
[description] => New Lead
[expected_value] => 0
[milestone] => New Loan
[probability] => 10
[close_date] => 1521192269
[created_time] => 1510824270
[milestone_changed_time] => 0
[entity_type] => deal
[notes] => Array (
)
[note_ids] => Array (
)
[note_created_time] => 0
[pipeline_id] => 5719238044024832
[archived] =>
[lost_reason_id] => 0
[deal_source_id] => 0
[total_deal_value] => 0
[updated_time] => 1510824270
[isCurrencyUpdateRequired] => 1
[currency_conversion_value] => 0
[tags] => Array (
)
[tagsWithTime] => Array (
)
[contacts] => Array (
[0] => Array (
[id] => 5645056174194688
[type] => PERSON
[properties] => Array (
[0] => Array (
[type] => SYSTEM
[name] => first_name
[value] => piet
)
[1] => Array (
[type] => SYSTEM
[name] => last_name
[value] => pompies
)
[2] => Array (
[type] => SYSTEM
[name] => name
[value] =>
)
)
)
)
[owner] => Array (
[id] => 5178546118721536
[domain] => domainname
[email] => myemail#email.com
[phone] =>
[name] => Piet Pompies
[pic] => https://d1gwclp1pmzk26.cloudfront.net/img/gravatar/48.png
[schedule_id] => Piet Pompies
[calendar_url] => https://homeside.agilecrm.com/calendar/Piet_Pompies
[calendarURL] => https://homeside.agilecrm.com/calendar/Piet_Pompies
)
)
)
I want to echo "5686812383117312" from "[id] => 5686812383117312" (4th line in the array above)
I've tried "foreach" statements but my expertise on it is limited and can't seem to get it right.
Any help will be appreciated.
In order to access the ID field you should:
get the array's first key
Access the required field
Array:
Array ( //$test
[0] => Array ( //first key [0]
[colorName] => WHITE
[id] => 5686812383117312 //the required field ['id']
[apply_discount] =>
PHP:
$test = json_decode($deal, true);
print_r($test);
echo $test[0]['id']; //Output: 5686812383117312

How to process complex json object in PHP

I have a working PHP app running in Bluemix that I want to extend to call a RESTful service (Insights for Twitter). I've been able to call the service, retrieve the json body, and use json_decode as follows to create an array:
$insightList = json_decode($guzzleResponse ->getBody(), true);
However, I can't figure out how to get access to the field I'm interested in. I've searched for solution on the web and tried a few approaches that looked promising, but when I tried to integrate them, I couldn't get them to work. I'm a bit of a PHP novice, so if something doesn't work I'm not sure how to proceed.
The json structure is quite complex, with three top-level arrays - search, tweets, and next. I'm interested in the second of these, tweets. It's a pretty complex array - there is one entry per tweet. The field I want right now is tweets.cde.message.body. You can find the full schema here: https://cdeservice.eu-gb.mybluemix.net/rest-api/#!/messages/getTweets
This is the code I have so far:
foreach($insightList as $cde) {
foreach($cde as $message) {
$insight = $message['body'];
if(strlen($insight) > 60) {
$posts[] = array(
'id' => 99999999,
//Temp; remove links from the text
'text' => $insight,
'category' => $insightCategory,
'image' => 'false'
);
}
}
}
Here's a print_r of $insightList:
[search] => Array (
[results] => 28
[current] => 28
)
[tweets] => Array (
[0] => Array (
[cde] => Array (
[author] => Array (
[gender] => male
[parenthood] => Array (
[isParent] => unknown
)
[location] => Array (
[country] =>
)
[maritalStatus] => Array (
[isMarried] => unknown
)
)
[content] => Array (
[sentiment] => Array (
[evidence] => Array ( )
[polarity] => NEUTRAL
)
)
)
[message] => Array (
[postedTime] => 2015-01-13T09:42:16.000Z
[verb] => share
[link] => http://twitter.com/zWDOM/statuses/554936456477933569
[generator] => Array (
[displayName] => Twitter Web Client
[link] => http://twitter.com
)
[body] => RT #VisualSuccess: "Mainframe & Cloud" Magazine wurde soeben publiziert! http://www.twitter.com #zWDOM #Rocket #JohnKnutson_IBM
[favoritesCount] => 0
[objectType] => activity
[actor] => Array (
[summary] => Seit über 25 Jahren im Mainframebereich, derzeit als Senior Consultant und IT Architekt für zEnterprise und Projektmanager beim IBM BP Cancom in Köln
[image] => https://pbs.twimg.com/profile_images/424202233463308288/XQquUcnh_normal.jpeg
[statusesCount] => 2309
[utcOffset] => 3600
[languages] => Array (
[0] => de
)
[preferredUsername] => zWDOM
[displayName] => Willi Domroese
[postedTime] => 2009-12-17T01:39:25.000Z
[link] => http://www.twitter.com/zWDOM
[verified] =>
)
[provider] => Array (
[displayName] => Twitter
[link] => http://www.twitter.com
[objectType] => service
)
[twitter_filter_level] => medium
[twitter_entities] => Array (
[urls] => Array (
[0] => Array (
[display_url] => ln.is/paper.li/visua…
[indices] => Array (
[0] => 77
[1] => 99
)
[expanded_url] => http://ln.is/paper.li/visualsucce/7zYNk
[url] => http://www.twitter.com
)
)
[hashtags] => Array ( )
[user_mentions] => Array (
[0] => Array (
[indices] => Array (
[0] => 3
[1] => 17
)
[screen_name] => VisualSuccess
[id_str] => 213337792
[name] => Predrag Gasic
[id] => 213337792
)
[1] => Array (
[indices] => Array (
[0] => 101
[1] => 107
)
[screen_name] => zWDOM
[id_str] => 97334013
[name] => Willi Domroese
[id] => 97334013
)
[2] => Array (
[indices] => Array (
[0] => 108
[1] => 115
)
[screen_name] => Rocket
[id_str] => 870584947
[name] => Rocket Software
[id] => 870584947
)
[3] => Array (
[indices] => Array (
[0] => 116
[1] => 132
)
[screen_name] => JohnKnutson_IBM
[id_str] => 16452310
[name] => John Knutson
[id] => 16452310
)
)
[trends] => Array ( )
[symbols] => Array ( )
)
[twitter_lang] => de
[id] => tag:search.twitter.com,2005:554936456477933569
[retweetCount] => 1
[gnip] => Array (
[urls] => Array (
[0] => Array (
[expanded_url] => http://linkis.com/paper.li/visualsucce/7zYNk
[expanded_status] => 200
[url] => http://www.twitter.com
)
)
[language] => Array (
[value] => de
)
)
[object] => Array (
[postedTime] => 2015-01-13T08:04:48.000Z
[verb] => post
[link] => http://twitter.com/VisualSuccess/statuses/554911928527888384
[generator] => Array (
[displayName] => Linkis.com
[link] => http://linkis.com
)
[body] => "Mainframe & Cloud" Magazine wurde soeben publiziert! http://www.twitter.com ://www.twitter.com
[objectType] => activity
[actor] => Array (
[summary] => Ù† (N), Wirtschaftsinformatiker | SAP Consultant Logistics #bigdata #appdevelopment #webdesign #eCommerce #SocialMedia #contentmarketing #SmartHome #Journal
[image] => https://pbs.twimg.com/profile_images/2841607223/959b0d23646b1f24bd7b70deac160e2f_normal.jpeg
[statusesCount] => 14185
[utcOffset] => 3600
[languages] => Array (
[0] => de
)
[preferredUsername] => VisualSuccess
[displayName] => Predrag Gasic
[postedTime] => 2010-11-08T17:19:27.000Z
[link] => http://www.twitter.com/VisualSuccess
[verified] =>
)
[provider] => Array (
[displayName] => Twitter
[link] => http://www.twitter.com
[objectType] => service
)
[twitter_filter_level] => low
[twitter_entities] => Array (
[urls] => Array (
[0] => Array (
[display_url] => ln.is/paper.li/visua…
[indices] => Array (
[0] => 58
[1] => 80
)
[expanded_url] => http://ln.is/paper.li/visualsucce/7zYNk
[url] => http://www.twitter.com
)
)
[hashtags] => Array ( )
[user_mentions] => Array (
[0] => Array (
[indices] => Array (
[0] => 82
[1] => 88
)
[screen_name] => zWDOM
[id_str] => 97334013
[name] => Willi Domroese
[id] => 97334013
)
[1] => Array (
[indices] => Array (
[0] => 89
[1] => 96
)
[screen_name] => Rocket
[id_str] => 870584947
[name] => Rocket Software
[id] => 870584947
)
[2] => Array (
[indices] => Array (
[0] => 97
[1] => 113
)
[screen_name] => JohnKnutson_IBM
[id_str] => 16452310
[name] => John Knutson
[id] => 16452310
)
)
[trends] => Array ( )
[symbols] => Array (
)
)
)
)
)
Answers to this question would be greatly appreciated
Iterating $insightList will not get you to the cde level. And you don't actually want the cde; you want the message.
Just iterate the tweets. You don't need a foreach to get keyed info from a PHP array.
foreach($insightList['tweets'] as $tweet) {
$insight = $tweet['message']['body'];
if(strlen($insight) > 60) {
$posts[] = array(
'id' => 99999999,
//Temp; remove links from the text
'text' => $insight,
'category' => $insightCategory,
'image' => 'false'
);
}
}
It looks to me from your print_r that what you want is at:
echo $insightList[0]['message']['body'];
When there's a section like this [some_key], then 'some_key' is an associative array key, and you can access those elements be they additional arrays or a value, using the key name, as I illustrated here.

anyone to help me convert stdClass Object to an array in php

stdClass Object ( [Order] => stdClass Object
( [id] => c62f5d272ghjjgd346lmn34
[type] => [status] => placed
[keys_status] => Keys were generated )
[Products] => Array ( [0] => stdClass Object ( [name] => Mobile Security
[devices] => 1 [months] => 12 [quantity] => 1 [msrp_price] => 9 [discount] => 0.0 [end_user_price] => 9 [reseller_margin] => 0.0 [reseller_price] => 9.01[partner_margin] => 90 [partner_price] => 0.9[Keys] => Array ( [0] => stdClass Object ( [product_id] => 21 [product_name] => Mobile Security [key] => 1234) ) ) ) [Customer] => stdClass Object ( [name] => IPPS [phone] => 25667587576 [address] => Bishop willis Street [contact_person] => Mukama Gordon [city] => Kigali [zipcode] => 250 [country_id] => 202 [state_id] => [email] => mukamatest#test.com ) [Keys] => Array ( [0] => stdClass Object ( [product_id] => 21 [product_name] => Mobile Security [key] => 1234 ) ) )
This is a really hacky way of doing it, but try
$arrayversion = json_decode(json_encode($objectversion), true);
Then
print_r($arrayversion); will be an array.

UPS Shipping API Integration Error (PHP)

I download the ShippingGroundFreightWebService PHP examples from UPS.com. I got following error message:
SoapFault Object
(
[message:protected] => An exception has been raised as a result of client data.
[string:private] =>
[code:protected] => 0
[file:protected] => /home5/vizparts/public_html/PHP/SoapGroundFreightShipClient.php
[line:protected] => 193
[trace:private] => Array
(
[0] => Array
(
[file] => /home5/vizparts/public_html/PHP/SoapGroundFreightShipClient.php
[line] => 193
[function] => __soapCall
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => ProcessShipment
[1] => Array
(
[0] => Array
(
[Request] => Array
(
[RequestOption] => Array
(
[0] => 1
[1] => Shipping
)
)
[Shipment] => Array
(
[ShipFrom] => Array
(
[Name] => Pat Stewart
[TaxIdentification] => 1234567890
[Address] => Array
(
[AddressLine] => 2311 York Road
[City] => Timonium
[StateProvinceCode] => MD
[PostalCode] => 21093
[CountryCode] => US
)
[AttentionName] => String
[Phone] => Array
(
[Number] => 6785851000
[Extension] => 123
)
)
[ShipperNumber] => 222006
[ShipTo] => Array
(
[Name] => Superman
[Address] => Array
(
[AddressLine] => 2010 Warsaw Road
[StateProvinceCode] => GA
[PostalCode] => 30076
[CountryCode] => US
[City] => Roswell
)
[AttentionName] => String
[Phone] => Array
(
[Number] => 6785851000
[Extention] => 111
)
)
[PaymentInformation] => Array
(
[Payer] => Array
(
[Name] => Superman
[Address] => Array
(
[AddressLine] => 2010 Warsaw Road
[City] => Roswell
[StateProvinceCode] => GA
[PostalCode] => 30075
[CountryCode] => US
)
[ShipperNumber] => 00613270
[AttentionName] => String
[Phone] => Array
(
[Number] => 6785851000
)
)
[ShipmentBillingOption] => Array
(
[Code] => 10
[Description] => String
)
)
[Service] => Array
(
[Code] => 308
[Description] => String
)
[HandlingUnitOne] => Array
(
[Quantity] => 16
[Type] => Array
(
[Code] => PLT
[Description] => String
)
)
[Commodity] => Array
(
[CommodityID] => 22
[Description] => BUGS
[Weight] => Array
(
[UnitOfMeasurement] => Array
(
[Code] => LBS
[Description] => String
)
[Value] => 511.25
)
[Dimensions] => Array
(
[UnitOfMeasurement] => Array
(
[Code] => IN
[Description] => String
)
[Length] => 1.25
[Width] => 1.2
[Height] => 5
)
[NumberOfPieces] => 1
[PackagingType] => Array
(
[Code] => PLT
[Description] => String
)
[CommodityValue] => Array
(
[CurrencyCode] => USD
[MonetaryValue] => 265.2
)
[FreightClass] => 60
[NMFCCommodityCode] => 566
)
[Reference] => Array
(
[Number] => Array
(
[Code] => PM
[Value] => 1651651616
)
[BarCodeIndicator] => Array
(
[NumberOfCartons] => 5
[Weight] => Array
(
[UnitOfMeasurement] => Array
(
[Code] => LBS
[Description] => String
)
[Value] => 2
)
)
)
)
)
)
)
)
)
[faultstring] => An exception has been raised as a result of client data.
[faultcode] => Client
[faultcodens] => http://schemas.xmlsoap.org/soap/envelope/
[detail] => stdClass Object
(
[Errors] => stdClass Object
(
[ErrorDetail] => stdClass Object
(
[Severity] => Hard
[PrimaryErrorCode] => stdClass Object
(
[Code] => 9121000
[Description] => Invalid Ship Request Document
)
)
)
)
)
I want to integrate the UPS API into my own website. I want to print the shipping label. How to fix this problem?
you should set the request xsd file,find it in other folder in the package you download.then set the request file with it.

Categories