Skip to content

Commit

Permalink
add extra fields
Browse files Browse the repository at this point in the history
  • Loading branch information
booni3 committed Jul 13, 2021
1 parent 1aa92d7 commit 8476f15
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/DTO/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Booni3\DhlExpressRest\DTO;

use Booni3\DhlExpressRest\AddressException;

class Address
{
protected $customer = [];
Expand All @@ -15,6 +17,7 @@ public function __construct(
string $city,
string $postcode,
string $countrycode,
string $typecode,
string $company = '-',
string $phone = '-',
string $email = '[email protected]'
Expand All @@ -34,6 +37,7 @@ public function __construct(
'fullName' => $name,
'email' => $email,
],
'typeCode' => $this->validateTypeCode($typecode)
];
}

Expand Down Expand Up @@ -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;
}
}
29 changes: 28 additions & 1 deletion src/DTO/ShipmentCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -221,6 +224,7 @@ public function outputImage(): array
'typeCode' => 'invoice',
'isRequested' => $this->customsDeclarable,
'invoiceType' => 'commercial',
'templateName' => 'COMMERCIAL_INVOICE_P_10',
],
[
'typeCode' => 'label',
Expand All @@ -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()
Expand All @@ -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()
],
];
}
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions src/Exceptions/AddressException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php


namespace Booni3\DhlExpressRest;


class AddressException extends \Exception
{
public static function validationException(string $field)
{
throw new static("Validation Exception For Address: $field");
}
}

0 comments on commit 8476f15

Please sign in to comment.