Skip to content

Commit

Permalink
feat: add carrier dhl (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
wthijmen authored Dec 5, 2022
1 parent ce8baf2 commit d1d56cf
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 121 deletions.
9 changes: 6 additions & 3 deletions src/Adapter/ConsignmentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ private function setExtraOptions(): self
'package_type' => $options['package_type'] ?? AbstractConsignment::PACKAGE_TYPE_PACKAGE,
'delivery_date' => $options['delivery_date'] ?? null,
'delivery_type' => $options['delivery_type'] ?? AbstractConsignment::DEFAULT_DELIVERY_TYPE,
'only_recipient' => (bool) ($options['only_recipient'] ?? false),
'large_format' => (bool) ($options['large_format'] ?? false),
'age_check' => (bool) ($options['age_check'] ?? false),
'signature' => (bool) ($options['signature'] ?? false),
'extra_assurance' => (bool) ($options['extra_assurance'] ?? false),
'hide_sender' => (bool) ($options['hide_sender'] ?? false),
'large_format' => (bool) ($options['large_format'] ?? false),
'only_recipient' => (bool) ($options['only_recipient'] ?? false),
'return' => (bool) ($options['return'] ?? false),
'same_day_delivery' => (bool) ($options['same_day_delivery'] ?? false),
'signature' => (bool) ($options['signature'] ?? false),
'insurance' => $options['insurance']['amount'] ?? 0,
'label_description' => $options['label_description'] ?? null,
]);
Expand Down
68 changes: 61 additions & 7 deletions src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php declare(strict_types=1);
<?php
declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Adapter\DeliveryOptions;

Expand All @@ -24,6 +25,11 @@ abstract class AbstractShipmentOptionsAdapter
*/
protected $same_day_delivery;

/**
* @var bool|null
*/
protected $hide_sender;

/**
* @var bool|null
*/
Expand All @@ -44,6 +50,11 @@ abstract class AbstractShipmentOptionsAdapter
*/
protected $label_description;

/**
* @var null|bool
*/
protected $extra_assurance;

/**
* @return bool|null
*/
Expand Down Expand Up @@ -76,6 +87,22 @@ public function hasLargeFormat(): ?bool
return $this->large_format;
}

/**
* @return null|bool
*/
public function hasHideSender(): ?bool
{
return $this->hide_sender;
}

/**
* @return null|bool
*/
public function hasExtraAssurance(): ?bool
{
return $this->extra_assurance;
}

/**
* Return the package if the recipient is not home
*
Expand Down Expand Up @@ -113,7 +140,7 @@ public function setLabelDescription(string $labelDescription): void
}

/**
* @param null|bool $signature
* @param null|bool $signature
*
* @return void
*/
Expand All @@ -123,7 +150,7 @@ public function setSignature(?bool $signature): void
}

/**
* @param null|int $insurance
* @param null|int $insurance
*
* @return void
*/
Expand All @@ -133,7 +160,7 @@ public function setInsurance(?int $insurance): void
}

/**
* @param null|bool $ageCheck
* @param null|bool $ageCheck
*
* @return void
*/
Expand All @@ -143,7 +170,7 @@ public function setAgeCheck(?bool $ageCheck): void
}

/**
* @param null|bool $onlyRecipient
* @param null|bool $onlyRecipient
*
* @return void
*/
Expand All @@ -153,7 +180,7 @@ public function setOnlyRecipient(?bool $onlyRecipient): void
}

/**
* @param null|bool $return
* @param null|bool $return
*
* @return void
*/
Expand All @@ -162,13 +189,28 @@ public function setReturn(?bool $return): void
$this->return = $return;
}

/**
* @param null|bool $sameDayDelivery
*
* @return void
*/
public function setSameDayDelivery(?bool $sameDayDelivery): void
{
$this->same_day_delivery = $sameDayDelivery;
}

/**
* @param null|bool $largeFormat
* @param null|bool $hideSender
*
* @return void
*/
public function setHideSender(?bool $hideSender): void
{
$this->hide_sender = $hideSender;
}

/**
* @param null|bool $largeFormat
*
* @return void
*/
Expand All @@ -177,6 +219,16 @@ public function setLargeFormat(?bool $largeFormat): void
$this->large_format = $largeFormat;
}

/**
* @param null|bool $extraAssurance
*
* @return void
*/
public function setExtraAssurance(?bool $extraAssurance): void
{
$this->extra_assurance = $extraAssurance;
}

