diff --git a/src/Adapter/ConsignmentAdapter.php b/src/Adapter/ConsignmentAdapter.php index 99e8b161..0d9b6e11 100644 --- a/src/Adapter/ConsignmentAdapter.php +++ b/src/Adapter/ConsignmentAdapter.php @@ -19,8 +19,8 @@ class ConsignmentAdapter /** * ConsignmentDecode constructor. * - * @param array $data - * @param \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment $consignment + * @param array $data + * @param \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment $consignment * * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException */ @@ -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), + '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 7dbaf82f..f11312be 100644 --- a/src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php +++ b/src/Adapter/DeliveryOptions/AbstractShipmentOptionsAdapter.php @@ -10,6 +10,11 @@ abstract class AbstractShipmentOptionsAdapter */ protected $signature; + /** + * @var bool|null + */ + protected $receipt_code; + /** * @var bool|null */ @@ -63,6 +68,14 @@ public function hasSignature(): ?bool return $this->signature; } + /** + * @return bool|null + */ + public function hasReceiptCode(): ?bool + { + return $this->receipt_code; + } + /** * @return bool|null */ @@ -140,7 +153,7 @@ public function setLabelDescription(string $labelDescription): void } /** - * @param null|bool $signature + * @param null|bool $signature * * @return void */ @@ -150,7 +163,17 @@ public function setSignature(?bool $signature): void } /** - * @param null|int $insurance + * @param bool|null $receiptCode + * + * @return void + */ + public function setReceiptCode(?bool $receiptCode): void + { + $this->receipt_code = $receiptCode; + } + + /** + * @param null|int $insurance * * @return void */ @@ -160,7 +183,7 @@ public function setInsurance(?int $insurance): void } /** - * @param null|bool $ageCheck + * @param null|bool $ageCheck * * @return void */ @@ -170,7 +193,7 @@ public function setAgeCheck(?bool $ageCheck): void } /** - * @param null|bool $onlyRecipient + * @param null|bool $onlyRecipient * * @return void */ @@ -180,7 +203,7 @@ public function setOnlyRecipient(?bool $onlyRecipient): void } /** - * @param null|bool $return + * @param null|bool $return * * @return void */ @@ -190,7 +213,7 @@ public function setReturn(?bool $return): void } /** - * @param null|bool $sameDayDelivery + * @param null|bool $sameDayDelivery * * @return void */ @@ -200,7 +223,7 @@ public function setSameDayDelivery(?bool $sameDayDelivery): void } /** - * @param null|bool $hideSender + * @param null|bool $hideSender * * @return void */ @@ -210,7 +233,7 @@ public function setHideSender(?bool $hideSender): void } /** - * @param null|bool $largeFormat + * @param null|bool $largeFormat * * @return void */ @@ -220,7 +243,7 @@ public function setLargeFormat(?bool $largeFormat): void } /** - * @param null|bool $extraAssurance + * @param null|bool $extraAssurance * * @return void */ @@ -236,6 +259,7 @@ public function toArray(): array { return [ 'signature' => $this->hasSignature(), + 'receipt_code' => $this->hasReceiptCode(), 'insurance' => $this->getInsurance(), 'age_check' => $this->hasAgeCheck(), 'only_recipient' => $this->hasOnlyRecipient(), diff --git a/src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php b/src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php index 7fe08d78..38299f63 100644 --- a/src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php +++ b/src/Adapter/DeliveryOptions/ShipmentOptionsV3Adapter.php @@ -19,5 +19,6 @@ 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->receipt_code = $shipmentOptions['receipt_code'] ?? null; } } diff --git a/src/Collection/Fulfilment/OrderCollection.php b/src/Collection/Fulfilment/OrderCollection.php index 6f0e84ae..d8136426 100644 --- a/src/Collection/Fulfilment/OrderCollection.php +++ b/src/Collection/Fulfilment/OrderCollection.php @@ -27,8 +27,8 @@ class OrderCollection extends Collection use HasCountry; /** - * @param string $apiKey - * @param array $parameters + * @param string $apiKey + * @param array $parameters * * @return self * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException @@ -62,8 +62,8 @@ public function save(): self $request = (new MyParcelRequest()) ->setUserAgents($this->getUserAgent()) ->setRequestParameters( - $this->ensureHasApiKey(), - $requestBody + $this->ensureHasApiKey(), + $requestBody ) ->sendRequest('POST', MyParcelRequest::REQUEST_TYPE_ORDERS); @@ -125,6 +125,7 @@ private function getShipmentOptions(AbstractDeliveryOptionsAdapter $deliveryOpti 'delivery_type' => $deliveryOptions->getDeliveryTypeId(), 'delivery_date' => $deliveryDate ?: null, 'signature' => (int) $shipmentOptions->hasSignature(), + 'receipt_code' => (int) $shipmentOptions->hasReceiptCode(), 'only_recipient' => (int) $shipmentOptions->hasOnlyRecipient(), 'age_check' => (int) $shipmentOptions->hasAgeCheck(), 'large_format' => (int) $shipmentOptions->hasLargeFormat(), @@ -143,7 +144,7 @@ private function getShipmentOptions(AbstractDeliveryOptionsAdapter $deliveryOpti } /** - * @param \MyParcelNL\Sdk\src\Model\Consignment\DropOffPoint $dropOffPoint + * @param \MyParcelNL\Sdk\src\Model\Consignment\DropOffPoint $dropOffPoint * * @return array */ @@ -162,7 +163,7 @@ private function getDropOffPointAsArray(DropOffPoint $dropOffPoint): array } /** - * @param \MyParcelNL\Sdk\src\Model\MyParcelRequest $request + * @param \MyParcelNL\Sdk\src\Model\MyParcelRequest $request * * @return self */ diff --git a/src/Helper/MyParcelCollection.php b/src/Helper/MyParcelCollection.php index fd6d024a..31c6eb4e 100644 --- a/src/Helper/MyParcelCollection.php +++ b/src/Helper/MyParcelCollection.php @@ -174,7 +174,7 @@ public function getLinkOfLabels() } /** - * @param AbstractConsignment $consignment + * @param AbstractConsignment $consignment * * @return self * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException @@ -193,8 +193,8 @@ public function addConsignment(AbstractConsignment $consignment): self } /** - * @param int[] $ids - * @param string $apiKey + * @param int[] $ids + * @param string $apiKey * * @return self * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException @@ -213,8 +213,8 @@ public function addConsignmentByConsignmentIds($ids, $apiKey): self } /** - * @param string[] $ids - * @param string $apiKey + * @param string[] $ids + * @param string $apiKey * * @return self * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException @@ -337,7 +337,7 @@ public function deleteConcepts(): self * Get all current data * Set id and run this function to update all the information about this shipment * - * @param int $size + * @param int $size * * @return self * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException @@ -373,7 +373,7 @@ public function setLatestData($size = 300): self * Get all the information about the last created shipments * * @param $key - * @param int $size + * @param int $size * * @return self * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException @@ -391,7 +391,7 @@ public function setLatestDataWithoutIds($key, $size = 300): self /** * Get link of labels * - * @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet. + * @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet. * Positioning is only applied on the first page with labels. All subsequent pages will use the default positioning `[1,2,3,4]`. * Pass an array to specify the positions on an A4 sheet, e.g. `[2,3,4]`. * Pass a number to specify the starting position on an A4 sheet, e.g. `2`. The following labels will fill the subsequent positions. @@ -439,7 +439,7 @@ public function setLinkOfLabels($positions = self::DEFAULT_A4_POSITION): self * Receive label PDF * After setPdfOfLabels() apiId and barcode is present * - * @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet. + * @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet. * Positioning is only applied on the first page with labels. All subsequent pages will use the default positioning `[1,2,3,4]`. * Pass an array to specify the positions on an A4 sheet, e.g. `[2,3,4]`. * Pass a number to specify the starting position on an A4 sheet, e.g. `2`. The following labels will fill the subsequent positions. @@ -478,7 +478,7 @@ public function setPdfOfLabels($positions = self::DEFAULT_A4_POSITION): self /** * Download labels * - * @param bool $inline_download + * @param bool $inline_download * * @return void * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException @@ -505,8 +505,8 @@ public function downloadPdfOfLabels($inline_download = false): void /** * Send return label to customer. The customer can pay and download the label. * - * @param bool $sendMail - * @param \Closure|null $modifier + * @param bool $sendMail + * @param \Closure|null $modifier * * @return self * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException @@ -521,8 +521,8 @@ public function generateReturnConsignments(bool $sendMail, Closure $modifier = n $parentConsignments = $this->getConsignments(false); $returnConsignments = $this->getReturnConsignments($parentConsignments, $modifier); - $data = $this->apiEncodeReturnShipments($returnConsignments); - $apiKey = $returnConsignments[0]->getApiKey(); + $data = $this->apiEncodeReturnShipments($returnConsignments); + $apiKey = $returnConsignments[0]->getApiKey(); $request = (new MyParcelRequest()) ->setUserAgents($this->getUserAgent()) @@ -610,8 +610,8 @@ public function clearConsignmentsCollection(): void /** * To search and filter consignments by certain values * - * @param string $apiKey - * @param mixed $parameters May be an array or object containing properties. + * @param string $apiKey + * @param mixed $parameters May be an array or object containing properties. * If query_data is an array, it may be a simple one-dimensional structure, * or an array of arrays (which in turn may contain other arrays). * If query_data is an object, then only public properties will be incorporated @@ -651,8 +651,8 @@ public static function query(string $apiKey, $parameters): self } /** - * @param int $id - * @param string $apiKey + * @param int $id + * @param string $apiKey * * @return self * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException @@ -665,8 +665,8 @@ public static function find(int $id, string $apiKey): self } /** - * @param array $consignmentIds - * @param string $apiKey + * @param array $consignmentIds + * @param string $apiKey * * @return self * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException @@ -691,8 +691,8 @@ public static function findMany(array $consignmentIds, string $apiKey): self } /** - * @param string $id - * @param string $apiKey + * @param string $id + * @param string $apiKey * * @return self * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException @@ -705,8 +705,8 @@ public static function findByReferenceId(string $id, string $apiKey): self } /** - * @param array $referenceIds - * @param string $apiKey + * @param array $referenceIds + * @param string $apiKey * * @return self * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException @@ -755,7 +755,7 @@ public function sortByCollection(MyParcelCollection $sortedCollection): self /** * Sets label format settings * - * @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet. + * @param mixed $positions The position(s) of the label(s) on an A4 sheet or false for an A6 sheet. * Positioning is only applied on the first page with labels. All subsequent pages will use the default positioning `[1,2,3,4]`. * Pass an array to specify the positions on an A4 sheet, e.g. `[2,3,4]`. * Pass a number to specify the starting position on an A4 sheet, e.g. `2`. The following labels will fill the subsequent positions. @@ -854,7 +854,7 @@ private function getNewCollectionFromResult($result): self private function addMissingReferenceId(): void { $this->transform(function (AbstractConsignment $consignment) { - if (!$consignment->getReferenceId()) { + if (! $consignment->getReferenceId()) { $consignment->setReferenceId('random_' . uniqid('', true)); } diff --git a/src/Model/Consignment/AbstractConsignment.php b/src/Model/Consignment/AbstractConsignment.php index d0161fac..122d1a8c 100755 --- a/src/Model/Consignment/AbstractConsignment.php +++ b/src/Model/Consignment/AbstractConsignment.php @@ -43,19 +43,22 @@ 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_RECEIPT_CODE = 'receipt_code'; /** * @deprecated since jan 2023 extra_assurance is no longer supported */ - public const SHIPMENT_OPTION_EXTRA_ASSURANCE = 'extra_assurance'; - - public const SHIPMENT_OPTIONS_TO_CHECK = [ - self::SHIPMENT_OPTION_AGE_CHECK, - self::SHIPMENT_OPTION_HIDE_SENDER, - self::SHIPMENT_OPTION_LARGE_FORMAT, - self::SHIPMENT_OPTION_ONLY_RECIPIENT, - self::SHIPMENT_OPTION_RETURN, - self::SHIPMENT_OPTION_SIGNATURE, - ]; + public const SHIPMENT_OPTION_EXTRA_ASSURANCE = 'extra_assurance'; + + public const SHIPMENT_OPTIONS_TO_CHECK + = [ + self::SHIPMENT_OPTION_AGE_CHECK, + self::SHIPMENT_OPTION_HIDE_SENDER, + self::SHIPMENT_OPTION_LARGE_FORMAT, + self::SHIPMENT_OPTION_ONLY_RECIPIENT, + self::SHIPMENT_OPTION_RETURN, + self::SHIPMENT_OPTION_SIGNATURE, + self::SHIPMENT_OPTION_RECEIPT_CODE, + ]; public const EXTRA_OPTION_DELIVERY_DATE = 'delivery_date'; public const EXTRA_OPTION_DELIVERY_MONDAY = 'delivery_monday'; @@ -85,29 +88,32 @@ abstract class AbstractConsignment */ public const DELIVERY_TYPE_PICKUP_EXPRESS_NAME = 'pickup_express'; - public const DELIVERY_TYPES_IDS = [ - self::DELIVERY_TYPE_MORNING, - self::DELIVERY_TYPE_STANDARD, - self::DELIVERY_TYPE_EVENING, - self::DELIVERY_TYPE_PICKUP, - self::DELIVERY_TYPE_PICKUP_EXPRESS, - ]; - - public const DELIVERY_TYPES_NAMES = [ - self::DELIVERY_TYPE_MORNING_NAME, - self::DELIVERY_TYPE_STANDARD_NAME, - self::DELIVERY_TYPE_EVENING_NAME, - self::DELIVERY_TYPE_PICKUP_NAME, - self::DELIVERY_TYPE_PICKUP_EXPRESS_NAME, - ]; - - public const DELIVERY_TYPES_NAMES_IDS_MAP = [ - self::DELIVERY_TYPE_MORNING_NAME => self::DELIVERY_TYPE_MORNING, - 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_PICKUP_EXPRESS_NAME => self::DELIVERY_TYPE_PICKUP_EXPRESS, - ]; + public const DELIVERY_TYPES_IDS + = [ + self::DELIVERY_TYPE_MORNING, + self::DELIVERY_TYPE_STANDARD, + self::DELIVERY_TYPE_EVENING, + self::DELIVERY_TYPE_PICKUP, + self::DELIVERY_TYPE_PICKUP_EXPRESS, + ]; + + public const DELIVERY_TYPES_NAMES + = [ + self::DELIVERY_TYPE_MORNING_NAME, + self::DELIVERY_TYPE_STANDARD_NAME, + self::DELIVERY_TYPE_EVENING_NAME, + self::DELIVERY_TYPE_PICKUP_NAME, + self::DELIVERY_TYPE_PICKUP_EXPRESS_NAME, + ]; + + public const DELIVERY_TYPES_NAMES_IDS_MAP + = [ + self::DELIVERY_TYPE_MORNING_NAME => self::DELIVERY_TYPE_MORNING, + 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_PICKUP_EXPRESS_NAME => self::DELIVERY_TYPE_PICKUP_EXPRESS, + ]; public const DEFAULT_DELIVERY_TYPE = self::DELIVERY_TYPE_STANDARD; public const DEFAULT_DELIVERY_TYPE_NAME = self::DELIVERY_TYPE_STANDARD_NAME; @@ -136,29 +142,32 @@ abstract class AbstractConsignment public const PACKAGE_TYPE_DIGITAL_STAMP_NAME = 'digital_stamp'; public const PACKAGE_TYPE_PACKAGE_SMALL_NAME = 'package_small'; - public const PACKAGE_TYPES_IDS = [ - self::PACKAGE_TYPE_PACKAGE, - self::PACKAGE_TYPE_MAILBOX, - self::PACKAGE_TYPE_LETTER, - self::PACKAGE_TYPE_DIGITAL_STAMP, - self::PACKAGE_TYPE_PACKAGE_SMALL, - ]; - - public const PACKAGE_TYPES_NAMES = [ - self::PACKAGE_TYPE_PACKAGE_NAME, - self::PACKAGE_TYPE_MAILBOX_NAME, - self::PACKAGE_TYPE_LETTER_NAME, - self::PACKAGE_TYPE_DIGITAL_STAMP_NAME, - self::PACKAGE_TYPE_PACKAGE_SMALL_NAME, - ]; - - public const PACKAGE_TYPES_NAMES_IDS_MAP = [ - self::PACKAGE_TYPE_PACKAGE_NAME => self::PACKAGE_TYPE_PACKAGE, - self::PACKAGE_TYPE_MAILBOX_NAME => self::PACKAGE_TYPE_MAILBOX, - self::PACKAGE_TYPE_LETTER_NAME => self::PACKAGE_TYPE_LETTER, - self::PACKAGE_TYPE_DIGITAL_STAMP_NAME => self::PACKAGE_TYPE_DIGITAL_STAMP, - self::PACKAGE_TYPE_PACKAGE_SMALL_NAME => self::PACKAGE_TYPE_PACKAGE_SMALL, - ]; + public const PACKAGE_TYPES_IDS + = [ + self::PACKAGE_TYPE_PACKAGE, + self::PACKAGE_TYPE_MAILBOX, + self::PACKAGE_TYPE_LETTER, + self::PACKAGE_TYPE_DIGITAL_STAMP, + self::PACKAGE_TYPE_PACKAGE_SMALL, + ]; + + public const PACKAGE_TYPES_NAMES + = [ + self::PACKAGE_TYPE_PACKAGE_NAME, + self::PACKAGE_TYPE_MAILBOX_NAME, + self::PACKAGE_TYPE_LETTER_NAME, + self::PACKAGE_TYPE_DIGITAL_STAMP_NAME, + self::PACKAGE_TYPE_PACKAGE_SMALL_NAME, + ]; + + public const PACKAGE_TYPES_NAMES_IDS_MAP + = [ + self::PACKAGE_TYPE_PACKAGE_NAME => self::PACKAGE_TYPE_PACKAGE, + self::PACKAGE_TYPE_MAILBOX_NAME => self::PACKAGE_TYPE_MAILBOX, + self::PACKAGE_TYPE_LETTER_NAME => self::PACKAGE_TYPE_LETTER, + self::PACKAGE_TYPE_DIGITAL_STAMP_NAME => self::PACKAGE_TYPE_DIGITAL_STAMP, + self::PACKAGE_TYPE_PACKAGE_SMALL_NAME => self::PACKAGE_TYPE_PACKAGE_SMALL, + ]; public const DEFAULT_PACKAGE_TYPE = self::PACKAGE_TYPE_PACKAGE; public const DEFAULT_PACKAGE_TYPE_NAME = self::PACKAGE_TYPE_PACKAGE_NAME; @@ -177,35 +186,36 @@ abstract class AbstractConsignment public const TYPE_B2C = 'b2c'; public const TYPE_B2B = 'b2b'; - public const EURO_COUNTRIES = [ - 'NL', - 'BE', - 'AT', - 'BG', - 'CZ', - 'CY', - 'DK', - 'EE', - 'FI', - 'FR', - 'DE', - 'GR', - 'HU', - 'IE', - 'IT', - 'LV', - 'LT', - 'LU', - 'PL', - 'PT', - 'RO', - 'SK', - 'SI', - 'ES', - 'SE', - 'XK', - 'HR', - ]; + public const EURO_COUNTRIES + = [ + 'NL', + 'BE', + 'AT', + 'BG', + 'CZ', + 'CY', + 'DK', + 'EE', + 'FI', + 'FR', + 'DE', + 'GR', + 'HU', + 'IE', + 'IT', + 'LV', + 'LT', + 'LU', + 'PL', + 'PT', + 'RO', + 'SK', + 'SI', + 'ES', + 'SE', + 'XK', + 'HR', + ]; /** * @var array @@ -383,6 +393,12 @@ abstract class AbstractConsignment */ public $signature; + /** + * @internal + * @var bool|null + */ + protected $receipt_code; + /** * @internal * @var bool|null @@ -512,7 +528,7 @@ final public function getCarrier(): ?AbstractCarrier } /** - * @param string $deliveryType + * @param string $deliveryType * * @return bool */ @@ -527,7 +543,7 @@ public function canHaveDeliveryType(string $deliveryType): bool } /** - * @param string $option + * @param string $option * * @return bool */ @@ -537,7 +553,7 @@ public function canHaveExtraOption(string $option): bool } /** - * @param string $packageType + * @param string $packageType * * @return bool */ @@ -547,7 +563,7 @@ public function canHavePackageType(string $packageType): bool } /** - * @param string $option + * @param string $option * * @return bool */ @@ -574,7 +590,7 @@ public function getMyParcelConsignmentId(): int } /** - * @param null|string $cc + * @param null|string $cc * * @return int[] */ @@ -621,7 +637,7 @@ public function getReferenceId(): ?string } /** - * @param int $id + * @param int $id * * @return \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment * @internal @@ -633,7 +649,7 @@ public function setMyParcelConsignmentId(int $id): AbstractConsignment } /** - * @param string|null $referenceIdentifier + * @param string|null $referenceIdentifier * * @return self */ @@ -645,7 +661,7 @@ public function setReferenceIdentifier(?string $referenceIdentifier): self } /** - * @param string|null $referenceIdentifier + * @param string|null $referenceIdentifier * * @return self * @deprecated use setReferenceIdentifier() @@ -667,7 +683,7 @@ public function getConsignmentId(): ?int } /** - * @param int|null $id + * @param int|null $id * * @return self * @internal @@ -681,7 +697,7 @@ public function setConsignmentId(?int $id): self } /** - * @param null|\MyParcelNL\Sdk\src\Model\Consignment\DropOffPoint $dropOffPoint + * @param null|\MyParcelNL\Sdk\src\Model\Consignment\DropOffPoint $dropOffPoint * * @return self */ @@ -700,7 +716,7 @@ public function getDropOffPoint(): ?DropOffPoint } /** - * @param bool $value + * @param bool $value * * @return self */ @@ -728,7 +744,7 @@ public function getBarcode(): ?string } /** - * @param string|null $barcode + * @param string|null $barcode * * @return self * @internal @@ -749,7 +765,7 @@ public function getExternalIdentifier(): ?string } /** - * @param null|string $externalIdentifier + * @param null|string $externalIdentifier * * @return self * @internal @@ -799,7 +815,7 @@ public function getStatus(): int /** * Status of the consignment. * - * @param int $status + * @param int $status * * @return self * @internal @@ -820,7 +836,7 @@ public function getShopId(): ?int } /** - * @param mixed $shopId + * @param mixed $shopId * * @return self * @internal @@ -855,7 +871,7 @@ public function isCdCountry(): bool */ public function isEuCountry(): bool { - return $this->isToEuCountry(); + return $this->isToEuCountry(); } /** @@ -883,7 +899,7 @@ public function getState(): ?string } /** - * @param null|string $state + * @param null|string $state * * @return self */ @@ -895,7 +911,7 @@ public function setState(?string $state): self } /** - * @param string|null $region + * @param string|null $region * * @return self */ @@ -910,7 +926,7 @@ public function setRegion(?string $region): self * The address city * Required: Yes. * - * @param string $city + * @param string $city * * @return self */ @@ -947,7 +963,7 @@ public function getStreet($useStreetAdditionalInfo = false): string * The address street name * Required: Yes or use setFullStreet(). * - * @param string $street + * @param string $street * * @return self */ @@ -986,7 +1002,7 @@ public function getStreetAdditionalInfo(): ?string * The street additional info * Required: No. * - * @param string|null $streetAdditionalInfo + * @param string|null $streetAdditionalInfo * * @return self */ @@ -1028,7 +1044,7 @@ public function getFullStreet(bool $useStreetAdditionalInfo = false): string * Splitting a full NL address and save it in this object * Required: Yes or use setStreet(). * - * @param string $fullStreet + * @param string $fullStreet * * @return self * @throws MissingFieldException @@ -1057,7 +1073,7 @@ public function setFullStreet(string $fullStreet): self } /** - * @param bool $value + * @param bool $value * * @return self */ @@ -1077,9 +1093,9 @@ public function isSaveRecipientAddress(): bool } /** - * @param string $barcode - * @param string $postalCode - * @param string $countryCode + * @param string $barcode + * @param string $postalCode + * @param string $countryCode * * @return string */ @@ -1103,7 +1119,7 @@ public function getNumber(): ?string * Example: 10. 20. NOT 2,3 * Required: Yes for NL. * - * @param mixed $number + * @param mixed $number * * @return self */ @@ -1126,7 +1142,7 @@ public function getNumberSuffix(): ?string * Street number suffix. * Required: no. * - * @param string|null $numberSuffix + * @param string|null $numberSuffix * * @return self */ @@ -1149,7 +1165,7 @@ public function getBoxNumber(): ?string * Street number suffix. * Required: no. * - * @param string|null $boxNumber + * @param string|null $boxNumber * * @return self */ @@ -1161,7 +1177,7 @@ public function setBoxNumber(?string $boxNumber): self } /** - * @param array $consignmentEncoded + * @param array $consignmentEncoded * * @return array * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException @@ -1178,7 +1194,7 @@ public function encodeStreet(array $consignmentEncoded): array * Check if address is correct * Only for Dutch addresses. * - * @param string $fullStreet + * @param string $fullStreet * * @return bool * @deprecated Use ValidateStreet::validate() @@ -1200,7 +1216,7 @@ public function getPostalCode(): ?string } /** - * @param string $postalCode + * @param string $postalCode * * @return self * @throws \BadMethodCallException @@ -1238,7 +1254,7 @@ public function getPerson(): string * The person at this address * Required: Yes. * - * @param string $person + * @param string $person * * @return self */ @@ -1261,7 +1277,7 @@ public function getCompany(): ?string * Company name * Required: no. * - * @param string|null $company + * @param string|null $company * * @return self */ @@ -1288,7 +1304,7 @@ public function getEmail(): ?string * The address email * Required: no. * - * @param string|null $email + * @param string|null $email * * @return self */ @@ -1311,7 +1327,7 @@ public function getPhone(): ?string * The address phone * Required: no. * - * @param string|null $phone + * @param string|null $phone * * @return self */ @@ -1323,7 +1339,7 @@ public function setPhone(?string $phone): self } /** - * @param int|null $default + * @param int|null $default * * @return int|null */ @@ -1343,7 +1359,7 @@ public function getPackageType($default = null): ?int * 4. digital stamp * Required: Yes. * - * @param int $packageType + * @param int $packageType * * @return self * @throws \Exception @@ -1373,7 +1389,7 @@ public function getDeliveryType(): int * The delivery type for the package * Required: Yes if delivery_date has been specified. * - * @param int $deliveryType + * @param int $deliveryType * * @return self */ @@ -1385,7 +1401,7 @@ public function setDeliveryType(int $deliveryType): self } /** - * @param bool $value + * @param bool $value * * @return self */ @@ -1418,7 +1434,7 @@ public function getDeliveryDate(): ?string * Example: 2017-01-01 | 2017-01-01 00:00:00 * Required: Yes if delivery type has been specified. * - * @param string|null $deliveryDate + * @param string|null $deliveryDate * * @return self */ @@ -1454,7 +1470,7 @@ public function setDeliveryDate(?string $deliveryDate): self * Deliver the package to the recipient only * Required: No. * - * @param bool $onlyRecipient + * @param bool $onlyRecipient * * @return self */ @@ -1469,7 +1485,7 @@ public function setOnlyRecipient(bool $onlyRecipient): self * * Package must be signed for * Required: No. * - * @param bool $signature + * @param bool $signature * * @return self */ @@ -1480,6 +1496,17 @@ public function setSignature(bool $signature): self return $this; } + /** + * @param bool $receiptCode + * @return self + */ + public function setReceiptCode(bool $receiptCode): self + { + $this->receipt_code = $receiptCode && $this->canHaveShipmentOption(self::SHIPMENT_OPTION_RECEIPT_CODE); + + return $this; + } + /** * Return the package if the recipient is not home. * @@ -1494,7 +1521,7 @@ public function isReturn(): ?bool * Return the package if the recipient is not home * Required: No. * - * @param bool $return + * @param bool $return * * @return self */ @@ -1516,7 +1543,7 @@ public function isSameDayDelivery(): ?bool /** * @param bool $sameDay * - * @return $this + * @return self */ public function setSameDayDelivery(bool $sameDay): self { @@ -1542,6 +1569,14 @@ public function isSignature(): ?bool return $this->signature; } + /** + * @return bool|null + */ + public function hasReceiptCode(): ?bool + { + return $this->receipt_code; + } + /** * @return boolean */ @@ -1562,7 +1597,7 @@ public function hasAgeCheck(): ?bool * Large format package * Required: No. * - * @param bool $largeFormat + * @param bool $largeFormat * * @return self * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException @@ -1575,9 +1610,9 @@ public function setLargeFormat(bool $largeFormat): self } /** - * @param bool $hideSender + * @param bool $hideSender * @codeCoverageIgnore - * @return $this + * @return self */ public function setHideSender(bool $hideSender): self { @@ -1595,9 +1630,9 @@ public function hasHideSender(): ?bool } /** - * @param bool $extraAssurance + * @param bool $extraAssurance * @codeCoverageIgnore - * @return $this + * @return self * @deprecated since 2023 */ public function setExtraAssurance(bool $extraAssurance): self @@ -1620,7 +1655,7 @@ public function hasExtraAssurance(): ?bool * Age check * Required: No. * - * @param bool $ageCheck + * @param bool $ageCheck * * @return AbstractConsignment * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException @@ -1645,7 +1680,7 @@ public function getLabelDescription(): string * Note: This will be overridden for return shipment by the following: Retour – 3SMYPAXXXXXX * Required: No. * - * @param mixed $labelDescription + * @param mixed $labelDescription * * @return self */ @@ -1669,7 +1704,7 @@ public function getInsurance(): int * Composite type containing integer and currency. The amount is without decimal separators. * Required: No. * - * @param int|null $insurance + * @param int|null $insurance * * @return self * @throws \Exception @@ -1696,7 +1731,7 @@ public function setInsurance(?int $insurance): self /** * Required: Yes for non-EU shipments and digital stamps. * - * @param array $physicalProperties + * @param array $physicalProperties * * @return self */ @@ -1735,7 +1770,7 @@ public function getContents(): int * 5. return shipment * Required: Yes for shipping outside EU. * - * @param int $contents + * @param int $contents * * @return self */ @@ -1758,7 +1793,7 @@ public function getInvoice(): ?string * The invoice number for the commercial goods or samples of package contents. * Required: Yes for international shipments. * - * @param string $invoice + * @param string $invoice * * @return self */ @@ -1781,7 +1816,7 @@ public function getItems(): array * A CustomsItem objects with description in the package. * Required: Yes for international shipments. * - * @param \MyParcelNL\Sdk\src\Model\MyParcelCustomsItem $item + * @param \MyParcelNL\Sdk\src\Model\MyParcelCustomsItem $item * * @return self * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException @@ -1822,7 +1857,7 @@ public function getTotalWeight(): int /** * The weight has to be entered in grams. * - * @param int $weight + * @param int $weight * * @return self */ @@ -1968,7 +2003,7 @@ protected function getRowInsurancePossibilities(): array } /** - * @param string $shipmentOption + * @param string $shipmentOption * * @return bool * @throws \MyParcelNL\Sdk\src\Exception\InvalidConsignmentException diff --git a/src/Model/Consignment/PostNLConsignment.php b/src/Model/Consignment/PostNLConsignment.php index e71e3cea..778ecd45 100644 --- a/src/Model/Consignment/PostNLConsignment.php +++ b/src/Model/Consignment/PostNLConsignment.php @@ -17,20 +17,21 @@ class PostNLConsignment extends AbstractConsignment * @var array * @deprecated use getLocalInsurancePossibilities() */ - public const INSURANCE_POSSIBILITIES_LOCAL = [ - 100, - 250, - 500, - 1000, - 1500, - 2000, - 2500, - 3000, - 3500, - 4000, - 4500, - 5000, - ]; + public const INSURANCE_POSSIBILITIES_LOCAL + = [ + 100, + 250, + 500, + 1000, + 1500, + 2000, + 2500, + 3000, + 3500, + 4000, + 4500, + 5000, + ]; /** * @var string @@ -86,6 +87,12 @@ public function getAllowedPackageTypes(): array */ public function getAllowedShipmentOptions(): array { + if ($this->hasReceiptCode()) { + return [ + self::SHIPMENT_OPTION_INSURANCE, + self::SHIPMENT_OPTION_RECEIPT_CODE, + ]; + } return [ self::SHIPMENT_OPTION_AGE_CHECK, self::SHIPMENT_OPTION_INSURANCE, @@ -93,6 +100,7 @@ public function getAllowedShipmentOptions(): array self::SHIPMENT_OPTION_ONLY_RECIPIENT, self::SHIPMENT_OPTION_RETURN, self::SHIPMENT_OPTION_SIGNATURE, + self::SHIPMENT_OPTION_RECEIPT_CODE, ]; } @@ -103,7 +111,9 @@ public function getMandatoryShipmentOptions(): array { $mandatory = []; - if ($this->hasAgeCheck()) { + if ($this->hasReceiptCode()) { + $mandatory[] = self::SHIPMENT_OPTION_INSURANCE; + } elseif ($this->hasAgeCheck()) { $mandatory = array_merge($mandatory, [ self::SHIPMENT_OPTION_ONLY_RECIPIENT, self::SHIPMENT_OPTION_SIGNATURE, diff --git a/src/Model/MyParcelRequest.php b/src/Model/MyParcelRequest.php index 914f7e41..3d4aac28 100644 --- a/src/Model/MyParcelRequest.php +++ b/src/Model/MyParcelRequest.php @@ -34,24 +34,25 @@ class MyParcelRequest /** * API headers. */ - public const HEADER_CONTENT_TYPE_SHIPMENT = [ - 'Content-Type' => 'application/vnd.shipment+json;charset=utf-8;version=1.1', - ]; + public const HEADER_CONTENT_TYPE_SHIPMENT + = [ + 'Content-Type' => 'application/vnd.shipment+json;charset=utf-8;version=1.1', + ]; public const HEADER_ACCEPT_APPLICATION_PDF = ['Accept' => 'application/pdf']; public const HEADER_CONTENT_TYPE_RETURN_SHIPMENT = ['Content-Type' => 'application/vnd.return_shipment+json; charset=utf-8']; /* @deprecated use HEADER_CONTENT_TYPE_SHIPMENT, HEADER_ACCEPT_APPLICATION_PDF or HEADER_CONTENT_TYPE_RETURN_SHIPMENT */ - public const REQUEST_HEADER_SHIPMENT = 'Content-Type: application/vnd.shipment+json;charset=utf-8;version=1.1'; + public const REQUEST_HEADER_SHIPMENT = 'Content-Type: application/vnd.shipment+json;charset=utf-8;version=1.1'; /* @deprecated use HEADER_CONTENT_TYPE_SHIPMENT, HEADER_ACCEPT_APPLICATION_PDF or HEADER_CONTENT_TYPE_RETURN_SHIPMENT */ - public const REQUEST_HEADER_RETRIEVE_SHIPMENT = 'Accept: application/json; charset=utf8'; + public const REQUEST_HEADER_RETRIEVE_SHIPMENT = 'Accept: application/json; charset=utf8'; /* @deprecated use HEADER_CONTENT_TYPE_SHIPMENT, HEADER_ACCEPT_APPLICATION_PDF or HEADER_CONTENT_TYPE_RETURN_SHIPMENT */ public const REQUEST_HEADER_RETRIEVE_LABEL_LINK = 'Accept: application/json; charset=utf8'; /* @deprecated use HEADER_CONTENT_TYPE_SHIPMENT, HEADER_ACCEPT_APPLICATION_PDF or HEADER_CONTENT_TYPE_RETURN_SHIPMENT */ - public const REQUEST_HEADER_RETRIEVE_LABEL_PDF = 'Accept: application/pdf'; + public const REQUEST_HEADER_RETRIEVE_LABEL_PDF = 'Accept: application/pdf'; /* @deprecated use HEADER_CONTENT_TYPE_SHIPMENT, HEADER_ACCEPT_APPLICATION_PDF or HEADER_CONTENT_TYPE_RETURN_SHIPMENT */ - public const REQUEST_HEADER_RETURN = 'Content-Type: application/vnd.return_shipment+json; charset=utf-8'; + public const REQUEST_HEADER_RETURN = 'Content-Type: application/vnd.return_shipment+json; charset=utf-8'; /* @deprecated use HEADER_CONTENT_TYPE_SHIPMENT, HEADER_ACCEPT_APPLICATION_PDF or HEADER_CONTENT_TYPE_RETURN_SHIPMENT */ - public const REQUEST_HEADER_DELETE = 'Accept: application/json; charset=utf8'; + public const REQUEST_HEADER_DELETE = 'Accept: application/json; charset=utf8'; /** * API URL. @@ -125,7 +126,7 @@ public function getHeaders(): array /** * @param $size - * @param MyParcelCollection $collection + * @param MyParcelCollection $collection * @param $key * * @return string|null @@ -160,8 +161,8 @@ public function getRequestUrl(): string /** * Get an item from the result using dot notation. * - * @param string|null $key - * @param string|null $pluck + * @param string|null $key + * @param string|null $pluck * * @return mixed */ @@ -183,8 +184,8 @@ public function getResult(string $key = null, string $pluck = null) /** * Send the created request to MyParcel. * - * @param string $method - * @param string $uri + * @param string $method + * @param string $uri * * @return self|bool * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException @@ -212,7 +213,7 @@ public function sendRequest(string $method = 'POST', string $uri = self::REQUEST } /** - * @param string|array $requestHeaders + * @param string|array $requestHeaders * * @return self */ @@ -228,7 +229,7 @@ public function setHeaders($requestHeaders): self } /** - * @param array $parameters + * @param array $parameters * * @return self */ @@ -239,7 +240,7 @@ public function setQuery(array $parameters): self } /** - * @param \MyParcelNL\Sdk\src\Model\RequestBody|array|string|null $body + * @param \MyParcelNL\Sdk\src\Model\RequestBody|array|string|null $body * * @return self */ @@ -261,9 +262,9 @@ public function setRequestBody($body): self * Sets the parameters for an API call based on a string with all required request parameters and the requested API * method. * - * @param string $apiKey - * @param array|string|null $body - * @param string|array $requestHeaders + * @param string $apiKey + * @param array|string|null $body + * @param string|array $requestHeaders * * @return self */ @@ -309,8 +310,8 @@ private function checkMyParcelErrors(): void } /** - * @param string $uri - * @param string $method + * @param string $uri + * @param string $method * * @return string */ @@ -334,7 +335,7 @@ private function createRequestUrl(string $uri, string $method): string /** * Get all consignment ids. * - * @param MyParcelCollection|AbstractConsignment[] $consignments + * @param MyParcelCollection|AbstractConsignment[] $consignments * @param $key * * @return array @@ -377,7 +378,7 @@ private function getRequestBody(): ?string } /** - * @param string $url + * @param string $url * * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException * @throws \MyParcelNL\Sdk\src\Exception\ApiException @@ -407,17 +408,17 @@ private function handleErrors(string $url): void private function instantiateCurl(): MyParcelCurl { return (new MyParcelCurl())->setConfig([ - 'header' => 0, - 'timeout' => 60, - ])->addOptions([ - CURLOPT_POST => true, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_AUTOREFERER => true, - ]); + 'header' => 0, + 'timeout' => 60, + ])->addOptions([ + CURLOPT_POST => true, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_AUTOREFERER => true, + ]); } /** - * @param MyParcelCurl $request + * @param MyParcelCurl $request * * @return array * @throws \Exception diff --git a/src/Services/ConsignmentEncode.php b/src/Services/ConsignmentEncode.php index 0ef6032f..31af7b58 100644 --- a/src/Services/ConsignmentEncode.php +++ b/src/Services/ConsignmentEncode.php @@ -12,6 +12,7 @@ namespace MyParcelNL\Sdk\src\Services; +use Exception; use InvalidArgumentException; use MyParcelNL\Sdk\src\Exception\MissingFieldException; use MyParcelNL\Sdk\src\Model\Carrier\CarrierDHLEuroplus; @@ -25,7 +26,7 @@ class ConsignmentEncode { - public const DEFAULT_CURRENCY = 'EUR'; + public const DEFAULT_CURRENCY = 'EUR'; private const MAX_INSURANCE_PACKETS_ROW = 5000; /** @@ -56,18 +57,18 @@ public function __construct($consignments) public function apiEncode(): array { $this->encodeBase() - ->encodeStreet(); + ->encodeStreet(); $this->consignmentEncoded = self::encodeExtraOptions( $this->consignmentEncoded, Arr::first($this->consignments) ); $this->encodeDeliveryType() - ->encodePickup() - ->encodePhysicalProperties() - ->encodeCdCountry() - ->encodeMultiCollo() - ->encodeDropOffPoint(); + ->encodePickup() + ->encodePhysicalProperties() + ->encodeCdCountry() + ->encodeMultiCollo() + ->encodeDropOffPoint(); return $this->consignmentEncoded; } @@ -84,14 +85,15 @@ public static function encodeExtraOptions(array $consignmentEncoded, AbstractCon $consignmentEncoded, [ 'options' => Helpers::toArrayWithoutNull([ - 'package_type' => $consignment->getPackageType(AbstractConsignment::DEFAULT_PACKAGE_TYPE), - 'label_description' => $consignment->getLabelDescription(), - 'only_recipient' => Helpers::intOrNull($consignment->isOnlyRecipient()), - 'signature' => Helpers::intOrNull($consignment->isSignature()), - 'return' => Helpers::intOrNull($consignment->isReturn()), - 'same_day_delivery' => Helpers::intOrNull($consignment->isSameDayDelivery()), - 'hide_sender' => Helpers::intOrNull($consignment->hasHideSender()), - 'extra_assurance' => Helpers::intOrNull($consignment->hasExtraAssurance()), + 'package_type' => $consignment->getPackageType(AbstractConsignment::DEFAULT_PACKAGE_TYPE), + 'label_description' => $consignment->getLabelDescription(), + 'only_recipient' => Helpers::intOrNull($consignment->isOnlyRecipient()), + 'signature' => Helpers::intOrNull($consignment->isSignature()), + 'receipt_code' => Helpers::intOrNull($consignment->hasReceiptCode()), + 'return' => Helpers::intOrNull($consignment->isReturn()), + 'same_day_delivery' => Helpers::intOrNull($consignment->isSameDayDelivery()), + 'hide_sender' => Helpers::intOrNull($consignment->hasHideSender()), + 'extra_assurance' => Helpers::intOrNull($consignment->hasExtraAssurance()), ]), ] ); @@ -120,7 +122,7 @@ public static function encodeExtraOptions(array $consignmentEncoded, AbstractCon if ($consignment->getInsurance() > 1) { $consignmentEncoded['options']['insurance'] = [ - 'amount' => (int) $consignment->getInsurance() * 100, + 'amount' => $consignment->getInsurance() * 100, 'currency' => self::DEFAULT_CURRENCY, ]; } @@ -144,7 +146,13 @@ public static function encodeExtraOptions(array $consignmentEncoded, AbstractCon $key = "options.$option"; $value = Arr::get($consignmentEncoded, $key); - if (null === $value || 0 === $value) { + if (AbstractConsignment::SHIPMENT_OPTION_INSURANCE === $option) { + $minimumAmount = $consignment->getInsurancePossibilities()[0] ?? 0; + Arr::set($consignmentEncoded, $key, [ + 'amount' => $consignment->getInsurance() * 100 ?: $minimumAmount, + 'currency' => self::DEFAULT_CURRENCY, + ]); + } elseif (null === $value || 0 === $value) { Arr::set($consignmentEncoded, $key, 1); } } @@ -168,6 +176,7 @@ private function encodeDeliveryType(): self { /** @var AbstractConsignment $consignment */ $consignment = Arr::first($this->consignments); + $this->consignmentEncoded['options']['delivery_type'] = $consignment->getDeliveryType(); return $this; @@ -324,7 +333,7 @@ private function encodeCdCountry(): self /** * Encode product for the request * - * @param MyParcelCustomsItem $customsItem + * @param MyParcelCustomsItem $customsItem * * @return array */ @@ -379,7 +388,7 @@ private function encodeMultiCollo(): self /** @var AbstractConsignment $first */ $first = Arr::first($this->consignments); if (count($this->consignments) > 1 && ! $first->isPartOfMultiCollo()) { - throw new \Exception("Can not encode multi collo with this consignment."); + throw new Exception("Can not encode multi collo with this consignment."); } $secondaryShipments = $this->consignments;