Hi I want to get value from given XML using simple_xml_string but its not working. XML is given below:
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:Header>
<eb:MessageHeader xmlns:eb="http://www.ebxml.org/namespaces/messageHeader" eb:version="1.0" soap-env:mustUnderstand="1">
<eb:From><eb:PartyId eb:type="urn:x12.org.IO5:01">webservices.sabre.com</eb:PartyId></eb:From>
<eb:To><eb:PartyId eb:type="urn:x12.org.IO5:01">info#gandakiintl.com</eb:PartyId></eb:To>
<eb:CPAId>T198</eb:CPAId>
<eb:ConversationId>111#gandakiintl.com</eb:ConversationId>
<eb:Service eb:type="SabreXML">Enhanced Air Book Request</eb:Service>
<eb:Action>ErrorRS</eb:Action>
<eb:MessageData>
<eb:MessageId>1522435489615361760</eb:MessageId>
<eb:Timestamp>2017-01-11T13:36:01</eb:Timestamp>
<eb:RefToMessageId>mid:11110info#gandakiintl.com</eb:RefToMessageId>
</eb:MessageData>
</eb:MessageHeader>
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/12/secext">
<wsse:BinarySecurityToken valueType="String" EncodingType="wsse:Base64Binary">
Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/ACPCRTC!ICESMSLB\/CRT.LB!-3319706757025363837!367706!0
</wsse:BinarySecurityToken>
</wsse:Security>
</soap-env:Header>
<soap-env:Body>
<soap-env:Fault>
<faultcode>soap-env:Client.InvalidSecurityToken</faultcode>
<faultstring>Invalid or Expired binary security token: Shared/IDL:IceSess\/SessMgr:1\.0.IDL/Common/!ICESMS\/ACPCRTC!ICESMSLB\/CRT.LB!-3319706757025363837!367706!0</faultstring>
<detail>
<StackTrace>
com.sabre.universalservices.base.session.SessionException: errors.session.USG_INVALID_SECURITY_TOKEN
</StackTrace>
</detail>
</soap-env:Fault>
</soap-env:Body>
</soap-env:Envelope>
From above xml I want to get faultCode node value But I am not able to get. Please help. I tried doing it but its not working.
$feed = simplexml_load_string($response);
$a = $feed->children('http://schemas.xmlsoap.org/soap/envelope/');
var_dump($a->Fault->children('http://schemas.xmlsoap.org/soap/envelope/'));
Edited:
Output I get is: Node no longer exists. But I want to get "soap-env:Client.InvalidSecurityToken" value.
Related
So I have a test payment with the Cybersource SOAP API like below but I'm not able to get it to return a payment token that I can use for payments in future without using the credit card details each times:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>{{merchant_id}}</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">{{SOAP KEY}}</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<requestMessage xmlns="urn:schemas-cybersource-com:transaction-data-1.150">
<merchantID>{{merchant_id}}</merchantID>
<merchantReferenceCode>kjdhflasjfhlasdjfasdf</merchantReferenceCode>
<billTo>
<firstName>John</firstName>
<lastName>Doe</lastName>
<street1>1295 Charleston Road</street1>
<city>Mountain View</city>
<state>CA</state>
<postalCode>94043</postalCode>
<country>US</country>
<email>null#cybersource.com</email>
</billTo>
<item id="0">
<unitPrice>5.00</unitPrice>
<quantity>1</quantity>
</item>
<item id="1">
<unitPrice>10.00</unitPrice>
<quantity>2</quantity>
</item>
<purchaseTotals>
<currency>ZMW</currency>
</purchaseTotals>
<card>
<accountNumber>4111111111111111</accountNumber>
<expirationMonth>11</expirationMonth>
<expirationYear>2020</expirationYear>
<cvNumber>123</cvNumber>
</card>
<ccAuthService run="true"/>
</requestMessage>
</soapenv:Body>
</soapenv:Envelope>
Add the following to your request:
<recurringSubscriptionInfo>
<frequency>on-demand</frequency>
</recurringSubscriptionInfo>
<paySubscriptionCreateService run="true"/>
Your new request will look like this:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>{{merchantID}}</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">{{SOAPKey}}</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<requestMessage xmlns="urn:schemas-cybersource-com:transaction-data-1.150">
<merchantID>{{merchantID}}</merchantID>
<merchantReferenceCode>kjdhflasjfhlasdjfasdf</merchantReferenceCode>
<billTo>
<firstName>John</firstName>
<lastName>Doe</lastName>
<street1>1295 Charleston Road</street1>
<city>Mountain View</city>
<state>CA</state>
<postalCode>94043</postalCode>
<country>US</country>
<email>null#cybersource.com</email>
</billTo>
<item id="0">
<unitPrice>5.00</unitPrice>
<quantity>1</quantity>
</item>
<item id="1">
<unitPrice>10.00</unitPrice>
<quantity>2</quantity>
</item>
<purchaseTotals>
<currency>ZMW</currency>
</purchaseTotals>
<card>
<accountNumber>4111111111111111</accountNumber>
<expirationMonth>11</expirationMonth>
<expirationYear>2020</expirationYear>
<cvNumber>123</cvNumber>
</card>
<recurringSubscriptionInfo>
<frequency>on-demand</frequency>
</recurringSubscriptionInfo>
<ccAuthService run="true"/>
<paySubscriptionCreateService run="true"/>
</requestMessage>
</soapenv:Body>
</soapenv:Envelope>
The response will now have a subscriptionID in it, that is your token to use in place of the card account number. You might find the tokenization guide useful.
You should not expose your merchantID and SOAP Key here. Please edit your question to remove them.
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 am looking how to sign soap header using PHP.
The soap service is built by apache rampart, which is exactly same as sample 2 in https://axis.apache.org/axis2/java/rampart/samples.html.
Now, I have a soap client develop by using PHP.
I have no idea how to sign the entire headers and body.
I can make my soap request as following
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.globesteel.com" xmlns:ns2="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns3="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<SOAP-ENV:Header>
<ns3:Security SOAP-ENV:mustUnderstand="1">
<ns2:Timestamp>
<ns2:Created>2016-07-13T08:16:02Z</ns2:Created>
<ns2:Expires>2016-07-20T06:56:02Z</ns2:Expires>
</ns2:Timestamp>
<ns3:Signature>
<ns3:SignedInfo>
<Signature>
<SignedInfo>
<CanonicalizationMethod>
<Algorithm>http://www.w3.org/2001/10/xml-exc-c14n#</Algorithm>
</CanonicalizationMethod>
<SignatureMethod>
<Algorithm>http://www.w3.org/2000/09/xmldsig#rsa-sha1</Algorithm>
</SignatureMethod>
<Reference>
<SOAP-ENC:Struct>
<Transforms>
<SOAP-ENC:Struct>
<Algorithm>http://www.w3.org/2001/10/xml-exc-c14n#</Algorithm>
</SOAP-ENC:Struct>
</Transforms>
<DigestMethod>
<Algorithm>http://www.w3.org/2000/09/xmldsig#sha1</Algorithm>
</DigestMethod>
<DigestValue>8f6c3a934fc237673e9f1a12793f5507b8103e4a</DigestValue>
<URI>#_body</URI>
<Id/>
</SOAP-ENC:Struct>
<SOAP-ENC:Struct>
<Transforms>
<SOAP-ENC:Struct>
<Algorithm>http://www.w3.org/2001/10/xml-exc-c14n#</Algorithm>
</SOAP-ENC:Struct>
</Transforms>
<DigestMethod>
<Algorithm>http://www.w3.org/2000/09/xmldsig#sha1</Algorithm>
</DigestMethod>
<DigestValue></DigestValue>
<URI>#_control</URI>
<Id/>
</SOAP-ENC:Struct>
</Reference>
</SignedInfo>
<SignatureValue>Yu/DkCbKXAoalySGM2XdieRYhk1rnwhFKNcklXn5l+YgNk3AXEnpr4yDAlReYgU3FGOZh0XGUn8hGWwEs28S+xjrROgb3G/SYKVKbS3EmAU/vLBa+lABn/0NDoGdR/iIv9C7XAr/OBhE++cHA+lktZSS1SUPtfG5BAifN/RtfkE=</SignatureValue>
<KeyInfo>aqePjuZzE1lzwMMtquksvNJsbmI=</KeyInfo>
</Signature>
</ns3:SignedInfo>
</ns3:Signature>
</ns3:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:GetAvailableSecurityQuestions/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
But I still get error return "Message is not signed".
After 2 weeks of pain, I finally solved this by using https://github.com/robrichards/xmlseclibs
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.
How can i get errorCode and errorMsg values? I went trough many example but still struggling.
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:doOperationsResponse xmlns:ns1="urn:bulkdeployer.easy.gintel.com" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<result href="#id0"/>
</ns1:doOperationsResponse>
<multiRef xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="urn:bulkdeployer.easy.gintel.com" id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:ResponseType">
<errorCode xsi:type="xsd:int">0</errorCode>
<errorMsg xsi:type="xsd:string">No errors</errorMsg>
</multiRef>
</soapenv:Body>
</soapenv:Envelope>
What I have tried:
$xml= simplexml_load_string($content);
$xml->registerXPathNamespace('nam','urn:bulkdeployer.easy.gintel.com'); // need to register namespace
$return_code = $xml->xpath('//nam:errorCode');
$return_msg = $xml->xpath('//nam:errorMsg');
Thanks