I'm working on a E-commerce site on which orders are placed. i want to track that delivery status of order and I need to give a status of order to user over mail.
I have to use Swiss Post Tracking Web Service API. Can anyone show me how to do so? I am new to SOAP WSDL.
From my understanding i did this now how to go further? My code below its just basic client i need to:
I need to track the delivery status
Below is my code
$wsdl = "https://webservices.post.ch:17005/IN_MYPBxTT/services/TrackAndTraceDFU.ws?WSDL
$username = 'username';
$password = 'password';
$trace = True;
$soapConfig = array(
'login'=>$username,
'password'=>$password,
'trace'=>$trace,
'keep_alive'=>TRUE,
'encoding'=>'utf8',
'connection_timeout'=>90,
);
$soapClient = new SoapClient($wsdl, $soapConfig);
try {
$xml = '<soapenv:Envelope xmlns:soapenv=“http://schemas.xmlsoap.org/soap/envelope/“
xmlns:req=“http://www.post.ch/npp/trackandtracews/v02/shipmentssearch/req“>
<soapenv:Header/>
<soapenv:Body>
<req:ShipmentsSearch>
<language>de</language>
<ShipmentNumbers>
<ShipmentNumber>99.60.122566.27198756</ShipmentNumber>
</ShipmentNumbers>
<Identity>?</Identity>
<Version>2.4</Version>
</req:ShipmentsSearch>
</soapenv:Body>
</soapenv:Envelope>';
$args = array(new SoapVar($xml, XSD_ANYXML));
$res = $this->_soapClient->__soapCall('ShipmentsSearch', $args);
return $res;
} catch (SoapFault $e) {
echo "Error: {$e}";
}
echo "<hr>Last Response";
echo "<pre>", htmlspecialchars($this->_soapClient->__getLastResponse()), "</pre>";
die;
I am using this code but getting below error
Error: SoapFault exception: [env:Client] Internal Error in /directory-name/ConsignmentWebService.php:114
Stack trace: #0 /directory-name/ConsignmentWebService.php(114): SoapClient->__soapCall('ShipmentsSearch', Array)
and get the response like this
Last Request
<?xml version='1.0' ?>
<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Body>
<env:Fault>
<faultcode>env:Client</faultcode>
<faultstring>Internal Error</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>
I referred this tutorial https://www.post.ch/en/business-solutions/digital-commerce/notification-services/sendungsinformationen
please help me I am new in soap
Updated Code who are looking for solution
$wsdl = "https://webservices.post.ch:17005/IN_MYPBxTT/services/TrackAndTraceDFU.ws?WSDL
$username = 'username';
$password = 'password';
$trace = True;
$soapConfig = array(
'login'=>$username,
'password'=>$password,
'trace'=>$trace,
'keep_alive'=>TRUE,
'encoding'=>'utf8',
'connection_timeout'=>90,
);
$soapClient = new SoapClient($wsdl, $soapConfig);
$response = null;
$generateRequest = array(
'language'=>'de',
'ShipmentNumbers'=>array(
'ShipmentNumber'=>$tracking_code, //your track code
),
'Identity'=>'?',
'Version'=>2.4
);
try {
$response = $this->_soapClient->ShipmentsSearch($generateRequest);
return $response;
} catch (SoapFault $fault) {
echo('Error in Getting Delivery Status: '. $fault->__toString() .'<br />');
echo '<pre>';
var_dump($this->_soapClient->__getLastResponse());
echo '</pre>';
die();
}