Get SOAP response to xml - php

Stack Overflow is full with questions like this, I'm aware of that. But none of the questions and accepted answers have solved it for me.
I'm getting a SOAP response like this:
string(402482) "ZSDSD1BKA00_DE_02DE00010000001083212550JVBERi0xLjUNJeLjz9MNCjExNCAwIG9iag08PC9MaW5lYXJpemVkIDEvTCAxMDgzMjEvTyAxMTYv RSAxODY2Mi9OIDEyL1QgMTA3Nzk3L0ggWyA1MDMgMjc2XT4+DWVuZG9iag0gICAgICAgICAgICAg DQoxMzQgMCBvYmoNPDwvRGVjb2RlUGFybXM8PC9Db2x1bW5zIDQvUHJlZGljdG9yIDEyPj4vRmls dGVyL0ZsYXRlRGVjb2RlL0lEWzwxREZGRkVGMUM4Q0E0NTI4QjBBMUYxOUEyNTMwREQ2OD48RURD QTlGRDBFNTE4N0M0N0JGRUZCOEM0MjlCRTUwMjE+XS9JbmRleFsxMTQgMzZdL0luZm8gMTEzIDAg Ui9MZW5ndGggOTMvUHJldiAxMDc3OTgvUm9vdCAxMTUgMCBSL1NpemUgMTUwL1R5cGUvWFJlZi9X WzEgMiAxXT4+c3RyZWFtDQpo3mJiZBBgYGJg/g0kGEKABONRIMHiCiSYNEASK0DEG5AEP4i4CZKI ABHiQEJIDyTWDiL+AwmuVhCLDaTDCsQtBHHZgcReIMHIwAiyg4GRIuI/Y9NngAADAOlxDEINCmVu ZHN0cmVhbQ1lbmRvYmoNc3RhcnR4cmVmDQowDQolJUVPRg0KICAgICAgICAgDQoxNDkgMCBvYmoN PDwvRmlsdGVyL0ZsYXRlRGVjb2RlL0kgMjE3L0wgMjAxL0xlbmd0aCAxODcvUyAxNDM+PnN0cmVh bQ0KaN5iYGBgZmBg8mZgZWDg38PAx4AAfEAZVgYWBo6qZQyMDAwCDNf1/NQ/HVzCrMDAO79pAssO rrZJjgW7zB7nbQCqZvMMlpJUbfRmmsaqwzPpwFIQCyjGNI2BvaIBhBoqgIipAkyzAzFW04AG+TMw TgYZKATEwmCHtDPwMn543+ykJGjUpMDleJGnJfMAA3v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SLMzsLC2y/NdfSVboLbnXP8nXqkjLd2buPi00NTMw YewP8V1ipuKm1s3yid5XdZHmxvTNovEBzLxJ82w5Kde5JozGjS7+IWF7M1yKYOts01Q1/d67hLki RhPXHDj4Y7msVlm5pt+yclJus06fZfW2mT6lNfHE3gEm+fHZfU7bJVwIGj//aBBMUj9rg6qDBr5X
... but much longer.
Then I use simplexml_load_string to convert it, resulting in an apparently empty object. Now I've learned that this object is not empty though. print_r and var_dump are of no help and I used simplexml_tree.php for help. But I'm now stuck on how I can access a property within the result. I tried a bunch of different variations, most of them left me either a blank page, or an error 500.
This is the response I expect:
Trying to access property ORBLK, like I wrote, with many variations, has not been successful. Thats my current try (resulting a blank page):
$resultRow = (string)$xml->children('soap-env', true)->Body->children('n0', true)->Z_SDB_GET_SDB_FOR_MATERIALResponse->T_SDB->item->DOKAR;
How would I be able to access the property ORBLK?

Related

Cloudflare php cURL get returns '1'

I've noticed a wierd behavior of php curl GET query to Cloudflare API https://api.cloudflare.com/client/v4/zones
When using Postman — everything is okay and it show correct response
But when trying to get via PHP it returns '1' for some reason. Here is my code and logs:
Also tried to pass in body, but it didn't work too
Please, help me to figure out the problem and fix it. Thanks!
p.s. i've also tried to pass urlencoded variable, but this also has no effect
The problem was in logs — i've just forgot to add second true parameter to print_r so it'll return the output

