I am using one payment gateway that return response as xml and I am trying to convert to json buy its not converting. I have tried that simplexamlloadfile , simplexmlsting function and etc.
But its not working.
Code :
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header />
<SOAP-ENV:Body>
<ns2:SingleVaultResponse xmlns:ns2="http://www.paygate.co.za/PayHOST">
<ns2:LookUpVaultResponse>
<ns2:Status>
<ns2:StatusName>Completed</ns2:StatusName>
<ns2:PayVaultData>
<ns2:name>cardNumber</ns2:name>
<ns2:value>411111xxxxx1111</ns2:value>
</ns2:PayVaultData>
<ns2:PayVaultData>
<ns2:name>expDate</ns2:name>
<ns2:value>012025</ns2:value>
</ns2:PayVaultData>
<ns2:PaymentType>
<ns2:Method>CC</ns2:Method>
<ns2:Detail>Visa</ns2:Detail>
</ns2:PaymentType>
</ns2:Status>
</ns2:LookUpVaultResponse>
</ns2:SingleVaultResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Try this:
$string2 = 'your xml sting';
$doc = new DOMDocument;
$doc->loadXML($string2);
echo "status => ".$doc->getElementsByTagName('Status')->item(0)->nodeValue;
Related
I wanted to generate the following SOAP header format,
<soapenv:Header>
<SoapHeaderMsg xmlns="http://xyz.com.au">
<opt:UserSoapHeader>
<opt:IdentityName>TEST</opt:IdentityName>
<opt:AuthenticationToken>jjjkjkjkjkjkj</opt:AuthenticationToken>
</opt:UserSoapHeader>
</SoapHeaderMsg>
</soapenv:Header>
So i am using the following php functions to generate this,
$this->__setSoapHeaders(array(
new SoapHeader('http://xyz.com.au', 'SoapHeaderMsg', array(
new SoapHeader('http://xyz.com.au', 'IdentityName', 'TEST'),
new SoapHeader('http://xyz.com.au', 'AuthenticationToken', 'jkjkjkk')
)),
));
Which generates following headers which is completely different to what i wanted above ? how do i generate exact same headers using PHP functions like above ?
<SOAP-ENV:Header>
<ns1:SoapHeaderMsg>
<SOAP-ENC:Struct>
<namespace>http://xyz.com.au</namespace>
<name>IdentityName</name>
<data>TEST</data>
<mustUnderstand>false</mustUnderstand>
</SOAP-ENC:Struct>
<SOAP-ENC:Struct>
<namespace>http://xyz.com.au</namespace>
<name>AuthenticationToken</name>
<data>hjhhjjhjhjhj</data>
<mustUnderstand>false</mustUnderstand>
</SOAP-ENC:Struct>
</ns1:SoapHeaderMsg>
</SOAP-ENV:Header>
array is mostly used on the PHP side, which gets converted to Struct. Can you please try to use object and see if you have any success with it.
$this->__setSoapHeaders(array(
new SoapHeader('http://xyz.com.au', 'SoapHeaderMsg',
(object)array(
'opt:UserSoapHeader' => (object)array(
'opt:IdentityName' => 'TEST',
'opt:AuthenticationToken' => 'jkjkjkk'
)
)),
));
The request looks like below:
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://test.domain.com/"
xmlns:ns2="http://xyz.com.au">
<SOAP-ENV:Header>
<ns2:SoapHeaderMsg>
<opt:UserSoapHeader>
<opt:IdentityName>TEST</opt:IdentityName>
<opt:AuthenticationToken>jkjkjkk</opt:AuthenticationToken>
</opt:UserSoapHeader>
</ns2:SoapHeaderMsg>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
......
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How do I read this soap response and echo the values of subid and points.
Here is the response
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:zuku">
<SOAP-ENV:Body>
<ns1:showloyaltypointsResponse xmlns:ns1="http://tempuri.org">
<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:subpoints[1]">
<item xsi:type="tns:subpoints">
<subid xsi:type="xsd:integer">618341</subid>
<points xsi:type="xsd:string">0</points>
</item>
</return>
</ns1:showloyaltypointsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And here is my php code
$result = $client ->call('showloyaltypoints',array("subid" =>$subid,"username" =>"$username", "password" =>"$password"));
echo $client->response;
I found out the solution by converting it to an array first.
https://stackoverflow.com/a/42311833/7042343
I want to transform my SOAP request from key-value format to another:
<SOAP-ENV:Header>
<ns2:AUTH>
<item>
<key>username</key>
<value>testuser</value>
</item>
<item>
<key>password</key>
<value>xxxxx</value>
</item>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is what I want:
<SOAP-ENV:Header>
<ns2:AUTH>
<username>testuser</username>
<password>xxxxx</password>
</ns2:AUTH>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:getProductConfig>
<partner_id>1</partner_id>
</ns1:getProductConfig>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
This is my PHP code where I create a new SoapClient object:
$header = new SoapHeader('chainstore-api','AUTH',$headerOptions, FALSE);
$req = new SoapClient(NULL, $options);
$req->__setSoapHeaders($header);
$res = $req->getProductConfig($params);
echo $res;
PS: Currently, It's non wsdl style but I'm thinking about to change to use wsdl too.
This may sound crazy, but I just fixed this by using WSDL instead.
It is much easier. WSDL file will determine both SOAP request and response.
I've been trying to get data from a SOAP service using PHP SoapClient.
If I point to http://my-service?WSDL (obviously I can't expose the correct one) away from PHP on a well know tool called SOAP UI with the right parameters I get a proper response. But In PHP I always get NULL in my response even with the right params and stuff.
This is my code:
<?php
$client = new SoapClient('http://my-service?WSDL',
array('trace'=>true, 'exceptions'=>true));
$params= ['EBMHeader'=> ['EBMID'=> 'anyvalue'],
'DataArea'=> ['Ip'=> '127.0.0.1', 'RequestId'=> '12345']];
try {
$response= $client->MySoapFunction($params);
var_dump($response); // returns always NULL
echo $client->__getLastResponse(); //Returns a valid XML with the proper data
} catch (Exception $exception) {
echo $exception;
}
I already tried these:
Double checked the wsdl and parameters
Changed soap options: trace and exceptions
Changed params keys to see if it fails, it does and SOAP server responds that the param is misssing or whatever the error is, for instance I can say that I'm getting a response from SOAP server.
Tried to debug using __getLastResponse(), it shows a valid XML with the expected data, also I validated the XML to see if it's ok.
Tried to use $client->__soapCall('MySoapFunction', $params, null);
and the result is the same.
I also tried to use the __getLastResponse() output and parse it to var so them i could convert it to an array but the result is an empty object:
$xml= $client->__getLastResponse();
$response = simplexml_load_string($xml, "SimpleXMLElement", LIBXML_NOCDATA);
This is my XML request from PHP with $client->__getLastRequest():
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/" xmlns:ns2="http://url.com/EnterpriseObjects/Autogestion/Producto/ABM/V1/">
<SOAP-ENV:Body>
<ns2:ConsultarProductoABM>
<ns1:EBMHeader>
<ns1:EBMID>whatever</ns1:EBMID>
</ns1:EBMHeader>
<ns2:DataArea>
<ns2:Ip>127.0.0.1</ns2:Ip>
<ns2:RequestId>12345</ns2:RequestId>
</ns2:DataArea>
</ns2:ConsultarProductoABM>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And this is my response $client->__getLastResponse():
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Body xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<v1:ConsultarProductoResponseEBM xmlns:v1="http://url.com/EnterpriseObjects/Core/EBM/Producto/V1/">
<v11:EBMHeader xmlns:v11="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/">
<v11:EBMID>anything</v11:EBMID>
<v11:CreationDateTime>2015-10-16T19:09:54.962-03:00</v11:CreationDateTime>
<v11:Sender>ATG</v11:Sender>
<v11:Target>SMFLX</v11:Target>
<v11:BusinessScope>SIN_CONFIGURACION</v11:BusinessScope>
<v11:BusinessScope>SIN_CONFIGURACION</v11:BusinessScope>
<v11:BusinessScope>SIN_CONFIGURACION</v11:BusinessScope>
<v11:BusinessScope>e6e00a83-ce05-4e2a-bdb6-d7bfbd14d84a</v11:BusinessScope>
<v11:EBMTracking>ConsultarProductoAutogestionReqABCS (V1).ConsultarProducto_+++_ConsultarProductoProvisioningProvABCS (V1).ConsultarProducto_+++_ValidarRespuestaEBS (V1).ValidarRespuesta_+++_ConsultarProductoOpenSmartFlexProvABCS (V1).ConsultarProducto_+++_ValidarRespuestaEBS (V1).ValidarRespuesta</v11:EBMTracking>
<v11:FaultNotification>
<ns1:FaultMessage xmlns:ns2="http://url.com/EnterpriseObjects/Autogestion/Producto/ABM/V1/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"/>
<ns1:FaultingService xmlns:ns2="http://url.com/EnterpriseObjects/Autogestion/Producto/ABM/V1/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"/>
<ns1:Destination xmlns:ns2="http://url.com/EnterpriseObjects/Autogestion/Producto/ABM/V1/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/" xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"/>
</v11:FaultNotification>
</v11:EBMHeader>
<v11:ReturnCode xmlns:v11="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/">0</v11:ReturnCode>
<v11:ReturnMessage xmlns:v11="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/"/>
<v11:ErrorCode xmlns:v11="http://url.com/EnterpriseObjects/Common/EBM/Ebm/V1/">0</v11:ErrorCode>
<v1:DataArea>
<v1:InstalledProduct>
<v11:Hub xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">BON</v11:Hub>
<v11:Node xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">BON076A</v11:Node>
<v11:CustomerParty xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">
<v12:Id xmlns:v12="http://url.com/EnterpriseObjects/Core/EBO/CustomerParty/V1/">7889679</v12:Id>
<v12:PartyHuman xmlns:v12="http://url.com/EnterpriseObjects/Core/EBO/CustomerParty/V1/">
<v13:FirstName xmlns:v13="http://url.com/EnterpriseObjects/Core/EBO/Common/V1/">JOHN</v13:FirstName>
<v13:LastName xmlns:v13="http://url.com/EnterpriseObjects/Core/EBO/Common/V1/">DOE</v13:LastName>
</v12:PartyHuman>
<v12:Location xmlns:v12="http://url.com/EnterpriseObjects/Core/EBO/CustomerParty/V1/">
<v13:Address xmlns:v13="http://url.com/EnterpriseObjects/Core/EBO/Common/V1/">
<v13:ProvinceName>LACATION</v13:ProvinceName>
<v13:StateName>LACATION</v13:StateName>
<v13:CityName>LACATION</v13:CityName>
</v13:Address>
</v12:Location>
</v11:CustomerParty>
<v11:ContractID xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">123456</v11:ContractID>
<v11:Service xmlns:v11="http://url.com/EnterpriseObjects/Core/EBO/InstalledProduct/V1/">
<v11:ClassId>52</v11:ClassId>
</v11:Service>
</v1:InstalledProduct>
</v1:DataArea>
</v1:ConsultarProductoResponseEBM>
</soap-env:Body>
</soapenv:Envelope>
The problem is that i don't know what else to do to get a valid php response if i do:
$response= $client->MySoapFunction($params);
var_dump($response);
I got an XML response as
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.*********.in">
<SOAP-ENV:Body>
<ns1:LoginResponse>
<return>
<SessionID>3AC46E3F62</SessionID>
<ResponseCode>0</ResponseCode>
<ResponseMessage>Successful</ResponseMessage>
</return>
</ns1:LoginResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
How can I parse the SessionID and ResponseCode from this xml using PHP.Im unable to do this.Please suggest some methods to do this.
Check this : How can I get and process a response from a PHP API and apply print_r(htmlentities($xmldata->asXML())); to your XML response
and this too : soap:Envelope SOAP-ENV:Envelope PHP
the responses from there maybe will help you , of course you may code yourself cause is very easy
Check this code too is already working example (very close to your problem):
<?php
$a ='<soap-env:envelope xmlns:ns1="http://v3.core.com.productserve.com/" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<ns1:getproductlistresponse>
<oproduct>
<iid>113133802</iid>
<icategoryid>270</icategoryid>
<imerchantid>1547</imerchantid>
<iadult>0</iadult>
<sname>The Ashes / 5th Test - England v Australia - Day 1</sname>
<sawdeeplink>http://www.awin1.com/pclick.php?p=113133802&a=111402&m=1547&platform=cs</sawdeeplink>
<sawthumburl>http://images.productserve.com/thumb/1547/113133802.jpg</sawthumburl>
<fprice>119.99</fprice>
</oproduct>
</ns1:getproductlistresponse>
</soap-env:body>
</soap-env:envelope>';
$xml = simplexml_load_string($a);
$ns = $xml->getNamespaces(true);
$soap = $xml->children($ns['soap-env']);
$getproductlistresponse = $soap->body->children($ns['ns1']);
foreach ($getproductlistresponse->children() as $item)
{
//This example just accesses the iid node but the others are all available.
echo (string) $item->iid . '<br />';
}
?>