DHL-PHP-SDK  v0.4
A wrapper for the DHL-XML-API Version 2
ShipmentDetails.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Petschko\DHL;
4 
16 use stdClass;
17 
29  const PALETTE = 'PL';
30 
36  const PACKAGE = 'PK';
37 
56  const PRODUCT_TYPE_EUROPA_PACKAGE = 'V54EPAK';
57  const PRODUCT_TYPE_PACKED_CONNECT = 'V55PAK';
61  const PRODUCT_TYPE_AUSTRIA_PACKAGE = 'V86PARCEL';
63  const PRODUCT_TYPE_CONNECT_PACKAGE = 'V87PARCEL';
64 
83  private $product = self::PRODUCT_TYPE_NATIONAL_PACKAGE;
84 
99  private $accountNumber;
100 
111  private $customerReference = null;
112 
123  private $shipmentDate = null;
124 
135  private $returnAccountNumber = null;
136 
147  private $returnReference = null;
148 
154  private $weight = 5.0;
155 
163  private $length = null;
164 
172  private $width = null;
173 
181  private $height = null;
182 
190  private $service = null;
191 
205  private $packageType = self::PACKAGE;
206 
214  private $notificationEmail = null;
215 
223  private $bank = null;
224 
230  public function __construct($accountNumber) {
231  $this->setAccountNumber($accountNumber);
232  }
233 
237  public function __destruct() {
238  unset($this->product);
239  unset($this->accountNumber);
240  unset($this->customerReference);
241  unset($this->shipmentDate);
242  unset($this->returnAccountNumber);
243  unset($this->returnReference);
244  unset($this->weight);
245  unset($this->length);
246  unset($this->width);
247  unset($this->height);
248  unset($this->service);
249  unset($this->packageType);
250  unset($this->notificationEmail);
251  unset($this->bank);
252  }
253 
272  public function getProduct() {
273  return $this->product;
274  }
275 
294  public function setProduct($product) {
295  $this->product = $product;
296  }
297 
307  private function getAccountNumber() {
308  return $this->accountNumber;
309  }
310 
320  private function setAccountNumber($accountNumber) {
321  $this->accountNumber = $accountNumber;
322  }
323 
329  public function getCustomerReference() {
330  return $this->customerReference;
331  }
332 
338  public function setCustomerReference($customerReference) {
339  $this->customerReference = $customerReference;
340  }
341 
347  public function getShipmentDate() {
348  if($this->shipmentDate === null)
349  $this->setShipmentDate($this->createDefaultShipmentDate());
350 
351  return $this->shipmentDate;
352  }
353 
360  public function setShipmentDate($shipmentDate, $useIntTime = false) {
361  if($useIntTime) {
362  // Convert Time-Stamp to Date
363  $shipmentDate = date('Y-m-d', $shipmentDate);
364 
365  if($shipmentDate === false)
366  $shipmentDate = null;
367  }
368 
369  $this->shipmentDate = $shipmentDate;
370  }
371 
377  public function getReturnAccountNumber() {
378  return $this->returnAccountNumber;
379  }
380 
386  public function setReturnAccountNumber($returnAccountNumber) {
387  $this->returnAccountNumber = $returnAccountNumber;
388  }
389 
395  public function getReturnReference() {
396  return $this->returnReference;
397  }
398 
404  public function setReturnReference($returnReference) {
405  $this->returnReference = $returnReference;
406  }
407 
413  public function getWeight() {
414  return $this->weight;
415  }
416 
422  public function setWeight($weight) {
423  $this->weight = $weight;
424  }
425 
431  public function getLength() {
432  return $this->length;
433  }
434 
440  public function setLength($length) {
441  $this->length = $length;
442  }
443 
449  public function getWidth() {
450  return $this->width;
451  }
452 
458  public function setWidth($width) {
459  $this->width = $width;
460  }
461 
467  public function getHeight() {
468  return $this->height;
469  }
470 
476  public function setHeight($height) {
477  $this->height = $height;
478  }
479 
485  public function getService() {
486  return $this->service;
487  }
488 
494  public function setService($service) {
495  $this->service = $service;
496  }
497 
509  public function getPackageType() {
510  trigger_error('[DHL-PHP-SDK]: Version 1 Methods are deprecated and will removed soon (Called method ' . __METHOD__ . ')!', E_USER_DEPRECATED);
511 
512  return $this->packageType;
513  }
514 
526  public function setPackageType($packageType) {
527  trigger_error('[DHL-PHP-SDK]: Version 1 Methods are deprecated and will removed soon (Called method ' . __METHOD__ . ')!', E_USER_DEPRECATED);
528 
529  $this->packageType = $packageType;
530  }
531 
537  public function getNotificationEmail() {
538  return $this->notificationEmail;
539  }
540 
546  public function setNotificationEmail($notificationEmail) {
547  $this->notificationEmail = $notificationEmail;
548  }
549 
555  public function getBank() {
556  return $this->bank;
557  }
558 
564  public function setBank($bank) {
565  $this->bank = $bank;
566  }
567 
573  private function createDefaultShipmentDate() {
574  $now = time();
575  $weekDay = date('w', $now);
576 
577  if($weekDay === 0)
578  $now += 86400; // Increase Day by 1 if Sunday
579 
580  return date('Y-m-d', $now);
581  }
582 
590  public function getShipmentDetailsClass_v1() {
591  trigger_error('[DHL-PHP-SDK]: Version 1 Methods are deprecated and will removed soon (Called method ' . __METHOD__ . ')!', E_USER_DEPRECATED);
592  trigger_error('[DHL-PHP-SDK]: Called Version 1 Method: ' . __METHOD__ . ' is incomplete (does nothing)!', E_USER_WARNING);
593 
594  return new StdClass;
595  }
596 
602  public function getShipmentDetailsClass_v2() {
603  $class = new StdClass;
604 
605  $class->product = $this->getProduct();
606  $class->accountNumber = $this->getAccountNumber();
607  if($this->getCustomerReference() !== null)
608  $class->customerReference = $this->getCustomerReference();
609  $class->shipmentDate = $this->getShipmentDate();
610  if($this->getReturnAccountNumber() !== null)
611  $class->returnShipmentAccountNumber = $this->getReturnAccountNumber();
612  if($this->getReturnReference() !== null)
613  $class->returnShipmentReference = $this->getReturnReference();
614 
615  $class->ShipmentItem = new StdClass;
616  $class->ShipmentItem->weightInKG = $this->getWeight();
617  if($this->getLength() !== null)
618  $class->ShipmentItem->lengthInCM = $this->getLength();
619  if($this->getWidth() !== null)
620  $class->ShipmentItem->widthInCM = $this->getWidth();
621  if($this->getHeight() !== null)
622  $class->ShipmentItem->heightInCM = $this->getHeight();
623 
624  if($this->getService() !== null)
625  $class->Service = $this->getService()->getServiceClass_v2($this->getProduct());
626 
627  if($this->getNotificationEmail() !== null) {
628  $class->Notification = new StdClass;
629  $class->Notification->recipientEmailAddress = $this->getNotificationEmail();
630  }
631 
632  if($this->getBank() !== null)
633  $class->BankData = $this->getBank()->getBankClass_v2();
634 
635  return $class;
636  }
637 }
setCustomerReference($customerReference)
setReturnReference($returnReference)
setReturnAccountNumber($returnAccountNumber)
setShipmentDate($shipmentDate, $useIntTime=false)
setNotificationEmail($notificationEmail)