Weird output when trying to list all customers in Stripe using php

I created a database customers.txt where are saved all my created customers in Stripe. Now I want to list all the customers. This is my code in php for listing customers.
$e= \Stripe\Customer::all(array(
'limit' => 3
));
echo $e;
}
But the output is weird:
IMAGE:
Can someone help me to list the customers?
Now I have got my JSON and run this:
$e=\Stripe\Customer::all(array(
"limit"=>10
));
$customers=json_decode($e,true);
var_dump($customers);
I get just NULL response!
That output is not wyrd, it's a Stripe JSON string. standing for Javascript Object Notation (website).
There's a lot of questions on Stackoverflow about JSON so ask things such as How to convert JSON string into a PHP array.
Also Stripes own documentation (which is very good), states:
JSON is returned by all API responses, including errors, although our API libraries convert responses to appropriate language-specific objects.
from the Stripe Documentation
Edit:
You can read A useful question about turning a JSON string into an object and vice versa
So now you know what JSON is
Using it to get a PHP customer object. (revised)
$e // customer JSON of all customers.
$customers = $e->__toArray(true);
//$customers = json_decode($e);
And then process the array $customers as you need to in your applicaton.
NOTE:
The value of $customers or $customersArray will be an Object or a String data type so you need to treat the appropriately, and they will not display with echo because echo is a string output function, so you need to use print_r() or var_dump() to display these values -in their raw form- on the screen.
EDIT TWO
Recommended that from your screenshot that you format the API response from Stripe into an Array of Objects. This can be done by following this Stack Overflow Answer here.
Please review my revised code above.

Accessing multiple responses in SOAP

I just learned soap a month ago and managed to get a reply in PHP. I managed to get a response and parse it but I am stuck with a different response where I get 5 instead of 1. Trying to figure out how to parse it. I'm so used to arrays and all that it's a bit confusing for me
Here is a normal response/reply
$value = $client->GetInmate($parameters);
$xml = $value->GetInmateResult;
print "Street: ".$xml->Address->Street;
print "<br>City: ".$xml->Address->City;
print "<br>State ".$xml->Address->State;
This works
Now I am trying to do something similar but my same method is not working, here is an image of the structure of the next reply:
http://i.stack.imgur.com/wWFxg.png
As you can see, I'm trying to get the 'Charges (5)' and manage them independently but racking my brain to do so. simplexml_load_string() isn't helping either, doesn't seem to parse them correctly.
Aren't you able to retrieve the result in the loop because it is the same format which i can see in the image attached. If not, then let me know the response which you are getting through this line:
$xml = $value->GetInmateResult

PHP, can't set variable via $_POST

