1

I'm having issues with a SOAP call, and I believe it is related to a namespace. I'm getting incorrect responses back from the server I'm sending to, and it appears to be thanks to an incorrect SOAP Envelope and namespace.

152     protected function callWithSOAP($xml) {
153         
154         try {
155             $soapClient = new SoapClient($this->mercuryWSDL, array('trace'=>1));
156         } catch (Exception $e) {
157             throw new Exception($e->getMessage());
158         }
159         
160         $message = array(
161             'tran'=> $xml,
162             'pw'=> $this->mercuryPassword
163         );      
164         
165         // Make SOAP Call
166         try {
167             $request = $soapClient->CreditTransaction($message);
168         } catch (Exception $e) { 
169             throw new Exception($e->getMessage());
170         }
171 
172         $res = $soapClient->__getLastRequest();
173         return $res;
174 
175         return $request;
176     }

The XML I'm feeding into it in the method signature is fine, I have confirmed that is the same as the server is expecting, its specifically the soap request that is having the problem.

Here is the SOAP request I'm sending with SoapClient:

<?xml version="1.0" encoding="UTF-8"?>

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.mercurypay.com">
    <SOAP-ENV:Body>
        <ns1:CreditTransaction>
            <ns1:tran>
            <?xml version="1.0"?>
            <TStream>
                <Transaction>
                    <MerchantID>******</MerchantID>
                    <TranType>Credit</TranType>
                    <TranCode>FSASale</TranCode>
                    <InvoiceNo>12</InvoiceNo>
                    <RefNo>12</RefNo>
                    <Account>
                        <AcctNo>*******</AcctNo>
                        <ExpDate>****</ExpDate>
                    </Account>
                    <Amount>
                        <Purchase>25</Purchase>
                        <FSAPrescription>25</FSAPrescription>
                    </Amount>
                </Transaction>
            </TStream>
        </ns1:tran>
        <ns1:pw>xyz</ns1:pw>
    </ns1:CreditTransaction>
</SOAP-ENV:Body>

But here is what it's actually expecting...how can i match this:

<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mer="http://www.mercurypay.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<mer:CreditTransaction>
<mer:tran>
<?xml version="1.0"?>
<TStream>
  <Transaction>
<MerchantID>******</MerchantID>
<TranType>Credit</TranType>
<TranCode>FSASale</TranCode>
<InvoiceNo>1</InvoiceNo>
<RefNo>1</RefNo>
<Account>
  <AcctNo>************</AcctNo>
  <ExpDate>****</ExpDate>
</Account>
<Amount>
  <Purchase>63.54</Purchase>
  <FSAPrescription>63.54</FSAPrescription>
</Amount>
</Transaction>
</TStream>
</mer:tran>
<mer:pw>xyz</mer:pw>
</mer:CreditTransaction>
</soapenv:Body>
</soapenv:Envelope>

You'll notice the "mer:" all over the place. I believe this is what I need to make get a proper response from the server. Please help me out, this is supposed to go out for testing tomorrow and we just realized that the responses from this are very inconsistant.

Thanks for any help you can provide, I really appreciate it.

Cody Halovich
  • 13
  • 1
  • 3

1 Answers1

0

The <mer: namespace prefix is defined in the document (in <soapenv:Envelope ... xmlns:mer="http://www.mercurypay.com" ... >), however it is not allowed to use the XML declaration <?xml version="1.0"?> in a different place than at the start of the document.

This is a concrete rule in XML you are violating and you can not expect that this works as SOAP is based on XML.

It seem that the way you set 'tran'=> $xml and especially what is $xml in context of $message as of CreditTransaction($message) is wrong here. Put data into $xml in the correct format so that it can be passed correctly (that part of your application is hidden like it is hidden the source of the WSDL therefore no further information or hints can be given).

hakre
  • 193,403
  • 52
  • 435
  • 836
  • The issue was the dual declarations. Thank you for noticing that, I didn't realize simplexml was adding its own and the soap call wasn't removing it. Makes sense, thank you. – Cody Halovich Apr 29 '13 at 16:42
  • if you want to prevent that with simplexml, it's tricky because not possible with an option or so: http://eval.in/18017 - I think I also posted this in the one or other answer once, but right now a little lazy to search for that. Maybe partially in here: http://stackoverflow.com/a/14831397/367456 - this variant working with different string functions than *`explode()`*. – hakre Apr 29 '13 at 17:54