Skip to content
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
8 changes: 8 additions & 0 deletions src/Resources/Interfaces/ShipmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions src/Resources/Proxy/ShipmentProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 16 additions & 0 deletions src/Resources/ResourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
28 changes: 28 additions & 0 deletions src/Resources/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions tests/Feature/Proxy/ShipmentProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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());
Expand Down
36 changes: 36 additions & 0 deletions tests/Feature/ResourceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down Expand Up @@ -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',
Expand Down
36 changes: 36 additions & 0 deletions tests/Unit/Resources/ShipmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -780,6 +796,7 @@ public function testJsonSerialize()
->setDescription('Fidget spinners')
->setCustomerReference('#012ASD')
->setPickupLocationCode('CODE123')
->setDropOffLocationCode('ABC456')
->setPrice(99)
->setTotalValueAmount(100)
->setTotalValueCurrency('EUR')
Expand All @@ -802,6 +819,7 @@ public function testJsonSerialize()
->setSenderTaxNumber('G666666-66')
->setReturnAddress($returnAddress)
->setPickupLocationAddress($pudoAddress)
->setDropOffLocationAddress($pudoAddress)
->setCustoms($customs)
->setItems([$item])
->setRegisterAt(9001)
Expand Down Expand Up @@ -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',
Expand Down