Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Add Tracking Error Details to SDK Response
Browse files Browse the repository at this point in the history
  • Loading branch information
Kadri Demir committed May 23, 2020
1 parent 42f4361 commit c48bd04
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
14 changes: 11 additions & 3 deletions src/Api/Data/Response/Tracking/TrackingInfoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Dhl\Express\Api\Data\Response\Tracking\TrackingInfo\PieceInterface;
use Dhl\Express\Api\Data\Response\Tracking\TrackingInfo\ShipmentDetailsInterface;
use Dhl\Express\Api\Data\Response\Tracking\TrackingInfo\ShipmentEventInterface;
use Dhl\Express\Webservice\Soap\Type\Tracking\ConditionCollection;

/**
* TrackingInfo class.
Expand Down Expand Up @@ -56,13 +55,22 @@ public function getShipmentEvents();
public function getPieces();

/**
* @return ConditionCollection
* @return string[]
*/
public function getAwbConditions();

/**
* @param ConditionCollection $awbConditions
* array of code=>message
* @param string[] $awbConditions
* @return self
*/
public function setAwbConditions($awbConditions);

/**
* @param string $conditionCode
* @param string $conditionDescription
* @return self
*/
public function addAwbConditions($conditionCode, $conditionDescription);

}
17 changes: 11 additions & 6 deletions src/Model/Response/Tracking/TrackingInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Dhl\Express\Api\Data\Response\Tracking\TrackingInfo\ShipmentDetailsInterface;
use Dhl\Express\Api\Data\Response\Tracking\TrackingInfo\ShipmentEventInterface;
use Dhl\Express\Api\Data\Response\Tracking\TrackingInfoInterface;
use Dhl\Express\Webservice\Soap\Type\Tracking\ConditionCollection;

/**
* TrackingInfo.
Expand All @@ -28,9 +27,11 @@ class TrackingInfo implements TrackingInfoInterface
*/
private $awbStatus;
/**
* @var ConditionCollection
* @var string[]
* code => message
* [101=>'error_description']
*/
private $awbConditions;
public $awbConditions = [];

/**
* @var ShipmentDetailsInterface
Expand All @@ -52,22 +53,19 @@ class TrackingInfo implements TrackingInfoInterface
*
* @param string $awbNumber
* @param string $awbStatus
* @param ConditionCollection $awbConditions
* @param ShipmentDetailsInterface $shipmentDetails
* @param ShipmentEventInterface[] $shipmentEvents
* @param PieceInterface[] $pieces
*/
public function __construct(
$awbNumber,
$awbStatus,
$awbConditions,
ShipmentDetailsInterface $shipmentDetails,
array $shipmentEvents,
array $pieces
) {
$this->awbNumber = $awbNumber;
$this->awbStatus = $awbStatus;
$this->awbConditions = $awbConditions;
$this->shipmentDetails = $shipmentDetails;
$this->shipmentEvents = $shipmentEvents;
$this->pieces = $pieces;
Expand Down Expand Up @@ -106,5 +104,12 @@ public function getAwbConditions()
public function setAwbConditions($awbConditions)
{
$this->awbConditions = $awbConditions;
return $this;
}

public function addAwbConditions($conditionCode, $conditionDescription)
{
$this->awbConditions[$conditionCode] = $conditionDescription;
return $this;
}
}
12 changes: 10 additions & 2 deletions src/Webservice/Soap/TypeMapper/TrackingResponseMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,22 @@ public function map(SoapTrackingResponse $soapTrackingResponse)
$shipmentEvents = [];
}

$trackingInfos[] = new TrackingInfo(
$trackingInfo = new TrackingInfo(
$soapTrackingItem->getAWBNumber(),
$soapTrackingItem->getStatus()->getActionStatus(),
$soapTrackingItem->getStatus()->getCondition(),
$shipmentDetails,
$shipmentEvents,
$trackingPieces
);
$conditions = $soapTrackingItem->getStatus()->getCondition();
if(empty($conditions)){
$conditions = [];
}
foreach ($conditions as $condition){
$trackingInfo->addAwbConditions($condition->getConditionCode(), $condition->getConditionData());
}

$trackingInfos[] = $trackingInfo;
}

$time = strtotime($soapResponseContent->getResponse()->getServiceHeader()->getMessageTime());
Expand Down

0 comments on commit c48bd04

Please sign in to comment.