Skip to content

Commit dbaf617

Browse files
authored
feat(carriers): add ups shipping options (#509)
* feat(carriers): add ups shipping options * feat(carriers): add ups shipping options
1 parent 863ba7b commit dbaf617

File tree

7 files changed

+123
-1
lines changed

7 files changed

+123
-1
lines changed

src/Adapter/ConsignmentAdapter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private function setExtraOptions(): self
103103
'return' => (bool) ($options['return'] ?? false),
104104
'same_day_delivery' => (bool) ($options['same_day_delivery'] ?? false),
105105
'signature' => (bool) ($options['signature'] ?? false),
106+
'collect' => (bool) ($options['collect'] ?? false),
106107
'receipt_code' => (bool) ($options['receipt_code'] ?? false),
107108
'insurance' => $options['insurance']['amount'] ?? 0,
108109
'label_description' => $options['label_description'] ?? null,

src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ abstract class AbstractShipmentOptionsAdapter
1515
*/
1616
protected $receipt_code;
1717

18+
/**
19+
* @var bool|null
20+
*/
21+
protected $collect;
22+
1823
/**
1924
* @var bool|null
2025
*/
@@ -76,6 +81,14 @@ public function hasReceiptCode(): ?bool
7681
return $this->receipt_code;
7782
}
7883

84+
/**
85+
* @return bool|null
86+
*/
87+
public function hasCollect(): ?bool
88+
{
89+
return $this->collect;
90+
}
91+
7992
/**
8093
* @return bool|null
8194
*/
@@ -172,6 +185,16 @@ public function setReceiptCode(?bool $receiptCode): void
172185
$this->receipt_code = $receiptCode;
173186
}
174187

188+
/**
189+
* @param bool|null $collect
190+
*
191+
* @return void
192+
*/
193+
public function setCollect(?bool $collect): void
194+
{
195+
$this->collect = $collect;
196+
}
197+
175198
/**
176199
* @param null|int $insurance
177200
*
@@ -259,6 +282,7 @@ public function toArray(): array
259282
{
260283
return [
261284
'signature' => $this->hasSignature(),
285+
'collect' => $this->hasCollect(),
262286
'receipt_code' => $this->hasReceiptCode(),
263287
'insurance' => $this->getInsurance(),
264288
'age_check' => $this->hasAgeCheck(),

src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function __construct(array $shipmentOptions)
1919
$this->return = $shipmentOptions['return'] ?? null;
2020
$this->same_day_delivery = $shipmentOptions['same_day_delivery'] ?? null;
2121
$this->signature = $shipmentOptions['signature'] ?? null;
22+
$this->collect = $shipmentOptions['collect'] ?? null;
2223
$this->receipt_code = $shipmentOptions['receipt_code'] ?? null;
2324
}
2425
}

src/Collection/Fulfilment/OrderCollection.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private function getShipmentOptions(AbstractDeliveryOptionsAdapter $deliveryOpti
125125
'delivery_type' => $deliveryOptions->getDeliveryTypeId(),
126126
'delivery_date' => $deliveryDate ?: null,
127127
'signature' => (int) $shipmentOptions->hasSignature(),
128+
'collect' => (int) $shipmentOptions->hasCollect(),
128129
'receipt_code' => (int) $shipmentOptions->hasReceiptCode(),
129130
'only_recipient' => (int) $shipmentOptions->hasOnlyRecipient(),
130131
'age_check' => (int) $shipmentOptions->hasAgeCheck(),

src/Model/Consignment/AbstractConsignment.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ abstract class AbstractConsignment
4343
public const SHIPMENT_OPTION_RETURN = 'return';
4444
public const SHIPMENT_OPTION_SAME_DAY_DELIVERY = 'same_day_delivery';
4545
public const SHIPMENT_OPTION_SIGNATURE = 'signature';
46+
public const SHIPMENT_OPTION_COLLECT = 'collect';
4647
public const SHIPMENT_OPTION_RECEIPT_CODE = 'receipt_code';
4748
/**
4849
* @deprecated since jan 2023 extra_assurance is no longer supported
@@ -57,6 +58,7 @@ abstract class AbstractConsignment
5758
self::SHIPMENT_OPTION_ONLY_RECIPIENT,
5859
self::SHIPMENT_OPTION_RETURN,
5960
self::SHIPMENT_OPTION_SIGNATURE,
61+
self::SHIPMENT_OPTION_COLLECT,
6062
self::SHIPMENT_OPTION_RECEIPT_CODE,
6163
];
6264

@@ -72,6 +74,7 @@ abstract class AbstractConsignment
7274
public const DELIVERY_TYPE_STANDARD = 2;
7375
public const DELIVERY_TYPE_EVENING = 3;
7476
public const DELIVERY_TYPE_PICKUP = 4;
77+
public const DELIVERY_TYPE_EXPRESS = 7;
7578

7679
/**
7780
* @deprecated Since November 2019 is it no longer possible to use pickup express.
@@ -82,6 +85,7 @@ abstract class AbstractConsignment
8285
public const DELIVERY_TYPE_STANDARD_NAME = 'standard';
8386
public const DELIVERY_TYPE_EVENING_NAME = 'evening';
8487
public const DELIVERY_TYPE_PICKUP_NAME = 'pickup';
88+
public const DELIVERY_TYPE_EXPRESS_NAME = 'express';
8589

8690
/**
8791
* @deprecated Since November 2019 is it no longer possible to use pickup express.
@@ -94,6 +98,7 @@ abstract class AbstractConsignment
9498
self::DELIVERY_TYPE_STANDARD,
9599
self::DELIVERY_TYPE_EVENING,
96100
self::DELIVERY_TYPE_PICKUP,
101+
self::DELIVERY_TYPE_EXPRESS,
97102
self::DELIVERY_TYPE_PICKUP_EXPRESS,
98103
];
99104

@@ -103,6 +108,7 @@ abstract class AbstractConsignment
103108
self::DELIVERY_TYPE_STANDARD_NAME,
104109
self::DELIVERY_TYPE_EVENING_NAME,
105110
self::DELIVERY_TYPE_PICKUP_NAME,
111+
self::DELIVERY_TYPE_EXPRESS_NAME,
106112
self::DELIVERY_TYPE_PICKUP_EXPRESS_NAME,
107113
];
108114

@@ -112,6 +118,7 @@ abstract class AbstractConsignment
112118
self::DELIVERY_TYPE_STANDARD_NAME => self::DELIVERY_TYPE_STANDARD,
113119
self::DELIVERY_TYPE_EVENING_NAME => self::DELIVERY_TYPE_EVENING,
114120
self::DELIVERY_TYPE_PICKUP_NAME => self::DELIVERY_TYPE_PICKUP,
121+
self::DELIVERY_TYPE_EXPRESS_NAME => self::DELIVERY_TYPE_EXPRESS,
115122
self::DELIVERY_TYPE_PICKUP_EXPRESS_NAME => self::DELIVERY_TYPE_PICKUP_EXPRESS,
116123
];
117124

@@ -399,6 +406,12 @@ abstract class AbstractConsignment
399406
*/
400407
protected $receipt_code;
401408

