From 7eb0a4fc7da352d25146588e586e821b0e16bf31 Mon Sep 17 00:00:00 2001 From: yoeriwalstra Date: Tue, 2 Jun 2026 16:34:57 +0200 Subject: [PATCH 1/3] add Shipment drop off attribute and getter setter --- .../Interfaces/ShipmentInterface.php | 8 +++++ src/Resources/Shipment.php | 28 +++++++++++++++ tests/Unit/Resources/ShipmentTest.php | 36 +++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/src/Resources/Interfaces/ShipmentInterface.php b/src/Resources/Interfaces/ShipmentInterface.php index b1f7e41a..498ca340 100644 --- a/src/Resources/Interfaces/ShipmentInterface.php +++ b/src/Resources/Interfaces/ShipmentInterface.php @@ -74,6 +74,14 @@ public function setPickupLocationAddress(?AddressInterface $pickupLocationAddres public function getPickupLocationAddress(): ?AddressInterface; + public function setDropOffLocationCode(?string $dropOffLocationCode): self; + + public function getDropOffLocationCode(): ?string; + + public function setDropOffLocationAddress(?AddressInterface $dropOffLocationAddress): self; + + public function getDropOffLocationAddress(): ?AddressInterface; + public function setChannel(?string $channel): self; public function getChannel(): ?string; diff --git a/src/Resources/Shipment.php b/src/Resources/Shipment.php index dd3f73a4..7cd4b117 100644 --- a/src/Resources/Shipment.php +++ b/src/Resources/Shipment.php @@ -53,6 +53,9 @@ class Shipment implements ShipmentInterface const ATTRIBUTE_PICKUP = 'pickup_location'; const ATTRIBUTE_PICKUP_CODE = 'code'; const ATTRIBUTE_PICKUP_ADDRESS = 'address'; + const ATTRIBUTE_DROP_OFF = 'drop_off_location'; + const ATTRIBUTE_DROP_OFF_CODE = 'code'; + const ATTRIBUTE_DROP_OFF_ADDRESS = 'address'; const ATTRIBUTE_CUSTOMS = 'customs'; const ATTRIBUTE_ITEMS = 'items'; const ATTRIBUTE_REGISTER_AT = 'register_at'; @@ -108,6 +111,7 @@ class Shipment implements ShipmentInterface self::ATTRIBUTE_SENDER_TAX_IDENTIFICATION_NUMBERS => null, self::ATTRIBUTE_RETURN_ADDRESS => null, self::ATTRIBUTE_PICKUP => null, + self::ATTRIBUTE_DROP_OFF => null, self::ATTRIBUTE_CUSTOMS => null, self::ATTRIBUTE_ITEMS => null, self::ATTRIBUTE_REGISTER_AT => null, @@ -326,6 +330,30 @@ public function getPickupLocationAddress(): ?AddressInterface return $this->attributes[self::ATTRIBUTE_PICKUP][self::ATTRIBUTE_PICKUP_ADDRESS] ?? null; } + public function setDropOffLocationCode(?string $dropOffLocationCode): self + { + $this->attributes[self::ATTRIBUTE_DROP_OFF][self::ATTRIBUTE_DROP_OFF_CODE] = $dropOffLocationCode; + + return $this; + } + + public function getDropOffLocationCode(): ?string + { + return $this->attributes[self::ATTRIBUTE_DROP_OFF][self::ATTRIBUTE_DROP_OFF_CODE] ?? null; + } + + public function setDropOffLocationAddress(?AddressInterface $dropOffLocationAddress): self + { + $this->attributes[self::ATTRIBUTE_DROP_OFF][self::ATTRIBUTE_DROP_OFF_ADDRESS] = $dropOffLocationAddress; + + return $this; + } + + public function getDropOffLocationAddress(): ?AddressInterface + { + return $this->attributes[self::ATTRIBUTE_DROP_OFF][self::ATTRIBUTE_DROP_OFF_ADDRESS] ?? null; + } + public function setChannel(?string $channel): self { $this->attributes[self::ATTRIBUTE_CHANNEL] = $channel; diff --git a/tests/Unit/Resources/ShipmentTest.php b/tests/Unit/Resources/ShipmentTest.php index c8a0dd51..1d69639f 100644 --- a/tests/Unit/Resources/ShipmentTest.php +++ b/tests/Unit/Resources/ShipmentTest.php @@ -135,6 +135,22 @@ public function testPickupLocationAddress() $this->assertEquals($address, $shipment->setPickupLocationAddress($address)->getPickupLocationAddress()); } + /** @test */ + public function testDropOffLocationCode() + { + $shipment = new Shipment(); + $this->assertEquals('CODE123', $shipment->setDropOffLocationCode('CODE123')->getDropOffLocationCode()); + } + + /** @test */ + public function testDropOffLocationAddress() + { + $shipment = new Shipment(); + $address = $this->getMockBuilder(AddressInterface::class)->getMock(); + + $this->assertEquals($address, $shipment->setDropOffLocationAddress($address)->getDropOffLocationAddress()); + } + /** @test */ public function testChannel() { @@ -780,6 +796,7 @@ public function testJsonSerialize() ->setDescription('Fidget spinners') ->setCustomerReference('#012ASD') ->setPickupLocationCode('CODE123') + ->setDropOffLocationCode('ABC456') ->setPrice(99) ->setTotalValueAmount(100) ->setTotalValueCurrency('EUR') @@ -802,6 +819,7 @@ public function testJsonSerialize() ->setSenderTaxNumber('G666666-66') ->setReturnAddress($returnAddress) ->setPickupLocationAddress($pudoAddress) + ->setDropOffLocationAddress($pudoAddress) ->setCustoms($customs) ->setItems([$item]) ->setRegisterAt(9001) @@ -897,6 +915,24 @@ public function testJsonSerialize() 'phone_number' => '+31 (0)234 567 890', ], ], + 'drop_off_location' => [ + 'code' => 'ABC456', + 'address' => [ + 'street_1' => 'Diagonally', + 'street_2' => 'Apartment 4', + 'street_number' => 3, + 'street_number_suffix' => 'A', + 'postal_code' => '1AR BR2', + 'city' => 'London', + 'region_code' => 'NH', + 'country_code' => 'AF', + 'first_name' => 'Robert', + 'last_name' => 'Drop Tables', + 'company' => 'ACME co.', + 'email' => 'rob@tables.com', + 'phone_number' => '+31 (0)234 567 890', + ], + ], 'items' => [ [ 'sku' => '123456789', From 3c53ff2c95bb1cf3bb8be4fc4964a40acc84eb21 Mon Sep 17 00:00:00 2001 From: yoeriwalstra Date: Tue, 2 Jun 2026 16:35:31 +0200 Subject: [PATCH 2/3] add ShipmentProxy drop off attribute and getter setter --- src/Resources/Proxy/ShipmentProxy.php | 24 +++++++++++++++++++++++ tests/Feature/Proxy/ShipmentProxyTest.php | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/src/Resources/Proxy/ShipmentProxy.php b/src/Resources/Proxy/ShipmentProxy.php index 95b4c581..04acb36e 100644 --- a/src/Resources/Proxy/ShipmentProxy.php +++ b/src/Resources/Proxy/ShipmentProxy.php @@ -184,6 +184,30 @@ public function getPickupLocationAddress(): ?AddressInterface return $this->getResource()->getPickupLocationAddress(); } + public function setDropOffLocationCode(?string $dropOffLocationCode): self + { + $this->getResource()->setDropOffLocationCode($dropOffLocationCode); + + return $this; + } + + public function getDropOffLocationCode(): ?string + { + return $this->getResource()->getDropOffLocationCode(); + } + + public function setDropOffLocationAddress(?AddressInterface $dropOffLocationAddress): self + { + $this->getResource()->setDropOffLocationAddress($dropOffLocationAddress); + + return $this; + } + + public function getDropOffLocationAddress(): ?AddressInterface + { + return $this->getResource()->getDropOffLocationAddress(); + } + public function setChannel(?string $channel): self { $this->getResource()->setChannel($channel); diff --git a/tests/Feature/Proxy/ShipmentProxyTest.php b/tests/Feature/Proxy/ShipmentProxyTest.php index 40bfcc3a..d6be7b6b 100644 --- a/tests/Feature/Proxy/ShipmentProxyTest.php +++ b/tests/Feature/Proxy/ShipmentProxyTest.php @@ -68,6 +68,7 @@ public function testAccessors() $this->assertEquals('|||||||||||||', $this->shipmentProxy->setBarcode('|||||||||||||')->getBarcode()); $this->assertEquals(12, $this->shipmentProxy->setWeight(12)->getWeight()); $this->assertEquals('80-90A', $this->shipmentProxy->setPickupLocationCode('80-90A')->getPickupLocationCode()); + $this->assertEquals('80-90A', $this->shipmentProxy->setDropOffLocationCode('80-90A')->getDropOffLocationCode()); $this->assertEquals('an-id-for-a-shipment', $this->shipmentProxy->setId('an-id-for-a-shipment')->getId()); /** @var ServiceInterface $service */ @@ -102,6 +103,10 @@ public function testAccessors() $pickupLocationAddress = $this->getMockBuilder(AddressInterface::class)->getMock(); $this->assertEquals($pickupLocationAddress, $this->shipmentProxy->setPickupLocationAddress($pickupLocationAddress)->getPickupLocationAddress()); + /** @var AddressInterface $dropOffLocationAddress */ + $dropOffLocationAddress = $this->getMockBuilder(AddressInterface::class)->getMock(); + $this->assertEquals($dropOffLocationAddress, $this->shipmentProxy->setDropOffLocationAddress($dropOffLocationAddress)->getDropOffLocationAddress()); + /** @var AddressInterface $recipientAddress */ $recipientAddress = $this->getMockBuilder(AddressInterface::class)->getMock(); $this->assertEquals($recipientAddress, $this->shipmentProxy->setRecipientAddress($recipientAddress)->getRecipientAddress()); From 24fdd7d4084cc31248d7729bb94d7ba68d3697e0 Mon Sep 17 00:00:00 2001 From: yoeriwalstra Date: Tue, 2 Jun 2026 16:36:14 +0200 Subject: [PATCH 3/3] add drop off attribute to ResourceFactory::shipmentFactory --- src/Resources/ResourceFactory.php | 16 ++++++++++++ tests/Feature/ResourceFactoryTest.php | 36 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/Resources/ResourceFactory.php b/src/Resources/ResourceFactory.php index 63a0abef..4244fa5a 100644 --- a/src/Resources/ResourceFactory.php +++ b/src/Resources/ResourceFactory.php @@ -189,6 +189,22 @@ protected function shipmentFactory(array &$data): Shipment unset($data['attributes']['pickup_location']); } + if (isset($data['attributes']['drop_off_location']['code'])) { + $shipment->setDropOffLocationCode($data['attributes']['drop_off_location']['code']); + } + + if (isset($data['attributes']['drop_off_location']['address'])) { + /** @var AddressInterface $pudoAddress */ + $pudoAddress = $this->create( + AddressInterface::class, + $data['attributes']['drop_off_location']['address'], + ); + + $shipment->setDropOffLocationAddress($pudoAddress); + + unset($data['attributes']['drop_off_location']); + } + if (isset($data['id'])) { $shipment->setStatusHistoryCallback(function () use ($data) { return $this->api->getResourcesFromUri( diff --git a/tests/Feature/ResourceFactoryTest.php b/tests/Feature/ResourceFactoryTest.php index 0281f676..f5cda317 100644 --- a/tests/Feature/ResourceFactoryTest.php +++ b/tests/Feature/ResourceFactoryTest.php @@ -528,6 +528,24 @@ public function testCreateShipment() 'phone_number' => '+31 (0)234 567 890', ], ], + 'drop_off_location' => [ + 'code' => 'ABC345', + 'address' => [ + 'street_1' => 'Diagonally', + 'street_2' => 'Apartment 41', + 'street_number' => 2, + 'street_number_suffix' => 'A', + 'postal_code' => '1AR BR2', + 'city' => 'London', + 'region_code' => 'NH', + 'country_code' => 'AF', + 'first_name' => 'Robert', + 'last_name' => 'Drop Tables', + 'company' => 'ACME co.', + 'email' => 'rob@tables.com', + 'phone_number' => '+31 (0)234 567 890', + ], + ], 'register_at' => 1526913941, ], 'relationships' => [ @@ -622,6 +640,24 @@ public function testCreateShipmentWithCustoms() 'phone_number' => '+31 (0)234 567 890', ], ], + 'drop_off_location' => [ + 'code' => 'ABC345', + 'address' => [ + 'street_1' => 'Diagonally', + 'street_2' => 'Apartment 41', + 'street_number' => 2, + 'street_number_suffix' => 'A', + 'postal_code' => '1AR BR2', + 'city' => 'London', + 'region_code' => 'NH', + 'country_code' => 'AF', + 'first_name' => 'Robert', + 'last_name' => 'Drop Tables', + 'company' => 'ACME co.', + 'email' => 'rob@tables.com', + 'phone_number' => '+31 (0)234 567 890', + ], + ], 'items' => [ [ 'sku' => '123456789',