30 const DHL_WSDL_LIB_URL =
'https://cig.dhl.de/cig-wsdls/com/dpdhl/wsdl/geschaeftskundenversand-api/';
73 private $soapClient = null;
80 private $errors = array();
105 private $credentials;
114 private $shipmentDetails;
125 private $service = null;
136 private $bank = null;
145 private $sender = null;
154 private $receiver = null;
165 private $returnReceiver = null;
176 private $exportDocument = null;
189 private $sequenceNumber =
'1';
202 private $receiverEmail = null;
213 private $printOnlyIfReceiverIsValid = null;
225 private $labelResponseType = null;
234 private $shipmentOrders = array();
241 private $customAPIURL = null;
261 $this->setTest(((
$testMode) ?
true :
false));
264 if($this->isTest()) {
266 $c->setApiUser($credentials->getApiUser());
267 $c->setApiPassword($credentials->getApiPassword());
275 $this->shipmentDetails =
new ShipmentDetails($credentials->getEkp(10) .
'0101');
282 parent::__destruct();
283 unset($this->soapClient);
284 unset($this->errors);
287 unset($this->credentials);
288 unset($this->shipmentDetails);
289 unset($this->service);
291 unset($this->sender);
292 unset($this->receiver);
293 unset($this->returnReceiver);
294 unset($this->exportDocument);
295 unset($this->sequenceNumber);
296 unset($this->receiverEmail);
297 unset($this->printOnlyIfReceiverIsValid);
298 unset($this->labelResponseType);
299 unset($this->shipmentOrders);
300 unset($this->customAPIURL);
313 return self::DHL_WSDL_LIB_URL . $this->
getVersion() .
'/geschaeftskundenversand-api-' . $this->
getVersion() .
'.wsdl';
321 private function getSoapClient() {
322 if($this->soapClient === null)
323 $this->buildSoapClient();
325 return $this->soapClient;
334 if($this->soapClient === null)
337 return $this->getSoapClient()->__getLastRequest();
345 private function setSoapClient($soapClient) {
346 $this->soapClient = $soapClient;
355 return $this->errors;
364 $this->errors = $errors;
372 private function addError($error) {
373 $this->errors[] = $error;
381 private function isTest() {
390 private function setTest($test) {
417 private function getCredentials() {
418 return $this->credentials;
427 $this->credentials = $credentials;
439 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
440 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
441 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
445 return $this->shipmentDetails;
457 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
458 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
459 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
463 $this->shipmentDetails = $shipmentDetails;
475 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
476 ' These details belong to the `ShipmentDetails` Object, please do/get them there and assign the' .
477 ' `ShipmentDetails` Object to the `ShipmentOrder` Object by using `setShipmentDetails($shipmentDetails)`' .
478 ' on the Shipment instance!',
482 return $this->service;
494 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
495 ' These details belong to the `ShipmentDetails` Object, please do/get them there and assign the' .
496 ' `ShipmentDetails` Object to the `ShipmentOrder` Object by using `setShipmentDetails($shipmentDetails)`' .
497 ' on the Shipment instance!',
501 $this->service = $service;
513 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
514 ' These details belong to the `ShipmentDetails` Object, please do/get them there and assign the' .
515 ' `ShipmentDetails` Object to the `ShipmentOrder` Object by using `setShipmentDetails($shipmentDetails)`' .
516 ' on the Shipment instance!',
532 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
533 ' These details belong to the `ShipmentDetails` Object, please do/get them there and assign the' .
534 ' `ShipmentDetails` Object to the `ShipmentOrder` Object by using `setShipmentDetails($shipmentDetails)`' .
535 ' on the Shipment instance!',
551 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
552 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
553 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
557 return $this->sender;
569 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
570 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
571 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
575 $this->sender = $sender;
587 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
588 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
589 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
593 return $this->receiver;
605 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
606 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
607 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
611 $this->receiver = $receiver;
625 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
626 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
627 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
631 return $this->returnReceiver;
645 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
646 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
647 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
651 $this->returnReceiver = $returnReceiver;
663 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
664 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
665 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
669 return $this->exportDocument;
681 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
682 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
683 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
687 $this->exportDocument = $exportDocument;
699 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
700 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
701 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
705 return $this->sequenceNumber;
717 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
718 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
719 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
723 $this->sequenceNumber = $sequenceNumber;
734 trigger_error(
'[DHL-PHP-SDK]: Called deprecated method ' . __METHOD__ .
' in class ' . __CLASS__ .
735 '. The notification E-Mail (or receiver E-Mail) was moved into the ShipmentDetail class!' .
736 ' Please use the new function, this here will removed in the future!', E_USER_DEPRECATED);
738 return $this->receiverEmail;
749 trigger_error(
'[DHL-PHP-SDK]: Called deprecated method ' . __METHOD__ .
' in class ' . __CLASS__ .
750 '. The notification E-Mail (or receiver E-Mail) was moved into the ShipmentDetail class!' .
751 ' Please use the new function, this here will removed in the future!', E_USER_DEPRECATED);
753 $this->receiverEmail = $receiverEmail;
765 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
766 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
767 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
771 return $this->printOnlyIfReceiverIsValid;
785 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
786 ' These details belong to the `ShipmentOrder` Object, please do/get them there and assign the' .
787 ' `ShipmentOrder` Object to this Object by using `addShipmentOrder($shipmentOrder)` on this instance!',
791 $this->printOnlyIfReceiverIsValid = $printOnlyIfReceiverIsValid;
800 return $this->labelResponseType;
809 $this->labelResponseType = $labelResponseType;
818 return $this->shipmentOrders;
827 if(! is_array($shipmentOrders)) {
829 '[DHL-PHP-SDK]: The type of $shipmentOrders is NOT an array, but is required to set as array! Called method ' .
830 __METHOD__ .
' in class ' . __CLASS__,
833 $this->addError(__METHOD__ .
': Non-Array value given');
838 $this->shipmentOrders = $shipmentOrders;
872 return $this->customAPIURL;
881 $this->customAPIURL = $customAPIURL;
891 private function checkRequestCount($array, $action, $maxReq = self::MAX_DHL_REQUESTS) {
892 $count = count($array);
894 if($count > self::MAX_DHL_REQUESTS)
895 $this->addError(
'There are only ' . $maxReq .
' Request/s for one call allowed for the action "' 896 . $action .
'"! You tried to request ' . $count .
' ones');
905 private function log($message, $errorLevel = E_USER_NOTICE) {
907 if(is_array($message) || is_object($message))
908 error_log(print_r($message,
true), $errorLevel);
910 error_log($message, $errorLevel);
919 private function buildAuthHeader() {
920 $auth_params = array(
921 'user' => $this->getCredentials()->getUser(),
922 'signature' => $this->getCredentials()->getSignature(),
926 return new SoapHeader(self::DHL_SOAP_HEADER_URI,
'Authentification', $auth_params);
932 private function buildSoapClient() {
933 $header = $this->buildAuthHeader();
936 $location = self::DHL_SANDBOX_URL;
938 $location = self::DHL_PRODUCTION_URL;
940 $auth_params = array(
941 'login' => $this->getCredentials()->getApiUser(),
942 'password' => $this->getCredentials()->getApiPassword(),
943 'location' => $location,
947 $this->log($auth_params);
949 $this->getSoapClient()->__setSoapHeaders($header);
950 $this->log($this->getSoapClient());
961 public function getVersion($viaSOAP =
false, $getBuildNumber =
false, $returnAsArray =
false) {
965 'mayor' => parent::getMayor(),
966 'minor' => parent::getMinor()
969 return parent::getVersion();
974 trigger_error(
'[DHL-PHP-SDK]: Called Version 1 Method: ' . __METHOD__ .
' is incomplete (does nothing)!', E_USER_WARNING);
975 $this->addError(
'Version 1 SOAP-Method "' . __METHOD__ .
'" is not implemented or removed!');
984 $response = $this->sendGetVersionRequest($data);
986 $this->addError($e->getMessage());
998 'mayor' =>
$response->Version->majorRelease,
999 'minor' =>
$response->Version->minorRelease,
1004 (($getBuildNumber) ?
'.' .
$response->Version->build :
'');
1014 private function sendGetVersionRequest($data) {
1015 return $this->getSoapClient()->getVersion($data);
1024 private function sendDoManifestRequest($data) {
1027 return $this->getSoapClient()->DoManifestTD($data);
1030 return $this->getSoapClient()->doManifest($data);
1043 $data = $this->createDoManifestClass_v1($shipmentNumbers);
1047 $data = $this->createDoManifestClass_v2($shipmentNumbers);
1051 $response = $this->sendDoManifestRequest($data);
1053 $this->addError($e->getMessage());
1059 $this->addError(
$response->faultstring);
1074 private function createDoManifestClass_v1($shipmentNumbers) {
1075 trigger_error(
'[DHL-PHP-SDK]: Version 1 Methods are deprecated and will removed soon (Called method ' . __METHOD__ .
')!', E_USER_DEPRECATED);
1076 trigger_error(
'[DHL-PHP-SDK]: Called Version 1 Method: ' . __METHOD__ .
' is incomplete (does nothing)!', E_USER_WARNING);
1078 $data =
new StdClass;
1089 private function createDoManifestClass_v2($shipmentNumbers) {
1090 $data =
new StdClass;
1094 if(is_array($shipmentNumbers)) {
1095 $this->checkRequestCount($shipmentNumbers,
'doManifest');
1097 foreach($shipmentNumbers as $key => &$number)
1098 $data->shipmentNumber[$key] = $number;
1100 $data->shipmentNumber = $shipmentNumbers;
1115 $oldDate = $manifestDate;
1116 $manifestDate = date(
'Y-m-d', $manifestDate);
1118 if($manifestDate ===
false) {
1119 $this->addError(
'Could not convert given time() value "' . $oldDate .
'" to YYYY-MM-DD... Called method: ' . __METHOD__);
1129 trigger_error(
'[DHL-PHP-SDK]: Called Version 1 Method: ' . __METHOD__ .
' is incomplete (does nothing)!', E_USER_WARNING);
1130 $this->addError(
'Version 1 Method "' . __METHOD__ .
'" is not implemented or removed!');
1135 $data = $this->createGetManifestClass_v2($manifestDate);
1139 $response = $this->sendGetManifestRequest($data);
1141 $this->addError($e->getMessage());
1147 $this->addError(
$response->faultstring);
1160 private function createGetManifestClass_v2($manifestDate) {
1161 $data =
new StdClass;
1163 if(is_array($manifestDate))
1164 $this->addError(
'You can only request 1 date on getManifest - multiple requests in 1 call are not allowed here');
1167 $data->manifestDate = $manifestDate;
1178 private function sendGetManifestRequest($data) {
1179 return $this->getSoapClient()->getManifest($data);
1188 private function sendCreateRequest($data) {
1191 return $this->getSoapClient()->CreateShipmentDD($data);
1194 return $this->getSoapClient()->createShipmentOrder($data);
1217 $data = $this->createShipmentClass_v1();
1222 $data = $this->createShipmentClass_v2_legacy();
1224 $data = $this->createShipmentClass_v2();
1231 $response = $this->sendCreateRequest($data);
1233 $this->addError($e->getMessage());
1239 $this->addError(
$response->faultstring);
1253 private function createShipmentClass_v1() {
1254 trigger_error(
'[DHL-PHP-SDK]: Version 1 Methods are deprecated and will removed soon (Called method ' . __METHOD__ .
')!', E_USER_DEPRECATED);
1255 trigger_error(
'[DHL-PHP-SDK]: Called Version 1 Method: ' . __METHOD__ .
' is incomplete (does nothing)!', E_USER_WARNING);
1257 $data =
new StdClass;
1267 private function createShipmentClass_v2() {
1270 $this->checkRequestCount($shipmentOrders,
'createShipmentClass');
1272 $data =
new StdClass;
1281 $shipmentOrder->setLabelResponseType($this->getLabelResponseType());
1283 $data->ShipmentOrder[$key] =
$shipmentOrder->getShipmentOrderClass_v2();
1296 private function createShipmentClass_v2_legacy() {
1298 '[DHL-PHP-SDK]: ' . __CLASS__ .
'->' . __METHOD__ .
1299 ' This method was called for Backward-Compatibility, please create `ShipmentOrder` Objects' .
1300 ' and assign them with `addShipmentOrder($shipmentOrder)` on this instance.',
1309 $data =
new StdClass;
1311 $data->ShipmentOrder =
new StdClass;
1315 $data->ShipmentOrder->Shipment =
new StdClass;
1316 $data->ShipmentOrder->Shipment->ShipmentDetails = $this->
getShipmentDetails()->getShipmentDetailsClass_v2();
1320 if($this->
getShipmentDetails()->getNotificationEmail() === null && $this->receiverEmail !== null)
1323 if($email !== null) {
1324 $data->ShipmentOrder->Shipment->ShipmentDetails->Notification =
new StdClass;
1325 $data->ShipmentOrder->Shipment->ShipmentDetails->Notification->recipientEmailAddress = $email;
1329 $data->ShipmentOrder->Shipment->Shipper = $this->
getSender()->getClass_v2();
1332 $data->ShipmentOrder->Shipment->Receiver = $this->
getReceiver()->getClass_v2();
1336 $data->ShipmentOrder->Shipment->ReturnReceiver = $this->
getReturnReceiver()->getClass_v2();
1341 $data->ShipmentOrder->Shipment->ExportDocument = $this->
getExportDocument()->getExportDocumentClass_v2();
1343 $this->addError($e->getMessage());
1349 $data->ShipmentOrder->PrintOnlyIfCodeable =
new StdClass;
1353 $data->ShipmentOrder->labelResponseType = $this->getLabelResponseType();
1364 private function sendDeleteRequest($data) {
1367 return $this->getSoapClient()->DeleteShipmentDD($data);
1370 return $this->getSoapClient()->deleteShipmentOrder($data);
1395 $data = $this->createDeleteClass_v1($shipmentNumbers);
1399 $data = $this->createDeleteClass_v2($shipmentNumbers);
1403 $response = $this->sendDeleteRequest($data);
1405 $this->addError($e->getMessage());
1411 $this->addError(
$response->faultstring);
1426 private function createDeleteClass_v1($shipmentNumbers) {
1427 trigger_error(
'[DHL-PHP-SDK]: Version 1 Methods are deprecated and will removed soon (Called method ' . __METHOD__ .
')!', E_USER_DEPRECATED);
1428 trigger_error(
'[DHL-PHP-SDK]: Called Version 1 Method: ' . __METHOD__ .
' is incomplete (does nothing)!', E_USER_WARNING);
1430 $data =
new StdClass;
1441 private function createDeleteClass_v2($shipmentNumbers) {
1442 $data =
new StdClass;
1446 if(is_array($shipmentNumbers)) {
1447 $this->checkRequestCount($shipmentNumbers,
'deleteShipmentOrder');
1449 foreach($shipmentNumbers as $key => &$number)
1450 $data->shipmentNumber[$key] = $number;
1452 $data->shipmentNumber = $shipmentNumbers;
1463 private function sendGetLabelRequest($data) {
1466 return $this->getSoapClient()->getLabelDD($data);
1469 return $this->getSoapClient()->getLabel($data);
1482 return $this->
getLabel($shipmentNumbers);
1494 $data = $this->getLabelClass_v1($shipmentNumbers);
1498 $data = $this->getLabelClass_v2($shipmentNumbers);
1502 $response = $this->sendGetLabelRequest($data);
1504 $this->addError($e->getMessage());
1510 $this->addError(
$response->faultstring);
1525 private function getLabelClass_v1($shipmentNumbers) {
1526 trigger_error(
'[DHL-PHP-SDK]: Version 1 Methods are deprecated and will removed soon (Called method ' . __METHOD__ .
')!', E_USER_DEPRECATED);
1527 trigger_error(
'[DHL-PHP-SDK]: Called Version 1 Method: ' . __METHOD__ .
' is incomplete (does nothing)!', E_USER_WARNING);
1529 $data =
new StdClass;
1540 private function getLabelClass_v2($shipmentNumbers) {
1541 $data =
new StdClass;
1545 if(is_array($shipmentNumbers)) {
1546 $this->checkRequestCount($shipmentNumbers,
'getLabel');
1548 foreach($shipmentNumbers as $key => &$number)
1549 $data->shipmentNumber[$key] = $number;
1551 $data->shipmentNumber = $shipmentNumbers;
1565 private function sendGetExportDocRequest($data) {
1568 return $this->getSoapClient()->getExportDocDD($data);
1571 return $this->getSoapClient()->getExportDoc($data);
1584 $data = $this->getExportDocClass_v1($shipmentNumbers);
1588 $data = $this->getExportDocClass_v2($shipmentNumbers);
1592 $response = $this->sendGetExportDocRequest($data);
1594 $this->addError($e->getMessage());
1600 $this->addError(
$response->faultstring);
1615 private function getExportDocClass_v1($shipmentNumbers) {
1616 trigger_error(
'[DHL-PHP-SDK]: Version 1 Methods are deprecated and will removed soon (Called method ' . __METHOD__ .
')!', E_USER_DEPRECATED);
1617 trigger_error(
'[DHL-PHP-SDK]: Called Version 1 Method: ' . __METHOD__ .
' is incomplete (does nothing)!', E_USER_WARNING);
1619 $data =
new StdClass;
1630 private function getExportDocClass_v2($shipmentNumbers) {
1631 $data =
new StdClass;
1635 if(is_array($shipmentNumbers)) {
1636 $this->checkRequestCount($shipmentNumbers,
'getExportDoc');
1638 foreach($shipmentNumbers as $key => &$number)
1639 $data->shipmentNumber[$key] = $number;
1641 $data->shipmentNumber = $shipmentNumbers;
1661 $data = $this->createShipmentClass_v2();
1665 $response = $this->sendValidateShipmentRequest($data);
1667 $this->addError($e->getMessage());
1673 $this->addError(
$response->faultstring);
1687 private function sendValidateShipmentRequest($data) {
1690 throw new Exception(__FUNCTION__ .
': Method doesn\'t exists for Version 1!');
1693 return $this->getSoapClient()->validateShipment($data);
deleteShipment($shipmentNumbers)
deleteShipmentOrder($shipmentNumbers)
setCustomAPIURL($customAPIURL)
getLabel($shipmentNumbers)
setPrintOnlyIfReceiverIsValid($printOnlyIfReceiverIsValid)
addShipmentOrder($shipmentOrder)
setReturnReceiver($returnReceiver)
__construct($credentials, $testMode=false, $version=null)
setSequenceNumber($sequenceNumber)
getVersion($viaSOAP=false, $getBuildNumber=false, $returnAsArray=false)
getPrintOnlyIfReceiverIsValid()
getManifest($manifestDate, $useIntTime=false)
getShipmentLabel($shipmentNumbers)
setShipmentDetails($shipmentDetails)
setCredentials($credentials)
setLabelResponseType($labelResponseType)
setReceiverEmail($receiverEmail)
setShipmentOrders($shipmentOrders)
getExportDoc($shipmentNumbers)
setExportDocument($exportDocument)
doManifest($shipmentNumbers)
const DHL_SOAP_HEADER_URI