Skip to content

Commit

Permalink
add IOSS logic
Browse files Browse the repository at this point in the history
  • Loading branch information
booni3 committed Jul 7, 2021
1 parent 7eaadd4 commit 1aa92d7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
18 changes: 18 additions & 0 deletions src/DTO/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ public function addEORI($number, $issueCountry = 'GB')
return $this;
}

public function addIOSS($number, $issueCountry = 'GB')
{
if ($number) {
$this->registrationNumbers['sdt'] = [
'number' => $number,
'issuerCountryCode' => $issueCountry,
'typeCode' => 'SDT',
];
}

return $this;
}

public function hasIOSS(): bool
{
return isset($this->registrationNumbers['sdt']['number']);
}

public function toArray()
{
return $this->customer + $this->registrationNumbers();
Expand Down
39 changes: 22 additions & 17 deletions src/DTO/ShipmentCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct()

public function setCutOffTime(string $time = '4pm', $weekdaysOnly = true)
{
if($weekdaysOnly && today()->isWeekend()){
if ($weekdaysOnly && today()->isWeekend()) {
$time = 'weekday '.$time;
}

Expand Down Expand Up @@ -99,7 +99,7 @@ public function packageWeightAndDimensionsOnly()

public function addReference(?string $reference)
{
if($reference){
if ($reference) {
$this->references[] = $reference;
}
}
Expand Down Expand Up @@ -139,38 +139,43 @@ public function accounts(): array
*
* @param bool $declarable
* @param bool $paperless
* @param string|null $ddpPayerAccountNumber
*/
public function setCustomsDeclarable(bool $declarable = true, bool $paperless = true, ?string $ddpPayerAccountNumber = null)
public function setCustomsDeclarable(bool $declarable = true, bool $paperless = true)
{
if ($this->customsDeclarable = $declarable) {
if ($paperless) {
$this->setPaperlessTrade();
}
if ($ddpPayerAccountNumber) {
$this->setIncotermDDP();
$this->setDutyPayerAccountNumber($ddpPayerAccountNumber);
}
}
}

public function setIncoterm(string $incoterm)
protected function setIncoterm(string $incoterm)
{
$incoterm = strtoupper($incoterm);

if (! in_array($incoterm, ['DDP', 'DAP'])) {
if (! in_array(strtoupper($incoterm), ['DDP', 'DAP'])) {
throw ShipmentException::invalidIncoterm();
}

if ($incoterm == 'DDP') {
$this->incoterm = 'DDP';
$this->incoterm = strtoupper($incoterm);

if ($this->incoterm == 'DDP') {
$this->addValueAddedService('DD');
}
}

public function setIncotermDDP()
public function setTermsDDP(string $ddpPayerAccountNumber)
{
$this->setIncoterm('DDP');
$this->setDutyPayerAccountNumber($ddpPayerAccountNumber);
}

public function setTermsIOSS(string $importerTaxId, string $countryCode)
{
if(! $this->shipper){
throw ShipmentException::shipperNotSet();
}

$this->setIncoterm('DAP');
$this->shipper->addIOSS($importerTaxId, $countryCode);
}

public function setPaperlessTrade(bool $bool = true)
Expand Down Expand Up @@ -313,7 +318,7 @@ public function setLabelFormat(string $format)
{
$format = strtolower($format);

if(! in_array($format, ['pdf', 'zpl', 'lp2', 'epl'])){
if (! in_array($format, ['pdf', 'zpl', 'lp2', 'epl'])) {
throw ShipmentException::invalidLabelEncodingFormat();
}

Expand All @@ -322,7 +327,7 @@ public function setLabelFormat(string $format)

protected function labelFormat(): string
{
if($this->labelFormat){
if ($this->labelFormat) {
return $this->labelFormat;
}

Expand Down
5 changes: 5 additions & 0 deletions src/Exceptions/ShipmentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public static function missingInformation($key)
{
throw new static('Required information missing: '.$key);
}

public static function shipperNotSet()
{
throw new static('A shipper must be set first');
}
}

0 comments on commit 1aa92d7

Please sign in to comment.