I am attempting to process a SOAP response from First Data’s Global Gateway. I’ve used SoapClient before, but there is no wsdl – and the company says they do not supply one.
I’ve tried various other approaches such as SimpleXMLElement based on examples found here and in the PHP manual but I can’t get anything to work. I suspect namespaces are part of my problem. Can anyone suggest an approach or point me to a similar example – my Google efforts have been fruitless to date.
Using PHP 5.
Partial SOAP Response (with all the HTML header stuff that precedes it stripped off) looks like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<fdggwsapi:FDGGWSApiOrderResponse xmlns:fdggwsapi="http://secure.linkpt.net/fdggwsapi/schemas_us/fdggwsapi">
<fdggwsapi:CommercialServiceProvider/>
<fdggwsapi:TransactionTime>Thu Nov 29 17:03:18 2012</fdggwsapi:TransactionTime>
<fdggwsapi:TransactionID/>
<fdggwsapi:ProcessorReferenceNumber/>
<fdggwsapi:ProcessorResponseMessage/>
<fdggwsapi:ErrorMessage>SGS-005005: Duplicate transaction.</fdggwsapi:ErrorMessage>
<fdggwsapi:OrderId>A-e833606a-5197-45d6-b990-81e52df41274</fdggwsapi:OrderId>
...
<snip>
I also need to be able to determine if a SOAP fault was signalled. XML for that looks like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<SOAP-ENV:FaultX>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring xml:lang="en">MerchantException</faultstring>
<detail>
cvc-pattern-valid: Value '9999185.00' is not facet-valid with respect to pattern '([1-9]([0-9]{0,3}))?[0-9](\.[0-9]{1,2})?' for type '#AnonType_ChargeTotalAmount'.
cvc-type.3.1.3: The value '9999185.00' of element 'v1:ChargeTotal' is not valid.
</detail>
</SOAP-ENV:FaultX>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Using Mr. Code’s answer I have been able to retrieve the data from the non-fault responses. But I need to determine what type of packet I am dealing with and extract data from both types. It would be so much easier if only they would supply a wsdl!
Your response can be parsed with SimpleXML, here’s an example. Notice I am passing the namespace URL to
children()to access the elements.Outputs
Codepad Demo
Edit: The SoapFault response can be parsed like below. It outputs the fault string and details, or ‘No fault found’: