From 8476f152fabf31e4d9e4fa6d687001e296a28f47 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 13 Jul 2021 11:29:51 +0100 Subject: [PATCH] add extra fields --- src/DTO/Address.php | 17 +++++++++++++++++ src/DTO/ShipmentCreator.php | 29 ++++++++++++++++++++++++++++- src/Exceptions/AddressException.php | 13 +++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/Exceptions/AddressException.php diff --git a/src/DTO/Address.php b/src/DTO/Address.php index 1e65b55..3abfe3e 100644 --- a/src/DTO/Address.php +++ b/src/DTO/Address.php @@ -2,6 +2,8 @@ namespace Booni3\DhlExpressRest\DTO; +use Booni3\DhlExpressRest\AddressException; + class Address { protected $customer = []; @@ -15,6 +17,7 @@ public function __construct( string $city, string $postcode, string $countrycode, + string $typecode, string $company = '-', string $phone = '-', string $email = 'a@b.com' @@ -34,6 +37,7 @@ public function __construct( 'fullName' => $name, 'email' => $email, ], + 'typeCode' => $this->validateTypeCode($typecode) ]; } @@ -97,8 +101,21 @@ protected function registrationNumbers() ]; } + public function getCityName() + { + return $this->customer['postalAddress']['cityName']; + } + public function getCountryCode() { return $this->customer['postalAddress']['countryCode']; } + + protected function validateTypeCode(string $typeCode){ + if(! in_array($typeCode, ['business', 'direct_consumer'])){ + throw AddressException::validationException('typeCode'); + } + + return $typeCode; + } } diff --git a/src/DTO/ShipmentCreator.php b/src/DTO/ShipmentCreator.php index ddf2d6b..816b9cb 100644 --- a/src/DTO/ShipmentCreator.php +++ b/src/DTO/ShipmentCreator.php @@ -26,9 +26,12 @@ class ShipmentCreator protected array $exportLineItems = []; protected int $lineItemNumber = 1; protected array $invoice = []; + protected array $additionalCharges = []; protected ?float $declaredValue = null; protected string $declaredValueCurrency = 'GBP'; protected string $exportReason = 'sale'; + protected string $exportReasonType = 'permanent'; + protected string $placeOfIncoterm = ''; protected bool $paperless = false; protected ?string $labelFormat = null; @@ -221,6 +224,7 @@ public function outputImage(): array 'typeCode' => 'invoice', 'isRequested' => $this->customsDeclarable, 'invoiceType' => 'commercial', + 'templateName' => 'COMMERCIAL_INVOICE_P_10', ], [ 'typeCode' => 'label', @@ -231,11 +235,13 @@ public function outputImage(): array ]; } - public function setExportDeclaration($reason = 'sale', $declaredValueCurrency = 'GBP', $declaredValue = null) + public function setExportDeclaration($reason = 'sale', $reasonType = 'permanent', $declaredValueCurrency = 'GBP', $declaredValue = null, $placeOfIncoterm = '') { $this->exportReason = $reason; + $this->exportReasonType = $reasonType; $this->declaredValueCurrency = $declaredValueCurrency; $this->declaredValue = $declaredValue; + $this->placeOfIncoterm = $placeOfIncoterm; } public function exportDeclaration() @@ -251,7 +257,10 @@ public function exportDeclaration() 'exportDeclaration' => [ 'lineItems' => $this->exportLineItems(), 'invoice' => $this->invoice(), + 'additionalCharges' => $this->additionalCharges(), 'exportReason' => $this->exportReason, + 'exportReasonType' => $this->exportReasonType, + 'placeOfIncoterm' => $this->placeOfIncoterm ?: $this->receiver->getCityName() ], ]; } @@ -293,6 +302,24 @@ protected function invoice(): array return $this->invoice; } + public function setFreightCost($freightCost) { + $this->additionalCharges['freight_cost'] = $freightCost; + } + + protected function additionalCharges(): array + { + $array = []; + + if(isset($this->additionalCharges['freight_cost'])){ + $array[] = [ + 'value' => $this->additionalCharges['freight_cost'], + 'typeCode' => 'freight' + ]; + } + + return $array; + } + protected function declaredValueFromItems($items): float { return array_reduce($items, function ($i, $row) { diff --git a/src/Exceptions/AddressException.php b/src/Exceptions/AddressException.php new file mode 100644 index 0000000..e711d22 --- /dev/null +++ b/src/Exceptions/AddressException.php @@ -0,0 +1,13 @@ +