409+
/**
410+
* @internal
411+
* @var bool|null
412+
*/
413+
protected $collect;
414+
402415
/**
403416
* @internal
404417
* @var bool|null
@@ -1507,6 +1520,17 @@ public function setReceiptCode(bool $receiptCode): self
15071520
return $this;
15081521
}
15091522

1523+
/**
1524+
* @param bool $collect
1525+
* @return self
1526+
*/
1527+
public function setCollect(bool $collect): self
1528+
{
1529+
$this->collect = $collect && $this->canHaveShipmentOption(self::SHIPMENT_OPTION_COLLECT);
1530+
1531+
return $this;
1532+
}
1533+
15101534
/**
15111535
* Return the package if the recipient is not home.
15121536
*
@@ -1577,6 +1601,11 @@ public function hasReceiptCode(): ?bool
15771601
return $this->receipt_code;
15781602
}
15791603

1604+
public function hasCollect(): ?bool
1605+
{
1606+
return $this->collect;
1607+
}
1608+
15801609
/**
15811610
* @return boolean
15821611
*/

src/Model/Consignment/UPSConsignment.php

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,72 @@ public function getAllowedPackageTypes(): array
5656
public function getAllowedDeliveryTypes(): array
5757
{
5858
return [
59-
self::DELIVERY_TYPE_STANDARD,
59+
self::DELIVERY_TYPE_STANDARD_NAME,
60+
self::DELIVERY_TYPE_EXPRESS_NAME,
6061
];
6162
}
63+
64+
/**
65+
* @return string[]
66+
*/
67+
public function getAllowedShipmentOptions(): array
68+
{
69+
return [
70+
self::SHIPMENT_OPTION_AGE_CHECK,
71+
self::SHIPMENT_OPTION_COLLECT,
72+
self::SHIPMENT_OPTION_INSURANCE,
73+
self::SHIPMENT_OPTION_ONLY_RECIPIENT,
74+
self::SHIPMENT_OPTION_SIGNATURE,
75+
];
76+
}
77+
78+
/**
79+
* @return string[]
80+
*/
81+
public function getMandatoryShipmentOptions(): array
82+
{
83+
if ($this->hasAgeCheck()) {
84+
return [
85+
self::SHIPMENT_OPTION_SIGNATURE,
86+
];
87+
}
88+
89+
return [];
90+
}
91+
92+
/**
93+
* @return int[]
94+
*/
95+
protected function getLocalInsurancePossibilities(): array
96+
{
97+
return [
98+
250,
99+
500,
100+
1000,
101+
1500,
102+
2000,
103+
2500,
104+
3000,
105+
3500,
106+
4000,
107+
4500,
108+
5000,
109+
];
110+
}
111+
112+
/**
113+
* @return int[]
114+
*/
115+
protected function getEuInsurancePossibilities(): array
116+
{
117+
return $this->getLocalInsurancePossibilities();
118+
}
119+
120+
/**
121+
* @return array
122+
*/
123+
protected function getNlToBeInsurancePossibilities(): array
124+
{
125+
return $this->getLocalInsurancePossibilities();
126+
}
62127
}

src/Services/ConsignmentEncode.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public static function encodeExtraOptions(array $consignmentEncoded, AbstractCon
8989
'label_description' => $consignment->getLabelDescription(),
9090
'only_recipient' => Helpers::intOrNull($consignment->isOnlyRecipient()),
9191
'signature' => Helpers::intOrNull($consignment->isSignature()),
92+
'collect' => Helpers::intOrNull($consignment->hasCollect()),
9293
'receipt_code' => Helpers::intOrNull($consignment->hasReceiptCode()),
9394
'return' => Helpers::intOrNull($consignment->isReturn()),
9495
'same_day_delivery' => Helpers::intOrNull($consignment->isSameDayDelivery()),

0 commit comments

Comments
 (0)