Skip to content

Commit

Permalink
DHLGW-1330: add support for recipient signature service
Browse files Browse the repository at this point in the history
  • Loading branch information
mam08ixo committed Jun 20, 2023
1 parent 2d10746 commit 48bf9b4
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 5 deletions.
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"require-dev": {
"ext-simplexml": "*",
"nyholm/psr7": "^1.0.0",
"php-http/curl-client": "^2.1.0",
"php-http/mock-client": "^1.5.0",
"phpunit/phpunit": "^8.0.0 || ^9.0.0",
"phpstan/phpstan": "^1.5.0",
Expand All @@ -54,5 +53,10 @@
"branch-alias": {
"dev-DHLGW-1275": "3.0.0.x-dev"
}
},
"config": {
"allow-plugins": {
"php-http/discovery": false
}
}
}
11 changes: 9 additions & 2 deletions src/Api/ShipmentOrderRequestBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,19 @@ public function setIdentCheck(
public function setParcelOutletRouting(string $email = null): ShipmentOrderRequestBuilderInterface;

/**
* Book the Postal Delivery Duty Paid (PDDP) service.
* Book the "Postal Delivery Duty Paid" (PDDP) service.
*
* @return ShipmentOrderRequestBuilderInterface
*/
public function setDeliveryDutyPaid(): ShipmentOrderRequestBuilderInterface;

/**
* Book the "Signed For By Recipient" service.
*
* @return ShipmentOrderRequestBuilderInterface
*/
public function setSignedForByRecipient(): ShipmentOrderRequestBuilderInterface;

/**
* Set customs details for international shipments.
*
Expand Down Expand Up @@ -577,7 +584,7 @@ public function setCustomsDetails(
bool $electronicExportNotification = null,
string $sendersCustomsReference = null,
string $addresseesCustomsReference = null
);
): ShipmentOrderRequestBuilderInterface;

/**
* Add a package item's customs details (optional).
Expand Down
14 changes: 13 additions & 1 deletion src/Model/ParcelDe/RequestType/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,19 @@ class Services implements \JsonSerializable
private $postalDeliveryDutyPaid;

/**
* Requires also DHL Retoure to be set
* Service for package return. Requires also DHL Retoure to be set.
*
* @var bool|null
*/
private $packagingReturn;

/**
* Delivery must be signed for by the recipient and not by DHL staff
*
* @var bool|null
*/
private $signedForByRecipient;

/**
* An email notification to the recipient that the shipment is closed (manifested).
*
Expand Down Expand Up @@ -255,6 +262,11 @@ public function setPackagingReturn(?bool $packagingReturn): void
$this->packagingReturn = $packagingReturn;
}

public function setSignedForByRecipient(?bool $signedForByRecipient): void
{
$this->signedForByRecipient = $signedForByRecipient;
}

/**
* @param \JsonSerializable|ShippingConfirmation|null $shippingConfirmation
* @return void
Expand Down
1 change: 1 addition & 0 deletions src/RequestBuilder/RestRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function create(): Shipment
$services->setNoNeighbourDelivery($this->data['services']['noNeighbourDelivery'] ?? null);
$services->setIndividualSenderRequirement($this->data['services']['individualSenderRequirement'] ?? null);
$services->setPackagingReturn($this->data['services']['packagingReturn'] ?? null);
$services->setSignedForByRecipient($this->data['services']['signedForByRecipient'] ?? null);
$services->setParcelOutletRouting($this->data['services']['parcelOutletRouting']['details'] ?? null);
$services->setPremium($this->data['services']['premium'] ?? null);
$services->setBulkyGoods($this->data['services']['bulkyGoods'] ?? null);
Expand Down
7 changes: 7 additions & 0 deletions src/RequestBuilder/ShipmentOrderRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ public function setDeliveryDutyPaid(): ShipmentOrderRequestBuilderInterface
return $this;
}

public function setSignedForByRecipient(): ShipmentOrderRequestBuilderInterface
{
$this->data['services']['signedForByRecipient'] = true;

return $this;
}

public function setCustomsDetails(
string $exportType,
string $placeOfCommital,
Expand Down
8 changes: 8 additions & 0 deletions src/RequestBuilder/SoapRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ public function create(): ShipmentOrderType
throw new RequestValidatorException($message);
}

if (isset($this->data['services']['signedForByRecipient'])) {
$message = sprintf(
ShipmentOrderRequestBuilderInterface::MSG_SERVICE_UNSUPPORTED,
'Signed for by recipient'
);
throw new RequestValidatorException($message);
}

$services = new ShipmentService();
if (isset($this->data['services']['dayOfDelivery'])) {
$config = new ServiceConfigurationDateOfDelivery(true, $this->data['services']['dayOfDelivery']);
Expand Down
2 changes: 2 additions & 0 deletions test/Expectation/Query/ArrayPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class ArrayPath
public const PATH_SERVICE_PREMIUM = 'services/premium';
public const PATH_SERVICE_CDP = 'services/closestDropPoint';
public const PATH_SERVICE_BULKY_GOODS = 'services/bulkyGoods';
public const PATH_SERVICE_SIGNED_BY_RECIPIENT = 'services/signedForByRecipient';
public const PATH_SERVICE_IDENT_LASTNAME = 'services/identCheck/lastName';
public const PATH_SERVICE_IDENT_FIRSTNAME = 'services/identCheck/firstName';
public const PATH_SERVICE_IDENT_DOB = 'services/identCheck/dateOfBirth';
Expand Down Expand Up @@ -319,6 +320,7 @@ public static function get(string $attribute): string
'premium' => self::PATH_SERVICE_PREMIUM,
'closestDropPoint' => self::PATH_SERVICE_CDP,
'bulkyGoods' => self::PATH_SERVICE_BULKY_GOODS,
'signedForByRecipient' => self::PATH_SERVICE_SIGNED_BY_RECIPIENT,
'identLastName' => self::PATH_SERVICE_IDENT_LASTNAME,
'identFirstName' => self::PATH_SERVICE_IDENT_FIRSTNAME,
'identDob' => self::PATH_SERVICE_IDENT_DOB,
Expand Down
2 changes: 2 additions & 0 deletions test/Expectation/Query/XPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class XPath
public const XPATH_SERVICE_RETURN_RECEIPT = './Shipment/ShipmentDetails/Service/ReturnReceipt/@active';
public const XPATH_SERVICE_PDDP = './Shipment/ShipmentDetails/Service/PDDP/@active';
public const XPATH_SERVICE_BULKY_GOODS = './Shipment/ShipmentDetails/Service/BulkyGoods/@active';
public const XPATH_SERVICE_SIGNED_BY_RECIPIENT = './Shipment/ShipmentDetails/Service/SignedForByRecipient/@active';
public const XPATH_SERVICE_IDENT_LASTNAME = './Shipment/ShipmentDetails/Service/IdentCheck/Ident/surname';
public const XPATH_SERVICE_IDENT_FIRSTNAME = './Shipment/ShipmentDetails/Service/IdentCheck/Ident/givenName';
public const XPATH_SERVICE_IDENT_DOB = './Shipment/ShipmentDetails/Service/IdentCheck/Ident/dateOfBirth';
Expand Down Expand Up @@ -296,6 +297,7 @@ public static function get(string $attribute): string
'returnReceipt' => self::XPATH_SERVICE_RETURN_RECEIPT,
'postalDeliveryDutyPaid' => self::XPATH_SERVICE_PDDP,
'bulkyGoods' => self::XPATH_SERVICE_BULKY_GOODS,
'signedForByRecipient' => self::XPATH_SERVICE_SIGNED_BY_RECIPIENT,
'identLastName' => self::XPATH_SERVICE_IDENT_LASTNAME,
'identFirstName' => self::XPATH_SERVICE_IDENT_FIRSTNAME,
'identDob' => self::XPATH_SERVICE_IDENT_DOB,
Expand Down
4 changes: 4 additions & 0 deletions test/Provider/RequestData/DomesticWithServices.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function get(): array
'namedPersonOnly' => true,
'returnReceipt' => true,
'bulkyGoods' => true,
'signedForByRecipient' => true,
// 'identLastName' => 'Smith',
// 'identFirstName' => 'Sam',
// 'identDob' => '1970-01-01',
Expand Down Expand Up @@ -222,6 +223,9 @@ protected function setBuilderData(ShipmentOrderRequestBuilderInterface $builder,
if (!empty($data['bulkyGoods'])) {
$builder->setBulkyGoods();
}
if (!empty($data['signedForByRecipient'])) {
$builder->setSignedForByRecipient();
}
// $builder->setIdentCheck(
// $data['identLastName'],
// $data['identFirstName'],
Expand Down
22 changes: 21 additions & 1 deletion test/TestCase/RequestBuilder/SoapRequestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,16 @@ public function createMultiShipmentRequest(

foreach ($requestData as $sequenceNumber => $data) {
$data->setSequenceNumber((string) $sequenceNumber);
$shipmentOrders[] = $data->createShipmentOrder($requestBuilder);
$shipmentOrders[] = $data->createShipmentOrder($requestBuilder, ['signedForByRecipient' => false]);
$requestValues[] = $data->get();
}

// send shipment orders to service
$service->createShipments($shipmentOrders);

// unset service that is not supported (and not booked) at the SOAP API.
unset($requestValues[1]['signedForByRecipient']);

// unset address data that are not transmitted with delivery location (post office) shipments
unset($requestValues[3]['recipientName']);
unset($requestValues[3]['recipientCountryCode']);
Expand Down Expand Up @@ -241,4 +244,21 @@ public function validationExceptionOnPoBoxConsignee()
$requestData = new POBox();
$requestData->createShipmentOrder($builder);
}

/**
* Assert that request builder throws exception if signature service is attempted to be booked via SOAP API.
*
* @test
* @throws RequestValidatorException
*/
public function validationExceptionOnSignedForByRecipientService()
{
$this->expectException(RequestValidatorException::class);
$regEx = str_replace('%s', '[\w\s]+', ShipmentOrderRequestBuilderInterface::MSG_SERVICE_UNSUPPORTED);
$this->expectExceptionMessageMatches("~$regEx~");

$builder = new ShipmentOrderRequestBuilder(self::REQUEST_TYPE);
$requestData = new DomesticWithServices();
$requestData->createShipmentOrder($builder);
}
}

0 comments on commit 48bf9b4

Please sign in to comment.