Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is the cleanest solution I could come up with:</p> <pre><code>$client = new SoapClient( 'https://www.sandbox.paypal.com/wsdl/PayPalSvc.wsdl', array( 'soap_version' =&gt; SOAP_1_1 )); $cred = array( 'Username' =&gt; $username, 'Password' =&gt; $password, 'Signature' =&gt; $signature ); $Credentials = new stdClass(); $Credentials-&gt;Credentials = new SoapVar( $cred, SOAP_ENC_OBJECT, 'Credentials' ); $headers = new SoapVar( $Credentials, SOAP_ENC_OBJECT, 'CustomSecurityHeaderType', 'urn:ebay:apis:eBLBaseComponents' ); $client-&gt;__setSoapHeaders( new SoapHeader( 'urn:ebay:api:PayPalAPI', 'RequesterCredentials', $headers )); $args = array( 'Version' =&gt; '71.0', 'ReturnAllCurrencies' =&gt; '1' ); $GetBalanceRequest = new stdClass(); $GetBalanceRequest-&gt;GetBalanceRequest = new SoapVar( $args, SOAP_ENC_OBJECT, 'GetBalanceRequestType', 'urn:ebay:api:PayPalAPI' ); $params = new SoapVar( $GetBalanceRequest, SOAP_ENC_OBJECT, 'GetBalanceRequest' ); $result = $client-&gt;GetBalance( $params ); echo 'Balance is: ', $result-&gt;Balance-&gt;_, $result-&gt;Balance-&gt;currencyID; </code></pre> <p>This produces the following XML request document, which, at the time of writing, was being successfully accepted and processed by PayPal:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:ebay:apis:eBLBaseComponents" xmlns:ns2="urn:ebay:api:PayPalAPI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; &lt;SOAP-ENV:Header&gt; &lt;ns2:RequesterCredentials&gt; &lt;ns1:Credentials xsi:type="Credentials"&gt; &lt;Username&gt;***&lt;/Username&gt; &lt;Password&gt;***&lt;/Password&gt; &lt;Signature&gt;***&lt;/Signature&gt; &lt;/ns1:Credentials&gt; &lt;/ns2:RequesterCredentials&gt; &lt;/SOAP-ENV:Header&gt; &lt;SOAP-ENV:Body&gt; &lt;ns2:GetBalanceReq xsi:type="GetBalanceRequest"&gt; &lt;GetBalanceRequest xsi:type="ns2:GetBalanceRequestType"&gt; &lt;ns1:Version&gt;71.0&lt;/ns1:Version&gt; &lt;ns2:ReturnAllCurrencies&gt;1&lt;/ns2:ReturnAllCurrencies&gt; &lt;/GetBalanceRequest&gt; &lt;/ns2:GetBalanceReq&gt; &lt;/SOAP-ENV:Body&gt; &lt;/SOAP-ENV:Envelope&gt; </code></pre> <p>In response to some of the other comments on this page:</p> <ul> <li>I'm fairly certain the OP <em>has</em> read the API doc, because that's where the example XML came from that he is trying to reproduce using PHP SOAP library.</li> <li>The PayPal PHP API has some shortcomings, the biggest one being that it fails to work with E_STRICT warnings turned on. It also requires PEAR, so if you are not currently using PEAR in your project it means dragging in quite a lot of new code, which means more complexity and potentially more risk, in order to achieve what should be two or three fairly simple XML exchanges for a basic implementation.</li> <li>The NVP API looks pretty good too, but I'm a glutten for punishment, so I chose the hard path. :-)</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload