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
2 changes: 0 additions & 2 deletions src/MyParcelComApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace MyParcelCom\ApiSdk;

use DateMalformedStringException;
use DateTimeImmutable;
use DateTimeInterface;
use GuzzleHttp\Psr7\Message;
Expand Down Expand Up @@ -1004,7 +1003,6 @@ public function deleteShipmentSurcharge(ShipmentSurchargeInterface $shipmentSurc
* @return list<array{ date_from: DateTimeImmutable, date_to: DateTimeImmutable }>
* @throws RequestException
* @throws JsonException
* @throws DateMalformedStringException
*/
public function getDeliveryDates(
string $carrierCode,
Expand Down
2 changes: 0 additions & 2 deletions src/MyParcelComApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace MyParcelCom\ApiSdk;

use DateMalformedStringException;
use DateTimeImmutable;
use DateTimeInterface;
use JsonException;
Expand Down Expand Up @@ -278,7 +277,6 @@ public function generateManifestForCollection(CollectionInterface $collection):
* }>
* @throws RequestException
* @throws JsonException
* @throws DateMalformedStringException
*/
public function getDeliveryDates(
string $carrierCode,
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 @@ -572,13 +572,37 @@ public function clearTags(): self
return $this;
}

public function setAddToNextCollection(bool $addToNextCollection): self
{
$this->getResource()->setAddToNextCollection($addToNextCollection);

return $this;
}

public function setCollectionMeta(
DateTime|int|string $from,
DateTime|int|string $to,
?string $description = null,
): self {
$this->getResource()->setCollectionMeta($from, $to, $description);

return $this;
}

public function setLabelMimeType(string $labelMimeType): self
{
$this->getResource()->setLabelMimeType($labelMimeType);

return $this;
}

public function setLabelSize(string $labelSize): self
{
$this->getResource()->setLabelSize($labelSize);

return $this;
}

public function setCollection(?CollectionInterface $collection): self
{
$this->getResource()->setCollection($collection);
Expand Down
58 changes: 54 additions & 4 deletions src/Resources/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTime;
use MyParcelCom\ApiSdk\Enums\DimensionUnitEnum;
use MyParcelCom\ApiSdk\LabelCombinerInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\AddressInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\CollectionInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\ContractInterface;
Expand Down Expand Up @@ -74,7 +75,15 @@ class Shipment implements ShipmentInterface
const RELATIONSHIP_COLLECTION = 'collection';
const RELATIONSHIP_SHIPMENT_SURCHARGES = 'shipment_surcharges';

const META_LABEL_MIME_TYPE = 'label_mime_type';
const META_COLLECTION = 'collection';
const META_COLLECTION_DESCRIPTION = 'description';
const META_COLLECTION_TIME = 'collection_time';
const META_COLLECTION_TIME_FROM = 'from';
const META_COLLECTION_TIME_TO = 'to';
const META_ADD_TO_NEXT_COLLECTION = 'add_to_next_collection';
const META_LABEL = 'label';
const META_LABEL_MIME_TYPE = 'mime_type';
const META_LABEL_SIZE = 'size';
const META_SERVICE_CODE = 'service_code';

const INCLUDES = [
Expand Down Expand Up @@ -157,8 +166,13 @@ class Shipment implements ShipmentInterface
];

private array $meta = [
self::META_LABEL_MIME_TYPE => FileInterface::MIME_TYPE_PDF,
self::META_SERVICE_CODE => null,
self::META_COLLECTION => [],
self::META_ADD_TO_NEXT_COLLECTION => false,
self::META_LABEL => [
self::META_LABEL_MIME_TYPE => FileInterface::MIME_TYPE_PDF,
self::META_LABEL_SIZE => LabelCombinerInterface::PAGE_SIZE_A6,
],
self::META_SERVICE_CODE => null,
];

/** @var ShipmentStatusInterface[] */
Expand Down Expand Up @@ -820,12 +834,48 @@ public function clearTags(): self
return $this;
}

/**
* Only for POST /shipments used by MyParcelComApi::createShipment()
*/
public function setAddToNextCollection(bool $addToNextCollection): self
{
$this->meta[self::META_ADD_TO_NEXT_COLLECTION] = $addToNextCollection;

return $this;
}

/**
* Only for POST /registered-shipments used by MyParcelComApi::createAndRegisterShipment()
*/
public function setCollectionMeta(
DateTime|int|string $from,
DateTime|int|string $to,
?string $description = null,
): self {
$this->meta[self::META_COLLECTION] = [
self::META_COLLECTION_DESCRIPTION => $description,
self::META_COLLECTION_TIME => [
self::META_COLLECTION_TIME_FROM => DateUtils::toTimestamp($from),
self::META_COLLECTION_TIME_TO => DateUtils::toTimestamp($to),
],
];

return $this;
}

/**
* Supported values are FileInterface::MIME_TYPE_PDF or FileInterface::MIME_TYPE_ZPL
*/
public function setLabelMimeType(string $labelMimeType): self
{
$this->meta[self::META_LABEL_MIME_TYPE] = $labelMimeType;
$this->meta[self::META_LABEL][self::META_LABEL_MIME_TYPE] = $labelMimeType;

return $this;
}

public function setLabelSize(string $labelSize): self
{
$this->meta[self::META_LABEL][self::META_LABEL_SIZE] = $labelSize;

return $this;
}
Expand Down
22 changes: 17 additions & 5 deletions tests/Feature/ResourceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,11 @@ public function testCreateEmptyShipment()
$this->assertEquals([
'type' => 'shipments',
'meta' => [
'label_mime_type' => 'application/pdf',
'add_to_next_collection' => false,
'label' => [
'mime_type' => 'application/pdf',
'size' => 'A6',
],
],
], $shipment->jsonSerialize());
}
Expand Down Expand Up @@ -528,7 +532,7 @@ public function testCreateShipment()
'phone_number' => '+31 (0)234 567 890',
],
],
'drop_off_location' => [
'drop_off_location' => [
'code' => 'ABC345',
'address' => [
'street_1' => 'Diagonally',
Expand Down Expand Up @@ -557,7 +561,11 @@ public function testCreateShipment()
'files' => ['data' => [['id' => 'file-id-1', 'type' => 'files']]],
],
'meta' => [
'label_mime_type' => 'application/pdf',
'add_to_next_collection' => false,
'label' => [
'mime_type' => 'application/pdf',
'size' => 'A6',
],
],
];

Expand Down Expand Up @@ -640,7 +648,7 @@ public function testCreateShipmentWithCustoms()
'phone_number' => '+31 (0)234 567 890',
],
],
'drop_off_location' => [
'drop_off_location' => [
'code' => 'ABC345',
'address' => [
'street_1' => 'Diagonally',
Expand Down Expand Up @@ -725,7 +733,11 @@ public function testCreateShipmentWithCustoms()
'files' => ['data' => [['id' => 'file-id-1', 'type' => 'files']]],
],
'meta' => [
'label_mime_type' => 'application/pdf',
'add_to_next_collection' => false,
'label' => [
'mime_type' => 'application/pdf',
'size' => 'A6',
],
],
];

Expand Down
39 changes: 34 additions & 5 deletions tests/Unit/Resources/ShipmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use MyParcelCom\ApiSdk\Enums\DimensionUnitEnum;
use MyParcelCom\ApiSdk\Enums\TaxTypeEnum;
use MyParcelCom\ApiSdk\Exceptions\MyParcelComException;
use MyParcelCom\ApiSdk\LabelCombinerInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\AddressInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\CollectionInterface;
use MyParcelCom\ApiSdk\Resources\Interfaces\ContractInterface;
Expand Down Expand Up @@ -534,15 +535,39 @@ public function testTags()
}