/**
* @return array
*/
Expand All @@ -191,6 +243,8 @@ public function toArray(): array
'same_day_delivery' => $this->isSameDayDelivery(),
'large_format' => $this->hasLargeFormat(),
'label_description' => $this->getLabelDescription(),
'hide_sender' => $this->hasHideSender(),
'extra_assurance' => $this->hasExtraAssurance(),
];
}
}
10 changes: 6 additions & 4 deletions src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ class ShipmentOptionsV3Adapter extends AbstractShipmentOptionsAdapter
*/
public function __construct(array $shipmentOptions)
{
$this->signature = $shipmentOptions['signature'] ?? null;
$this->only_recipient = $shipmentOptions['only_recipient'] ?? null;
$this->insurance = $shipmentOptions['insurance'] ?? null;
$this->age_check = $shipmentOptions['age_check'] ?? null;
$this->extra_assurance = $shipmentOptions['extra_assurance'] ?? null;
$this->hide_sender = $shipmentOptions['hide_sender'] ?? null;
$this->insurance = $shipmentOptions['insurance'] ?? null;
$this->label_description = $shipmentOptions['label_description'] ?? null;
$this->large_format = $shipmentOptions['large_format'] ?? null;
$this->only_recipient = $shipmentOptions['only_recipient'] ?? null;
$this->return = $shipmentOptions['return'] ?? null;
$this->same_day_delivery = $shipmentOptions['same_day_delivery'] ?? null;
$this->label_description = $shipmentOptions['label_description'] ?? null;
$this->signature = $shipmentOptions['signature'] ?? null;
}
}
1 change: 1 addition & 0 deletions src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ private function apiEncodeReturnShipments(array $consignments): string
*
* @return self
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException
* @throws \Exception
*/
private function getNewCollectionFromResult($result): self
{
Expand Down
35 changes: 35 additions & 0 deletions src/Model/Carrier/CarrierDHLForYou.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Carrier;

use MyParcelNL\Sdk\src\Model\Consignment\DHLForYouConsignment;

class CarrierDHLForYou extends AbstractCarrier
{
public const CONSIGNMENT = DHLForYouConsignment::class;
public const HUMAN = 'DHL For You Vandaag';
public const ID = 9;
public const NAME = 'dhlforyou';

/**
* @var class-string
*/
protected $consignmentClass = self::CONSIGNMENT;

/**
* @var string
*/
protected $human = self::HUMAN;

/**
* @var int
*/
protected $id = self::ID;

/**
* @var string
*/
protected $name = self::NAME;
}
1 change: 1 addition & 0 deletions src/Model/Carrier/CarrierFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CarrierFactory
CarrierDPD::class,
CarrierPostNL::class,
CarrierInstabox::class,
CarrierDHLForYou::class,
];

/**
Expand Down
54 changes: 53 additions & 1 deletion src/Model/Consignment/AbstractConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ abstract class AbstractConsignment
use HasApiKey;

public const SHIPMENT_OPTION_AGE_CHECK = 'age_check';
public const SHIPMENT_OPTION_HIDE_SENDER = 'hide_sender';
public const SHIPMENT_OPTION_INSURANCE = 'insurance';
public const SHIPMENT_OPTION_LARGE_FORMAT = 'large_format';
public const SHIPMENT_OPTION_ONLY_RECIPIENT = 'only_recipient';
public const SHIPMENT_OPTION_RETURN = 'return';
public const SHIPMENT_OPTION_SIGNATURE = 'signature';
public const SHIPMENT_OPTION_SAME_DAY_DELIVERY = 'same_day_delivery';
public const SHIPMENT_OPTION_SIGNATURE = 'signature';
public const SHIPMENT_OPTION_EXTRA_ASSURANCE = 'extra_assurance';

public const EXTRA_OPTION_DELIVERY_DATE = 'delivery_date';
public const EXTRA_OPTION_DELIVERY_MONDAY = 'delivery_monday';
Expand Down Expand Up @@ -423,6 +425,16 @@ abstract class AbstractConsignment
*/
private $carrier;

/**
* @var bool
*/
private $hide_sender;

/**
* @var bool
*/
private $extra_assurance;

/**
* @var bool
*/
Expand Down Expand Up @@ -1489,6 +1501,46 @@ public function setLargeFormat(bool $largeFormat): self
return $this;
}

/**
* @param bool $hideSender
* @codeCoverageIgnore
* @return $this
*/
public function setHideSender(bool $hideSender): self
{
$this->hide_sender = $hideSender;

return $this;
}

/**
* @return null|bool
*/
public function hasHideSender(): ?bool
{
return $this->hide_sender;
}

/**
* @param bool $extraAssurance
* @codeCoverageIgnore
* @return $this
*/
public function setExtraAssurance(bool $extraAssurance): self
{
$this->extra_assurance = $extraAssurance;

return $this;
}

/**
* @return null|bool
*/
public function hasExtraAssurance(): ?bool
{
return $this->extra_assurance;
}

/**
* Age check
* Required: No.
Expand Down
66 changes: 66 additions & 0 deletions src/Model/Consignment/DHLForYouConsignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Consignment;

use MyParcelNL\Sdk\src\Model\Carrier\CarrierDHLForYou;
use MyParcelNL\Sdk\src\Validator\Consignment\DHLForYouConsignmentValidator;

class DHLForYouConsignment extends AbstractConsignment
{
/**
* @var string
*/
protected $carrierClass = CarrierDHLForYou::class;

/**
* @var string
*/
protected $validatorClass = DHLForYouConsignmentValidator::class;

/**
* @return string[]
*/
public function getAllowedDeliveryTypes(): array
{
return [
self::DELIVERY_TYPE_STANDARD_NAME,
self::DELIVERY_TYPE_PICKUP_NAME,
];
}

/**
* @return string[]
*/
public function getAllowedPackageTypes(): array
{
return [
self::PACKAGE_TYPE_PACKAGE_NAME,
self::PACKAGE_TYPE_MAILBOX_NAME,
];
}

/**
* @return string[]
*/
public function getAllowedShipmentOptions(): array
{
return [
self::SHIPMENT_OPTION_AGE_CHECK,
self::SHIPMENT_OPTION_HIDE_SENDER,
self::SHIPMENT_OPTION_EXTRA_ASSURANCE,
self::SHIPMENT_OPTION_ONLY_RECIPIENT,
self::SHIPMENT_OPTION_SIGNATURE,
self::SHIPMENT_OPTION_SAME_DAY_DELIVERY,
];
}

/**
* @return string
*/
public function getLocalCountryCode(): string
{
return self::CC_NL;
}
}
Loading

0 comments on commit d1d56cf

Please sign in to comment.