I have a slightly frustrating problem...
I'm sending a form value to PHP via AJAX and that seem to work fine.
When I do var_dump in PHP I see my values I can also set a variable and echo it correctly.
However, the line
$prod_id=$_POST['product'];
causes an uncaught type error in the browser.
If I just set the variable with text in PHP everything works fine.
To conclude, this piece of code works fine:
$prod_id=("Slab Skate");
$selected_customers = mysqli_query($link,"SELECT * FROM customers
INNER JOIN cust_products on cust_products.cust_id=id
INNER JOIN products on products.prod_id=cust_products.product_id
WHERE products.prod_name='$prod_id'");
This code causes uncaught typerror:
$prod_id=$_POST['product']
Same SQL statement as above.
If I do
var_dump ($prod_id);
after setting it with $_POST I get:
string(10) "Slab Skate"
My form data in network headers tab of Chrome developer tools say:
product:Slab Skate
I don't get it...
Thanks in advance for any tips.
Update and some clarifications.
The error I get is this: "Uncaught TypeError: Cannot read property 'documentElement' of null" which is a Javascript error coming from a function later in the code. However, since the whole thing works if I "hardcode" the variable instead of setting it from $_POST my assumption was that the error must reside in PHP.
But maybe that's not the case...
What I'm doing is the following: posting a form value to PHP -> use value to select from my_sql and prepare an XML output. So far so good, (I can see the xml output in Chrome dev tools) but then I go back to a javascript to fetch the xml output from my PHP file and then it fails.
When thinking about it, it's rather obvious why it works with a "hardoded" variable and not with the $_POST set one.
So, I see two solutions either set the PHP variable in my_sql or using javascript more intelligently.
Do anyone have a smart solution? I could post all the code, but it's quite long.
Second update:
I solved the issue by writing an xml file to the server instead of trying to download it from the php file. Then my java function can process the xml correctly.
It does work, but I'm not sure how well it scales? It must be better to process the xml output from PHP directly rather then saving it to file first and then process. But, I have no insight on how big the difference is...
/Tim
I wouldn't use SELECT * FROM when using Inner Join if i were you. that would cause all sort of problems , simply give the names of columns.

What is the structure of Stripe PHP API method response? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 4 years ago.
Improve this question
I am working on a Stripe integration and I am baffled by the actual responses I get from the PHP API. I started out believing that the API reference was accurate and that the response would be a JSON string as shown for each method. I quickly discovered significant differences. Most often, the id field is missing from the JSON response. Also, the response seems to be a string, an object, and maybe some other structures, all at the same time.
Here is my debug code. I am using the latest Stripe PHP library, version 1.7.15.
function var_dump_ret($mixed=null)
{
ob_start();
var_dump($mixed);
$content=ob_get_contents();
ob_end_clean();
return($content);
}
$token=$_POST['stripeToken'];
$customer=Stripe_Customer::create(array(
"card"=>$token,
"plan"=>"agency")
);
$custVarDump=var_dump_ret($customer);
$cDecoded=json_decode($customer);
$Debug="Invidual attributes of JSON decoded customer object:"._EOL;
$Debug.="object:".$cDecoded->object._EOL;
$Debug.="created:".$cDecoded->created._EOL;
$Debug.="id:".$cDecoded->id._EOL;
$Debug.="livemode:".$cDecoded->livemode._EOL;
$Debug.="description:".$cDecoded->description._EOL;
$Debug.="active_card.object:".$cDecoded->active_card->object._EOL;
$Debug.="active_card.last4:".$cDecoded->active_card->last4._EOL;
$Debug.="active_card.type:".$cDecoded->active_card->type._EOL;
$Debug.="active_card.exp_month:".$cDecoded->active_card->exp_month._EOL;
$Debug.="active_card.exp_year:".$cDecoded->active_card->exp_year._EOL;
$Debug.="active_card.fingerprint:".$cDecoded->active_card->fingerprint._EOL;
$Debug.="active_card.country:".$cDecoded->active_card->country._EOL;
$Debug.="active_card.name:".$cDecoded->active_card->name._EOL;
$Debug.="active_card.address_line1:".$cDecoded->active_card->address_line1._EOL;
$Debug.="active_card.address_line2:".$cDecoded->active_card->address_line2._EOL;
$Debug.="active_card.address_city:".$cDecoded->active_card->address_city._EOL;
$Debug.="active_card.address_state:".$cDecoded->active_card->address_state._EOL;
$Debug.="active_card.address_zip:".$cDecoded->active_card->address_zip._EOL;
$Debug.="active_card.address_country:".$cDecoded->active_card->address_country._EOL;
$Debug.="active_card.cvc_check:".$cDecoded->active_card->cvc_check._EOL;
$Debug.="active_card.address_line1_check:".$cDecoded->active_card->address_line1_check._EOL;
$Debug.="active_card.address_zip_check:".$cDecoded->active_card->address_zip_check._EOL;
$Debug.="email:".$cDecoded->email._EOL;
$Debug.="delinquent:".$cDecoded->delinquent._EOL;
//$Debug.="subscription:".$cDecoded->subscription._EOL;
$Debug.="discount:".$cDecoded->discount._EOL;
$Debug.="account_balance:".$cDecoded->account_balance._EOL;
$Debug.="unaltered response from Stripe_Customer::create:"._EOL.$customer._EOL.
"var dump of response:"._EOL.$custVarDump._EOL.
"print_r of json_decode of response:"._EOL.print_r($cDecoded,true)._EOL;
file_put_contents(_LOGFILE,$Debug,FILE_APPEND);
Below are the contents of my debug file for the invidual attributes of the JSON decoded customer object. When executed, the code posted a notice.
Notice: Undefined property: stdClass::$id in stripe/subscription.php on line 51
Also note that I had to comment out the line that added 'subscription' to the debug string due to a fatal error regarding stdClass.
object:customer
created:1365951909
id:
livemode:
description:
active_card.object:card
active_card.last4:4242
active_card.type:Visa
active_card.exp_month:7
active_card.exp_year:2013
active_card.fingerprint:WTXPLgKDCXyp9xpD
active_card.country:US
active_card.name:charlie
active_card.address_line1:
active_card.address_line2:
active_card.address_city:
active_card.address_state:
active_card.address_zip:
active_card.address_country:
active_card.cvc_check:pass
active_card.address_line1_check:
active_card.address_zip_check:
email:
delinquent:
discount:
account_balance:0
Most notably absent is the customer ID. It does not exist in the JSON response. However, as seen in some of the Stripe example programs, it can be accessed using $customer->id. Furthermore, the var_dump output indicates even more atributes are present in a structure I cannot figure out. The entire debug file is at http://www.helioza.com/stripe/debug.txt. I have only shown the customer create method, but I am experiencing similar problems with invoices and cannot find the invoice id anywhere in the Stripe_Invoice::all or Stripe_Invoice::upcoming responses.
Questions
1) How can the value returned by Stripe_Customer::create be both a string and an object at the same time?
2) Where can I find documentation that describes the API method return values, including how to access each attribute?
Although Stripe's API returns JSON at the HTTP level (i.e. what is actually being sent over the wire), the Stripe PHP library already handles decoding the JSON response and turning it into a PHP object.
There should be no need to pass the return value from Stripe_Customer::create to json_decode - in fact, given that it's already an object, I don't understand json_decode well enough to understand why that isn't just erroring out.
In any case, you should just interact with the returned customer object directly, e.g. $customer->description or $customer->active_card->cvc_check. You can see this, for example, in the Stripe tutorial.
With Evan's help, I figured out a complete answer to the second question. As Evan stated, the key is to treat the structure returned by the Stripe PHP library as an object. The elements are referenced according to the rules implicit in the JSON structure of the raw method response.
Since I have trouble reading complex JSON, particularly as the indent depth increases, I wrote a script that turns each element of a JSON structure into a complete PHP reference, like $obj->arr[index]->obj2, and so on. At www.helioza.com/decoders/explain-json.php you can paste in a JSON string, like the examples in the Stripe API reference, and get a complete list of PHP code that references each element.
Update 5/27/2014
Looking at the various comments it seems to me that there are several hidden contexts at work here. Most are over my head, so to be clear about what I do and do not know, here is how I interpret the Stripe API documentation.
Look at the example for creating a new customer, PHP code option. The following is part of the API call response.
EXAMPLE RESPONSE
{
"object": "customer",
"created": 1401219085,
"id": "cus_474RjipEtz2ff7",
"livemode": false,
"description": "payinguser#example.com",
"email": null,
"delinquent": false,
"metadata": {
},
"subscriptions": {
"object": "list",
"total_count": 0,
"has_more": false,
"url": "/v1/customers/cus_474RjipEtz2ff7/subscriptions",
"data": [
]
},
Now in my experience, every web API response is an HTTP response. Somewhere the Stripe docs say it is POST. So I look at the response above and I see JSON, which is compatible with HTTP. The doc page does not actually identify the response as JSON or anything else. If this is not JSON, then please identify it and tell me how you know that. Calling it StdClass doesn't help since the PHP manual is quite obtuse on that topic and does not define the structure of the class.
This is really the essence of my original question. What is the nature of the response as Stripe has documented it? Sure looks like JSON delivered via HTTP. I want to be educated.
Yes, I am getting the results I want by treating what the Stripe library returns as an object. But cookbook solutions don't further anyone's knowledge. The most valuable answers on SO are explanatory.

Categories