/** @test */
public function testLabelMimeType()
public function testCollectionMeta()
{
$shipment = new Shipment();

$this->assertEquals(FileInterface::MIME_TYPE_PDF, $shipment->jsonSerialize()['meta']['label_mime_type']);
$this->assertNotContains(Shipment::META_COLLECTION, $shipment->jsonSerialize()['meta']);

$shipment->setCollectionMeta(123, 456, 'desc');

$this->assertEquals(
[
'description' => 'desc',
'collection_time' => [
'from' => 123,
'to' => 456,
],
],
$shipment->jsonSerialize()['meta']['collection'],
);
}

/** @test */
public function testLabel()
{
$shipment = new Shipment();

$this->assertEquals(FileInterface::MIME_TYPE_PDF, $shipment->jsonSerialize()['meta']['label']['mime_type']);
$this->assertEquals(LabelCombinerInterface::PAGE_SIZE_A6, $shipment->jsonSerialize()['meta']['label']['size']);

$shipment->setLabelMimeType(FileInterface::MIME_TYPE_ZPL);
$shipment->setLabelSize(LabelCombinerInterface::PAGE_SIZE_A4);

$this->assertEquals(FileInterface::MIME_TYPE_ZPL, $shipment->jsonSerialize()['meta']['label_mime_type']);
$this->assertEquals(FileInterface::MIME_TYPE_ZPL, $shipment->jsonSerialize()['meta']['label']['mime_type']);
$this->assertEquals(LabelCombinerInterface::PAGE_SIZE_A4, $shipment->jsonSerialize()['meta']['label']['size']);
}

/** @test */
Expand Down Expand Up @@ -915,7 +940,7 @@ public function testJsonSerialize()
'phone_number' => '+31 (0)234 567 890',
],
],
'drop_off_location' => [
'drop_off_location' => [
'code' => 'ABC456',
'address' => [
'street_1' => 'Diagonally',
Expand Down Expand Up @@ -972,7 +997,11 @@ public function testJsonSerialize()
'collection' => ['data' => ['id' => 'collection-id-1', 'type' => 'collections']],
],
'meta' => [
'label_mime_type' => 'application/pdf',
'add_to_next_collection' => false,
'label' => [
'mime_type' => 'application/pdf',
'size' => 'A6',
],
],
], $shipment->jsonSerialize());
}
Expand Down