diff --git a/src/Adapter/ConsignmentAdapter.php b/src/Adapter/ConsignmentAdapter.php index 0d9b6e11..bfede0ed 100644 --- a/src/Adapter/ConsignmentAdapter.php +++ b/src/Adapter/ConsignmentAdapter.php @@ -103,6 +103,7 @@ private function setExtraOptions(): self 'return' => (bool) ($options['return'] ?? false), 'same_day_delivery' => (bool) ($options['same_day_delivery'] ?? false), 'signature' => (bool) ($options['signature'] ?? false), + 'collect' => (bool) ($options['collect'] ?? false), 'receipt_code' => (bool) ($options['receipt_code'] ?? false), 'insurance' => $options['insurance']['amount'] ?? 0, 'label_description' => $options['label_description'] ?? null, diff --git a/src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php b/src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php index f11312be..2dd7596a 100644 --- a/src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php +++ b/src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php @@ -15,6 +15,11 @@ abstract class AbstractShipmentOptionsAdapter */ protected $receipt_code; + /** + * @var bool|null + */ + protected $collect; + /** * @var bool|null */ @@ -76,6 +81,14 @@ public function hasReceiptCode(): ?bool return $this->receipt_code; } + /** + * @return bool|null + */ + public function hasCollect(): ?bool + { + return $this->collect; + } + /** * @return bool|null */ @@ -172,6 +185,16 @@ public function setReceiptCode(?bool $receiptCode): void $this->receipt_code = $receiptCode; } + /** + * @param bool|null $collect + * + * @return void + */ + public function setCollect(?bool $collect): void + { + $this->collect = $collect; + } + /** * @param null|int $insurance * @@ -259,6 +282,7 @@ public function toArray(): array { return [ 'signature' => $this->hasSignature(), + 'collect' => $this->hasCollect(), 'receipt_code' => $this->hasReceiptCode(), 'insurance' => $this->getInsurance(), 'age_check' => $this->hasAgeCheck(), diff --git a/src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php b/src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php index 38299f63..c56462d4 100644 --- a/src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php +++ b/src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php @@ -19,6 +19,7 @@ public function __construct(array $shipmentOptions) $this->return = $shipmentOptions['return'] ?? null; $this->same_day_delivery = $shipmentOptions['same_day_delivery'] ?? null; $this->signature = $shipmentOptions['signature'] ?? null; + $this->collect = $shipmentOptions['collect'] ?? null; $this->receipt_code = $shipmentOptions['receipt_code'] ?? null; } } diff --git a/src/Collection/Fulfilment/OrderCollection.php b/src/Collection/Fulfilment/OrderCollection.php index d8136426..eed1393b 100644 --- a/src/Collection/Fulfilment/OrderCollection.php +++ b/src/Collection/Fulfilment/OrderCollection.php @@ -125,6 +125,7 @@ private function getShipmentOptions(AbstractDeliveryOptionsAdapter $deliveryOpti 'delivery_type' => $deliveryOptions->getDeliveryTypeId(), 'delivery_date' => $deliveryDate ?: null, 'signature' => (int) $shipmentOptions->hasSignature(), + 'collect' => (int) $shipmentOptions->hasCollect(), 'receipt_code' => (int) $shipmentOptions->hasReceiptCode(), 'only_recipient' => (int) $shipmentOptions->hasOnlyRecipient(), 'age_check' => (int) $shipmentOptions->hasAgeCheck(), diff --git a/src/Model/Consignment/AbstractConsignment.php b/src/Model/Consignment/AbstractConsignment.php index 122d1a8c..7db65ed6 100755 --- a/src/Model/Consignment/AbstractConsignment.php +++ b/src/Model/Consignment/AbstractConsignment.php @@ -43,6 +43,7 @@ abstract class AbstractConsignment public const SHIPMENT_OPTION_RETURN = 'return'; public const SHIPMENT_OPTION_SAME_DAY_DELIVERY = 'same_day_delivery'; public const SHIPMENT_OPTION_SIGNATURE = 'signature'; + public const SHIPMENT_OPTION_COLLECT = 'collect'; public const SHIPMENT_OPTION_RECEIPT_CODE = 'receipt_code'; /** * @deprecated since jan 2023 extra_assurance is no longer supported @@ -57,6 +58,7 @@ abstract class AbstractConsignment self::SHIPMENT_OPTION_ONLY_RECIPIENT, self::SHIPMENT_OPTION_RETURN, self::SHIPMENT_OPTION_SIGNATURE, + self::SHIPMENT_OPTION_COLLECT, self::SHIPMENT_OPTION_RECEIPT_CODE, ]; @@ -72,6 +74,7 @@ abstract class AbstractConsignment public const DELIVERY_TYPE_STANDARD = 2; public const DELIVERY_TYPE_EVENING = 3; public const DELIVERY_TYPE_PICKUP = 4; + public const DELIVERY_TYPE_EXPRESS = 7; /** * @deprecated Since November 2019 is it no longer possible to use pickup express. @@ -82,6 +85,7 @@ abstract class AbstractConsignment public const DELIVERY_TYPE_STANDARD_NAME = 'standard'; public const DELIVERY_TYPE_EVENING_NAME = 'evening'; public const DELIVERY_TYPE_PICKUP_NAME = 'pickup'; + public const DELIVERY_TYPE_EXPRESS_NAME = 'express'; /** * @deprecated Since November 2019 is it no longer possible to use pickup express. @@ -94,6 +98,7 @@ abstract class AbstractConsignment self::DELIVERY_TYPE_STANDARD, self::DELIVERY_TYPE_EVENING, self::DELIVERY_TYPE_PICKUP, + self::DELIVERY_TYPE_EXPRESS, self::DELIVERY_TYPE_PICKUP_EXPRESS, ]; @@ -103,6 +108,7 @@ abstract class AbstractConsignment self::DELIVERY_TYPE_STANDARD_NAME, self::DELIVERY_TYPE_EVENING_NAME, self::DELIVERY_TYPE_PICKUP_NAME, + self::DELIVERY_TYPE_EXPRESS_NAME, self::DELIVERY_TYPE_PICKUP_EXPRESS_NAME, ]; @@ -112,6 +118,7 @@ abstract class AbstractConsignment self::DELIVERY_TYPE_STANDARD_NAME => self::DELIVERY_TYPE_STANDARD, self::DELIVERY_TYPE_EVENING_NAME => self::DELIVERY_TYPE_EVENING, self::DELIVERY_TYPE_PICKUP_NAME => self::DELIVERY_TYPE_PICKUP, + self::DELIVERY_TYPE_EXPRESS_NAME => self::DELIVERY_TYPE_EXPRESS, self::DELIVERY_TYPE_PICKUP_EXPRESS_NAME => self::DELIVERY_TYPE_PICKUP_EXPRESS, ]; @@ -399,6 +406,12 @@ abstract class AbstractConsignment */ protected $receipt_code; + /** + * @internal + * @var bool|null + */ + protected $collect; + /** * @internal * @var bool|null @@ -1507,6 +1520,17 @@ public function setReceiptCode(bool $receiptCode): self return $this; } + /** + * @param bool $collect + * @return self + */ + public function setCollect(bool $collect): self + { + $this->collect = $collect && $this->canHaveShipmentOption(self::SHIPMENT_OPTION_COLLECT); + + return $this; + } + /** * Return the package if the recipient is not home. * @@ -1577,6 +1601,11 @@ public function hasReceiptCode(): ?bool return $this->receipt_code; } + public function hasCollect(): ?bool + { + return $this->collect; + } + /** * @return boolean */ diff --git a/src/Model/Consignment/UPSConsignment.php b/src/Model/Consignment/UPSConsignment.php index a71cf4e7..699ef6b7 100644 --- a/src/Model/Consignment/UPSConsignment.php +++ b/src/Model/Consignment/UPSConsignment.php @@ -56,7 +56,72 @@ public function getAllowedPackageTypes(): array public function getAllowedDeliveryTypes(): array { return [ - self::DELIVERY_TYPE_STANDARD, + self::DELIVERY_TYPE_STANDARD_NAME, + self::DELIVERY_TYPE_EXPRESS_NAME, ]; } + + /** + * @return string[] + */ + public function getAllowedShipmentOptions(): array + { + return [ + self::SHIPMENT_OPTION_AGE_CHECK, + self::SHIPMENT_OPTION_COLLECT, + self::SHIPMENT_OPTION_INSURANCE, + self::SHIPMENT_OPTION_ONLY_RECIPIENT, + self::SHIPMENT_OPTION_SIGNATURE, + ]; + } + + /** + * @return string[] + */ + public function getMandatoryShipmentOptions(): array + { + if ($this->hasAgeCheck()) { + return [ + self::SHIPMENT_OPTION_SIGNATURE, + ]; + } + + return []; + } + + /** + * @return int[] + */ + protected function getLocalInsurancePossibilities(): array + { + return [ + 250, + 500, + 1000, + 1500, + 2000, + 2500, + 3000, + 3500, + 4000, + 4500, + 5000, + ]; + } + + /** + * @return int[] + */ + protected function getEuInsurancePossibilities(): array + { + return $this->getLocalInsurancePossibilities(); + } + + /** + * @return array + */ + protected function getNlToBeInsurancePossibilities(): array + { + return $this->getLocalInsurancePossibilities(); + } } diff --git a/src/Services/ConsignmentEncode.php b/src/Services/ConsignmentEncode.php index 31af7b58..be260021 100644 --- a/src/Services/ConsignmentEncode.php +++ b/src/Services/ConsignmentEncode.php @@ -89,6 +89,7 @@ public static function encodeExtraOptions(array $consignmentEncoded, AbstractCon 'label_description' => $consignment->getLabelDescription(), 'only_recipient' => Helpers::intOrNull($consignment->isOnlyRecipient()), 'signature' => Helpers::intOrNull($consignment->isSignature()), + 'collect' => Helpers::intOrNull($consignment->hasCollect()), 'receipt_code' => Helpers::intOrNull($consignment->hasReceiptCode()), 'return' => Helpers::intOrNull($consignment->isReturn()), 'same_day_delivery' => Helpers::intOrNull($consignment->isSameDayDelivery()),