简体   繁体   中英

SOAP API USING CURL

I am trying to use the soap api for Ezidebit to fetch all customers in a list. Their documtation for me is very confusing and seems to be missing some things. It could be me not having enough skill too.

The documentation is here: https://www.getpayments.com/docs/#getcustomerlist

The current response im getting is:

a:ActionNotSupportedThe message with Action 'run' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

Here is my code: (ive removed my key in the xml and replaced with 000000000000000 )

<?php
  $soap_request ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:px="https://px.ezidebit.com.au/">
                   <soapenv:Header/>
                   <soapenv:Body>
                      <px:GetCustomerList>
                      <px:DigitalKey>000000000000000</px:DigitalKey>
                         <px:CustomerStatus>ALL</px:CustomerStatus>
                         <px:OrderBy>EzidebitCustomerID</px:OrderBy>
                         <px:Order>ASC</px:Order>
                         <px:PageNumber>1</px:PageNumber> 
                      </px:GetCustomerList>
                   </soapenv:Body>
                </soapenv:Envelope>';

  $header = array(
    "Content-type: text/xml;charset=\"utf-8\"",
    "Accept: text/xml",
    "Cache-Control: no-cache",
    "Pragma: no-cache",
    "SOAPAction: \"run\"",
    "Content-length: ".strlen($soap_request),
  );

  $soap_do = curl_init();
  curl_setopt($soap_do, CURLOPT_URL, "https://api.ezidebit.com.au/v3-5/nonpci" );
  curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
  curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
  curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);

  curl_setopt($soap_do, CURLOPT_POST,           true );
  curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
  curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);
  $content  = curl_exec($soap_do);
  if(curl_exec($soap_do) === false) {
    $err = 'Curl error: ' . curl_error($soap_do);
    curl_close($soap_do);
    print $err;
  } else {
    curl_close($soap_do);
    print_r($content);
  }
?>

I can see the error is referring to the header for: "SOAPAction: \\"run\\"", however im not sure what i am meant to have in its place.

Hopefully someone can assist me.

if you don't know how to use the native PHP SoapClient class (which is the best way to consume SOAP in PHP) then use a WSDL to php generator that will wrap all things up in structured classes so you won't wonder if you're doing wrong anywhere. And if there is an error, you'll identify it precisely. I can't propose anything else than the PackageGenerator project

Try to change SOAPAction header to

"SOAPAction: \\" https://px.ezidebit.com.au/INonPCIService/GetCustomerList \\""

In WSDL of this service you can find

<wsdl:operation name="GetCustomerList"><wsdl:input wsaw:Action="https://px.ezidebit.com.au/INonPCIService/GetCustomerList"

And now code:

$soap_request ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:px="https://px.ezidebit.com.au/">
               <soapenv:Header/>
               <soapenv:Body>
                  <px:GetCustomerList>
                  <px:DigitalKey>000000000000000</px:DigitalKey>
                     <px:CustomerStatus>ALL</px:CustomerStatus>
                     <px:OrderBy>EzidebitCustomerID</px:OrderBy>
                     <px:Order>ASC</px:Order>
                     <px:PageNumber>1</px:PageNumber> 
                  </px:GetCustomerList>
               </soapenv:Body>
            </soapenv:Envelope>';

    $header = array(
        "Content-type: text/xml;charset=\"utf-8\"",
        "Accept: text/xml",
        "Cache-Control: no-cache",
        "Pragma: no-cache",
        "SOAPAction: \"https://px.ezidebit.com.au/INonPCIService/GetCustomerList\"",
        "Content-length: ".strlen($soap_request),
    );

    $soap_do = curl_init();
    curl_setopt($soap_do, CURLOPT_URL, "https://api.ezidebit.com.au/v3-5/nonpci" );
    curl_setopt($soap_do, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($soap_do, CURLOPT_TIMEOUT,        10);
    curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);

    curl_setopt($soap_do, CURLOPT_POST,           true );
    curl_setopt($soap_do, CURLOPT_POSTFIELDS,     $soap_request);
    curl_setopt($soap_do, CURLOPT_HTTPHEADER,     $header);
    $content  = curl_exec($soap_do);
    if(curl_exec($soap_do) === false) {
        $err = 'Curl error: ' . curl_error($soap_do);
        curl_close($soap_do);
        print $err;
    } else {
        curl_close($soap_do);
        print_r($content);
    }

gives an error

Invalid DigitalKey.

And the same with SoapClient:

$wsdl = 'https://api.demo.ezidebit.com.au/v3-5/nonpci?wsdl';
    $client = new SoapClient($wsdl, array('soap_version' => SOAP_1_1, 'trace' => 1, "exceptions" => 0));

    $params = [
        'DigitalKey' => '8591BFD4-E7C8-4284-84F7-E6C419114FA8',
        'CustomerStatus' => 'ALL',
        'OrderBy' => 'EzidebitCustomerID',
        'Order' => 'ASC',
        'PageNumber' => 1
    ];

    $result = $client->__soapCall('GetCustomerList', [$params]);


    print_r($client->__getLastRequest());
    echo PHP_EOL;
    print_r($result);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM