diff --git a/src/Helper/MyParcelCollection.php b/src/Helper/MyParcelCollection.php index a2984318..805f641c 100644 --- a/src/Helper/MyParcelCollection.php +++ b/src/Helper/MyParcelCollection.php @@ -23,6 +23,7 @@ use MyParcelNL\Sdk\src\Exception\MissingFieldException; use MyParcelNL\Sdk\src\Factory\ConsignmentFactory; use MyParcelNL\Sdk\src\Model\Carrier\CarrierInstabox; +use MyParcelNL\Sdk\src\Model\Carrier\CarrierUPS; use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment; use MyParcelNL\Sdk\src\Model\Consignment\BaseConsignment; use MyParcelNL\Sdk\src\Model\MyParcelRequest; @@ -829,7 +830,7 @@ private function getNewCollectionFromResult($result): self $consignment = ConsignmentFactory::createByCarrierId($shipment['carrier_id'])->setApiKey($apiKey); //TODO: MY-32524 Make AbstractConsignmentAdapter for carrier specific exceptions - if (CarrierInstabox::ID === $shipment['carrier_id']) { + if (CarrierInstabox::ID === $shipment['carrier_id'] || CarrierUPS::ID === $shipment['carrier_id']) { $shipment['barcode'] = $shipment['barcode'] ?: $shipment['external_identifier']; } diff --git a/src/Model/Carrier/CarrierFactory.php b/src/Model/Carrier/CarrierFactory.php index 7729c82d..c11ba7dc 100644 --- a/src/Model/Carrier/CarrierFactory.php +++ b/src/Model/Carrier/CarrierFactory.php @@ -18,7 +18,8 @@ class CarrierFactory CarrierPostNL::class, CarrierDHLForYou::class, CarrierDHLParcelConnect::class, - CarrierDHLEuroplus::class + CarrierDHLEuroplus::class, + CarrierUPS::class ]; /** diff --git a/src/Model/Carrier/CarrierUPS.php b/src/Model/Carrier/CarrierUPS.php new file mode 100644 index 00000000..616b5754 --- /dev/null +++ b/src/Model/Carrier/CarrierUPS.php @@ -0,0 +1,35 @@ + self::DEFAULT_WEIGHT]; + + /** + * @var string + */ + protected $carrierClass = CarrierUPS::class; + + /** + * @var string + */ + protected $validatorClass = UPSConsignmentValidator::class; + + /** + * @return string + */ + public function getLocalCountryCode(): string + { + return self::CC_NL; + } + + /** + * @return array|string[] + */ + public function getAllowedPackageTypes(): array + { + return [ + self::PACKAGE_TYPE_PACKAGE_NAME, + ]; + } + + /** + * @return array|string[] + */ + public function getAllowedDeliveryTypes(): array + { + return [ + self::DELIVERY_TYPE_STANDARD, + ]; + } +} diff --git a/src/Validator/Consignment/UPSConsignmentValidator.php b/src/Validator/Consignment/UPSConsignmentValidator.php new file mode 100644 index 00000000..03b8dc77 --- /dev/null +++ b/src/Validator/Consignment/UPSConsignmentValidator.php @@ -0,0 +1,25 @@ + false, self::SAME_DAY_DELIVERY => true, ], - 'Age check' => [ - self::AGE_CHECK => true, - self::ONLY_RECIPIENT => true, + 'Age check' => [ + self::AGE_CHECK => true, + self::ONLY_RECIPIENT => true, self::expected(self::ONLY_RECIPIENT) => false, ], ]); diff --git a/test/Model/Consignment/UPSConsignmentTest.php b/test/Model/Consignment/UPSConsignmentTest.php new file mode 100644 index 00000000..81b3ad60 --- /dev/null +++ b/test/Model/Consignment/UPSConsignmentTest.php @@ -0,0 +1,55 @@ +createConsignmentProviderDataset([ + 'NL -> EU' => [], + ]); + } + + /** + * @param array $testData + * + * @throws \Exception + * @throws \Exception + * @dataProvider provideUPSConsignmentsData + */ + public function testUPSForYouConsignments(array $testData): void + { + $this->doConsignmentTest($testData); + } + + /** + * @return array|string[] + * @throws \Exception + */ + protected function getDefaultConsignmentData(): array + { + return array_replace( + parent::getDefaultConsignmentData(), + [ + self::CARRIER_ID => CarrierUPS::ID, + self::PACKAGE_TYPE => AbstractConsignment::PACKAGE_TYPE_PACKAGE, + self::FULL_STREET => 'Feldstrasse 17', + self::POSTAL_CODE => '39394', + self::CITY => 'Schwanebeck', + self::COUNTRY => 'DE', + self::PHONE => '123456', + ] + ); + } +}