Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add package type package_small #471

Merged
merged 9 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Model/Consignment/AbstractConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,36 @@ abstract class AbstractConsignment
public const PACKAGE_TYPE_MAILBOX = 2;
public const PACKAGE_TYPE_LETTER = 3;
public const PACKAGE_TYPE_DIGITAL_STAMP = 4;
public const PACKAGE_TYPE_PACKAGE_SMALL = 6;

public const PACKAGE_TYPE_PACKAGE_NAME = 'package';
public const PACKAGE_TYPE_MAILBOX_NAME = 'mailbox';
public const PACKAGE_TYPE_LETTER_NAME = 'letter';
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 DEFAULT_PACKAGE_TYPE = self::PACKAGE_TYPE_PACKAGE;
Expand Down
1 change: 1 addition & 0 deletions src/Model/Consignment/PostNLConsignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function getAllowedPackageTypes(): array
self::PACKAGE_TYPE_MAILBOX_NAME,
self::PACKAGE_TYPE_LETTER_NAME,
self::PACKAGE_TYPE_DIGITAL_STAMP_NAME,
self::PACKAGE_TYPE_PACKAGE_SMALL_NAME,
];
}

Expand Down
7 changes: 7 additions & 0 deletions src/Rule/Consignment/MaximumWeightRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class MaximumWeightRule extends Rule
* @var int
*/
public const MAX_COLLO_WEIGHT_DIGITAL_STAMP_GRAMS = 2000;
/**
* @var int
*/
public const MAX_COLLO_WEIGHT_PACKAGE_SMALL_GRAMS = 2000;

/**
* @param \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment $validationSubject
Expand All @@ -50,6 +54,9 @@ public function validate($validationSubject): void
case AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP:
$weightLimit = self::MAX_COLLO_WEIGHT_DIGITAL_STAMP_GRAMS;
break;
case AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL:
$weightLimit = self::MAX_COLLO_WEIGHT_PACKAGE_SMALL_GRAMS;
break;
default:
$weightLimit = null;
}
Expand Down
21 changes: 19 additions & 2 deletions src/Services/ConsignmentEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
];
}

if (AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL === $consignment->getPackageType()) {
$consignmentEncoded['options']['tracked'] = 1;
}

foreach ($consignment->getMandatoryShipmentOptions() as $option) {
$key = "options.$option";
$value = Arr::get($consignmentEncoded, $key);
Expand Down Expand Up @@ -271,6 +275,9 @@
* @var \MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment $consignment
*/
$consignment = Arr::first($this->consignments);

var_dump($consignment);

if ($consignment->isToEuCountry()) {
return $this;
}
Expand Down Expand Up @@ -334,8 +341,18 @@
throw new MissingFieldException('Product data must be set for international MyParcel shipments. Use addItem().');
}

if ($consignment->getPackageType() !== AbstractConsignment::PACKAGE_TYPE_PACKAGE && $consignment->getPackageType() !== AbstractConsignment::PACKAGE_TYPE_LETTER) {
throw new MissingFieldException('For international shipments, package_type must be 1 (normal package) or 3 (letter).');
if (! in_array(
$consignment->getPackageType(),
[
AbstractConsignment::PACKAGE_TYPE_PACKAGE,
AbstractConsignment::PACKAGE_TYPE_LETTER,
AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL,
],
true
)) {
throw new MissingFieldException(
'For international shipments, package_type must be 1 (normal package), 3 (letter) or 6 (small package).'

Check warning on line 354 in src/Services/ConsignmentEncode.php

View check run for this annotation

Codecov / codecov/patch

src/Services/ConsignmentEncode.php#L353-L354

Added lines #L353 - L354 were not covered by tests
);
}

if (empty($consignment->getInvoice())) {
Expand Down
7 changes: 7 additions & 0 deletions test/Bootstrap/ConsignmentTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,13 @@ protected function getDefaultAddress(string $country = AbstractConsignment::CC_N
self::POSTAL_CODE => '2000',
self::CITY => 'Antwerpen',
];
case 'DE':
return [
self::COUNTRY => 'DE',
self::FULL_STREET => 'Kurfürstendamm 195',
self::POSTAL_CODE => '10707',
self::CITY => 'Berlin',
];
case 'CA':
return [
self::COUNTRY => 'CA',
Expand Down
13 changes: 13 additions & 0 deletions test/Model/Consignment/PostNLConsignmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ public function providePostNLConsignmentsData(): array
self::expected(self::ONLY_RECIPIENT) => true,
self::expected(self::SIGNATURE) => true,
],
'Letter' => [
self::PACKAGE_TYPE => AbstractConsignment::PACKAGE_TYPE_LETTER,
self::expected(self::DELIVERY_TYPE) => AbstractConsignment::DELIVERY_TYPE_STANDARD,
],
'Small package' => $this->getDefaultAddress('DE') + [
self::PACKAGE_TYPE => AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL,
self::expected(self::DELIVERY_TYPE) => AbstractConsignment::DELIVERY_TYPE_STANDARD,
],
'Customs declaration' => array_merge($this->getDefaultConsignmentData(), $this->getDefaultAddress('CA'), [
self::PACKAGE_TYPE => AbstractConsignment::PACKAGE_TYPE_PACKAGE,
self::CUSTOMS_DECLARATION => $this->getDefaultCustomsDeclaration(),
self::expected(self::DELIVERY_TYPE) => AbstractConsignment::DELIVERY_TYPE_STANDARD,
]),
]);
}

Expand Down
Loading