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 carrier ups #463

Merged
merged 10 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
}

Expand Down
3 changes: 2 additions & 1 deletion src/Model/Carrier/CarrierFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class CarrierFactory
CarrierPostNL::class,
CarrierDHLForYou::class,
CarrierDHLParcelConnect::class,
CarrierDHLEuroplus::class
CarrierDHLEuroplus::class,
CarrierUPS::class
];

/**
Expand Down
35 changes: 35 additions & 0 deletions src/Model/Carrier/CarrierUPS.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Carrier;

use MyParcelNL\Sdk\src\Model\Consignment\UPSConsignment;

class CarrierUPS extends AbstractCarrier
{
public const CONSIGNMENT = UPSConsignment::class;
public const HUMAN = 'UPS';
public const ID = 8;
public const NAME = 'ups';

/**
* @var class-string
*/
protected $consignmentClass = self::CONSIGNMENT;

/**
* @var string
*/
protected $human = self::HUMAN;

/**
* @var int
*/
protected $id = self::ID;

/**
* @var string
*/
protected $name = self::NAME;
}
57 changes: 57 additions & 0 deletions src/Model/Consignment/UPSConsignment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Model\Consignment;

use MyParcelNL\Sdk\src\Model\Carrier\CarrierUPS;
use MyParcelNL\Sdk\src\Validator\Consignment\UPSConsignmentValidator;

class UPSConsignment extends AbstractConsignment
{
public const DEFAULT_WEIGHT = 3000;

/**
* @internal
* @var int
*/
public $physical_properties = ['weight' => 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,
];
}
}
25 changes: 25 additions & 0 deletions src/Validator/Consignment/UPSConsignmentValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\src\Validator\Consignment;

use MyParcelNL\Sdk\src\Rule\Consignment\DeliveryDateRule;
use MyParcelNL\Sdk\src\Rule\Consignment\MinimumWeightRule;
use MyParcelNL\Sdk\src\Rule\Consignment\ShipmentOptionsRule;
use MyParcelNL\Sdk\src\Validator\AbstractValidator;

class UPSConsignmentValidator extends AbstractValidator
{
/**
* @return \MyParcelNL\Sdk\src\Rule\Rule[]
*/
protected function getRules(): array
{
return [
new DeliveryDateRule(),
new MinimumWeightRule(),
new ShipmentOptionsRule(),
];
}
}
6 changes: 3 additions & 3 deletions test/Model/Consignment/DHLForYouConsignmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public function provideDHLForYouConsignmentsData(): array
self::expected(self::RETURN) => 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,
],
]);
Expand Down
55 changes: 55 additions & 0 deletions test/Model/Consignment/UPSConsignmentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Sdk\Test\Model\Consignment;

use MyParcelNL\Sdk\src\Model\Carrier\CarrierUPS;
use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment;
use MyParcelNL\Sdk\Test\Bootstrap\ConsignmentTestCase;

class UPSConsignmentTest extends ConsignmentTestCase
{
/**
* @return array
* @throws \Exception
*/
public function provideUPSConsignmentsData(): array
{
return $this->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',
]
);
}
}