| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
namespace MyParcelNL\Sdk\src\Model\Consignment; |
| 4 |
|
| 5 |
class PostNLConsignment extends AbstractConsignment |
| 6 |
{ |
| 7 |
/** |
| 8 |
* @var int |
| 9 |
*/ |
| 10 |
public const CARRIER_ID = 1; |
| 11 |
|
| 12 |
/** |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
public const CARRIER_NAME = 'postnl'; |
| 16 |
|
| 17 |
/** |
| 18 |
* @var array |
| 19 |
*/ |
| 20 |
public const INSURANCE_POSSIBILITIES_LOCAL = [ |
| 21 |
0, |
| 22 |
100, |
| 23 |
250, |
| 24 |
500, |
| 25 |
1000, |
| 26 |
1500, |
| 27 |
2000, |
| 28 |
2500, |
| 29 |
3000, |
| 30 |
3500, |
| 31 |
4000, |
| 32 |
4500, |
| 33 |
5000 |
| 34 |
]; |
| 35 |
|
| 36 |
/** |
| 37 |
* @var array |
| 38 |
*/ |
| 39 |
private const VALID_PACKAGE_TYPES = [ |
| 40 |
self::PACKAGE_TYPE_PACKAGE, |
| 41 |
self::PACKAGE_TYPE_MAILBOX, |
| 42 |
self::PACKAGE_TYPE_LETTER, |
| 43 |
self::PACKAGE_TYPE_DIGITAL_STAMP |
| 44 |
]; |
| 45 |
|
| 46 |
/** |
| 47 |
* @var string |
| 48 |
*/ |
| 49 |
protected $local_cc = self::CC_NL; |
| 50 |
|
| 51 |
/** |
| 52 |
* The id of the consignment |
| 53 |
* |
| 54 |
* Save this id in your database |
| 55 |
* |
| 56 |
* @return int |
| 57 |
* @deprecated Use getConsignmentId instead |
| 58 |
* |
| 59 |
*/ |
| 60 |
public function getMyParcelConsignmentId(): int |
| 61 |
{ |
| 62 |
return $this->getConsignmentId(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* @param int $id |
| 67 |
* |
| 68 |
* @return \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment |
| 69 |
* @internal |
| 70 |
* |
| 71 |
* The id of the consignment |
| 72 |
* |
| 73 |
* @deprecated Use getConsignmentId instead |
| 74 |
* |
| 75 |
*/ |
| 76 |
public function setMyParcelConsignmentId(int $id): AbstractConsignment |
| 77 |
{ |
| 78 |
return $this->setConsignmentId($id); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* @param array $consignmentEncoded |
| 83 |
* |
| 84 |
* @return array |
| 85 |
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException |
| 86 |
*/ |
| 87 |
public function encodeStreet(array $consignmentEncoded): array |
| 88 |
{ |
| 89 |
if ($this->getCountry() == $this->local_cc) { |
| 90 |
$consignmentEncoded = array_merge_recursive( |
| 91 |
$consignmentEncoded, |
| 92 |
[ |
| 93 |
'recipient' => [ |
| 94 |
'street' => $this->getStreet(true), |
| 95 |
'street_additional_info' => $this->getStreetAdditionalInfo(), |
| 96 |
'number' => $this->getNumber(), |
| 97 |
'number_suffix' => (string) $this->getNumberSuffix(), |
| 98 |
], |
| 99 |
] |
| 100 |
); |
| 101 |
|
| 102 |
return $consignmentEncoded; |
| 103 |
} |
| 104 |
|
| 105 |
return parent::encodeStreet($consignmentEncoded); |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Street number suffix. |
| 110 |
* |
| 111 |
* Required: no |
| 112 |
* |
| 113 |
* @param string $numberSuffix |
| 114 |
* |
| 115 |
* @return $this |
| 116 |
*/ |
| 117 |
public function setNumberSuffix(?string $numberSuffix): AbstractConsignment |
| 118 |
{ |
| 119 |
$this->number_suffix = $numberSuffix; |
| 120 |
|
| 121 |
return $this; |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* The package type |
| 126 |
* |
| 127 |
* For international shipment only package type 1 is allowed |
| 128 |
* Pattern: [1 – 3]<br> |
| 129 |
* Example: |
| 130 |
* 1. package |
| 131 |
* 2. mailbox package |
| 132 |
* 3. letter |
| 133 |
* Required: Yes |
| 134 |
* |
| 135 |
* @param int $packageType |
| 136 |
* |
| 137 |
* @return $this |
| 138 |
* @throws \Exception |
| 139 |
*/ |
| 140 |
public function setPackageType(int $packageType): AbstractConsignment |
| 141 |
{ |
| 142 |
if (! in_array($packageType, self::VALID_PACKAGE_TYPES)) { |
| 143 |
throw new \Exception('Use the correct package type for shipment:' . $this->consignment_id); |
| 144 |
} |
| 145 |
|
| 146 |
return parent::setPackageType($packageType); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* The delivery type for the package |
| 151 |
* |
| 152 |
* Required: Yes if delivery_date has been specified |
| 153 |
* |
| 154 |
* @param int $deliveryType |
| 155 |
* @param bool $needDeliveryDate |
| 156 |
* |
| 157 |
* @return \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment |
| 158 |
* @throws \Exception |
| 159 |
*/ |
| 160 |
public function setDeliveryType(int $deliveryType, bool $needDeliveryDate = true): AbstractConsignment |
| 161 |
{ |
| 162 |
if ($needDeliveryDate && |
| 163 |
$deliveryType !== self::DELIVERY_TYPE_STANDARD && |
| 164 |
$this->getDeliveryDate() == null |
| 165 |
) { |
| 166 |
throw new \Exception('If delivery type !== 2, first set delivery date with setDeliveryDate() before running setDeliveryType() for shipment: ' . $this->consignment_id); |
| 167 |
} |
| 168 |
|
| 169 |
return parent::setDeliveryType($deliveryType, $needDeliveryDate); |
| 170 |
} |
| 171 |
|
| 172 |
/** |
| 173 |
* The delivery date time for this shipment |
| 174 |
* Pattern: YYYY-MM-DD | YYYY-MM-DD HH:MM:SS |
| 175 |
* Example: 2017-01-01 | 2017-01-01 00:00:00 |
| 176 |
* Required: Yes if delivery type has been specified |
| 177 |
* |
| 178 |
* @param string $delivery_date |
| 179 |
* |
| 180 |
* @return \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment |
| 181 |
* @throws \Exception |
| 182 |
*/ |
| 183 |
public function setDeliveryDate(?string $delivery_date): AbstractConsignment |
| 184 |
{ |
| 185 |
return parent::setDeliveryDate($delivery_date); |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Insurance price for the package. |
| 190 |
* |
| 191 |
* Composite type containing integer and currency. The amount is without decimal separators. |
| 192 |
* Required: No |
| 193 |
* |
| 194 |
* @param int|null $insurance |
| 195 |
* |
| 196 |
* @return \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment |
| 197 |
* @throws \Exception |
| 198 |
*/ |
| 199 |
public function setInsurance(?int $insurance): AbstractConsignment |
| 200 |
{ |
| 201 |
if (null === $insurance) { |
| 202 |
throw new \BadMethodCallException('Insurance must be one of ' . implode(', ', self::INSURANCE_POSSIBILITIES_LOCAL)); |
| 203 |
} |
| 204 |
|
| 205 |
return parent::setInsurance($insurance); |
| 206 |
} |
| 207 |
|
| 208 |
/** |
| 209 |
* @return bool |
| 210 |
*/ |
| 211 |
public function isOnlyRecipient(): bool |
| 212 |
{ |
| 213 |
return (bool) $this->only_recipient; |
| 214 |
} |
| 215 |
|
| 216 |
/** |
| 217 |
* Deliver the package to the recipient only |
| 218 |
* |
| 219 |
* Required: No |
| 220 |
* |
| 221 |
* @param bool $only_recipient |
| 222 |
* |
| 223 |
* @return $this |
| 224 |
* @throws \Exception |
| 225 |
*/ |
| 226 |
public function setOnlyRecipient(bool $only_recipient): AbstractConsignment |
| 227 |
{ |
| 228 |
$this->only_recipient = $this->canHaveOption($only_recipient); |
| 229 |
|
| 230 |
return $this; |
| 231 |
} |
| 232 |
|
| 233 |
/** |
| 234 |
* @return bool |
| 235 |
*/ |
| 236 |
public function isSignature(): bool |
| 237 |
{ |
| 238 |
return (bool) $this->signature; |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* Package must be signed for |
| 243 |
* |
| 244 |
* Required: No |
| 245 |
* |
| 246 |
* @param bool $signature |
| 247 |
* |
| 248 |
* @return $this |
| 249 |
* @throws \Exception |
| 250 |
*/ |
| 251 |
public function setSignature(bool $signature): AbstractConsignment |
| 252 |
{ |
| 253 |
$this->signature = $this->canHaveOption($signature); |
| 254 |
|
| 255 |
return $this; |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* @return boolean |
| 260 |
*/ |
| 261 |
public function isLargeFormat(): bool |
| 262 |
{ |
| 263 |
return (bool) $this->large_format; |
| 264 |
} |
| 265 |
|
| 266 |
/** |
| 267 |
* * Large format package |
| 268 |
* |
| 269 |
* Required: No |
| 270 |
* |
| 271 |
* @param bool $largeFormat |
| 272 |
* |
| 273 |
* @return \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment |
| 274 |
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException |
| 275 |
*/ |
| 276 |
public function setLargeFormat(bool $largeFormat): AbstractConsignment |
| 277 |
{ |
| 278 |
$this->large_format = $this->canHaveOption($largeFormat); |
| 279 |
|
| 280 |
return $this; |
| 281 |
} |
| 282 |
|
| 283 |
/** |
| 284 |
* @return bool |
| 285 |
*/ |
| 286 |
public function hasAgeCheck(): bool |
| 287 |
{ |
| 288 |
return (bool) $this->age_check; |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* Age check |
| 293 |
* |
| 294 |
* Required: No |
| 295 |
* |
| 296 |
* @param bool $ageCheck |
| 297 |
* |
| 298 |
* @return $this |
| 299 |
* @throws \Exception |
| 300 |
*/ |
| 301 |
public function setAgeCheck(bool $ageCheck): AbstractConsignment |
| 302 |
{ |
| 303 |
$this->age_check = $this->canHaveOption($ageCheck); |
| 304 |
|
| 305 |
return $this; |
| 306 |
} |
| 307 |
|
| 308 |
/** |
| 309 |
* Pattern: [0-9A-Za-z] |
| 310 |
* Example: Albert Heijn |
| 311 |
* Required: Yes for pickup location |
| 312 |
* |
| 313 |
* @param string $retailNetworkId |
| 314 |
* |
| 315 |
* @return \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment |
| 316 |
* @deprecated Use setRetailNetworkId instead |
| 317 |
* |
| 318 |
*/ |
| 319 |
public function setPickupNetworkId($retailNetworkId): AbstractConsignment |
| 320 |
{ |
| 321 |
return $this->setRetailNetworkId((string) $retailNetworkId); |
| 322 |
} |
| 323 |
|
| 324 |
/** |
| 325 |
* Pattern: [0-9A-Za-z] |
| 326 |
* Example: Albert Heijn |
| 327 |
* Required: Yes for pickup location |
| 328 |
* |
| 329 |
* @param string $retailNetworkId |
| 330 |
* |
| 331 |
* @return \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment |
| 332 |
*/ |
| 333 |
public function setRetailNetworkId(string $retailNetworkId): AbstractConsignment |
| 334 |
{ |
| 335 |
$this->retail_network_id = $retailNetworkId; |
| 336 |
|
| 337 |
return $this; |
| 338 |
} |
| 339 |
} |
| 340 |
|