Skip to content

Commit

Permalink
feat(carriers): add ups shipping options (#509)
Browse files Browse the repository at this point in the history
* feat(carriers): add ups shipping options

* feat(carriers): add ups shipping options
  • Loading branch information
joerivanveen authored Nov 14, 2024
1 parent 863ba7b commit dbaf617
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Adapter/ConsignmentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 24 additions & 0 deletions src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ abstract class AbstractShipmentOptionsAdapter
*/
protected $receipt_code;

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

/**
* @var bool|null
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions src/Collection/Fulfilment/OrderCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
29 changes: 29 additions & 0 deletions src/Model/Consignment/AbstractConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
];

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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,
];

Expand All @@ -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,
];

Expand All @@ -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,
];

Expand Down Expand Up @@ -399,6 +406,12 @@ abstract class AbstractConsignment
*/
protected $receipt_code;

/**
* @internal
* @var bool|null
*/
protected $collect;

/**
* @internal
* @var bool|null
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -1577,6 +1601,11 @@ public function hasReceiptCode(): ?bool
return $this->receipt_code;
}

public function hasCollect(): ?bool
{
return $this->collect;
}

/**
* @return boolean
*/
Expand Down
67 changes: 66 additions & 1 deletion src/Model/Consignment/UPSConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
1 change: 1 addition & 0 deletions src/Services/ConsignmentEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit dbaf617

Please sign in to comment.