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

🔀 #223

Merged
merged 9 commits into from
Nov 6, 2024
27 changes: 21 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Composer
uses: php-actions/composer@v6
with:
php_version: 8.0
- name: PHPUnit
uses: php-actions/phpunit@v3
uses: php-actions/phpunit@v4
with:
version: 9
php_version: 8.0
Expand All @@ -20,13 +20,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Composer
uses: php-actions/composer@v6
with:
php_version: 8.1
- name: PHPUnit
uses: php-actions/phpunit@v3
uses: php-actions/phpunit@v4
with:
version: 9
php_version: 8.1
Expand All @@ -35,14 +35,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Composer
uses: php-actions/composer@v6
with:
php_version: 8.2
- name: PHPUnit
uses: php-actions/phpunit@v3
uses: php-actions/phpunit@v4
with:
version: 9
php_version: 8.2
configuration: phpunit.xml
php83:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Composer
uses: php-actions/composer@v6
with:
php_version: 8.3
- name: PHPUnit
uses: php-actions/phpunit@v4
with:
version: 9
php_version: 8.3
configuration: phpunit.xml
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
version: '3'

services:
php8:
build:
context: ./docker/php8
dockerfile: Dockerfile
image: myparcelcom/sdk-php8:v1-dev
image: myparcelcom/sdk-php8:v2-dev
working_dir: /opt/sdk
volumes:
- .:/opt/sdk
Expand Down
2 changes: 1 addition & 1 deletion docker/php8/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.2.7-cli
FROM php:8.3.13-cli

RUN apt-get update \
&& apt-get install -y curl zip unzip software-properties-common gettext-base iproute2 \
Expand Down
15 changes: 15 additions & 0 deletions src/Resources/Interfaces/ServiceOptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public function setCategory(?string $category): self;

public function getCategory(): ?string;

public function setValuesFormat(?array $valuesFormat): self;

/**
* Defines if this ServiceOption requires a `values` array to be set when using it to create a shipment.
*/
public function getValuesFormat(): ?array;

public function setPrice(?int $price): self;

public function getPrice(): ?int;
Expand All @@ -29,4 +36,12 @@ public function getCurrency(): ?string;
public function setIncluded(bool $included): self;

public function isIncluded(): bool;

/**
* When adding a ServiceOption to a Shipment, it might require values such as an `amount` and a `currency`.
* This is defined in the `values_format` of the ServiceOption, which returns these requirements as JSON Schema.
*/
public function setValues(?array $values): self;

public function getValues(): ?array;
}
28 changes: 28 additions & 0 deletions src/Resources/Proxy/ServiceOptionProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ class ServiceOptionProxy implements ServiceOptionInterface, ResourceProxyInterfa
const META_PRICE_AMOUNT = 'amount';
const META_PRICE_CURRENCY = 'currency';
const META_INCLUDED = 'included';
const META_VALUES = 'values';

private ?string $id = null;

private string $type = ResourceInterface::TYPE_SERVICE_OPTION;

private array $meta = [
// Relationships returned from the service-rates endpoints can have a price and indication if they are included.
self::META_PRICE => [
self::META_PRICE_AMOUNT => null,
self::META_PRICE_CURRENCY => null,
],
self::META_INCLUDED => null,
// Relationships returned from the shipment endpoints can have values (according to the defined values_format).
self::META_VALUES => null,
];

public function setName(string $name): self
Expand Down Expand Up @@ -74,6 +78,18 @@ public function getCategory(): ?string
return $this->getResource()->getCategory();
}

public function setValuesFormat(?array $valuesFormat): self
{
$this->getResource()->setValuesFormat($valuesFormat);

return $this;
}

public function getValuesFormat(): ?array
{
return $this->getResource()->getValuesFormat();
}

public function setPrice(?int $price): self
{
$this->meta[self::META_PRICE][self::META_PRICE_AMOUNT] = $price;
Expand Down Expand Up @@ -110,6 +126,18 @@ public function isIncluded(): bool
return (bool) $this->meta[self::META_INCLUDED];
}

public function setValues(?array $values): self
{
$this->meta[self::META_VALUES] = $values;

return $this;
}

public function getValues(): ?array
{
return $this->meta[self::META_VALUES];
}

/**
* This function puts all object properties in an array and returns it.
*/
Expand Down
30 changes: 22 additions & 8 deletions src/Resources/Proxy/ShipmentProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,16 @@ public function getServiceCode(): ?string

public function setTags(?array $tags): self
{
return $this->getResource()->setTags($tags);
$this->getResource()->setTags($tags);

return $this;
}

public function addTag($tag): self
{
return $this->getResource()->addTag($tag);
$this->getResource()->addTag($tag);

return $this;
}

public function getTags(): ?array
Expand All @@ -534,17 +538,23 @@ public function getTags(): ?array

public function clearTags(): self
{
return $this->getResource()->clearTags();
$this->getResource()->clearTags();

return $this;
}

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

return $this;
}

public function setCollection(?CollectionInterface $collection): self
{
return $this->getResource()->setCollection($collection);
$this->getResource()->setCollection($collection);

return $this;
}

public function getCollection(): ?CollectionInterface
Expand All @@ -554,12 +564,16 @@ public function getCollection(): ?CollectionInterface

public function setShipmentSurcharges(array $surcharges): self
{
return $this->getResource()->setShipmentSurcharges($surcharges);
$this->getResource()->setShipmentSurcharges($surcharges);

return $this;
}

public function addShipmentSurcharge(ShipmentSurchargeInterface $surcharge): self
{
return $this->getResource()->addShipmentSurcharge($surcharge);
$this->getResource()->addShipmentSurcharge($surcharge);

return $this;
}

public function getShipmentSurcharges(): array
Expand Down
20 changes: 15 additions & 5 deletions src/Resources/Proxy/ShipmentSurchargeProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class ShipmentSurchargeProxy implements ShipmentSurchargeInterface, ResourceProx

public function setName(string $name): self
{
return $this->getResource()->setName($name);
$this->getResource()->setName($name);

return $this;
}

public function getName(): ?string
Expand All @@ -37,7 +39,9 @@ public function getName(): ?string

public function setDescription(?string $description): self
{
return $this->getResource()->setDescription($description);
$this->getResource()->setDescription($description);

return $this;
}

public function getDescription(): ?string
Expand All @@ -47,7 +51,9 @@ public function getDescription(): ?string

public function setFeeAmount(int $amount): self
{
return $this->getResource()->setFeeAmount($amount);
$this->getResource()->setFeeAmount($amount);

return $this;
}

public function getFeeAmount(): ?int
Expand All @@ -57,7 +63,9 @@ public function getFeeAmount(): ?int

public function setFeeCurrency(string $currency): self
{
return $this->getResource()->setFeeCurrency($currency);
$this->getResource()->setFeeCurrency($currency);

return $this;
}

public function getFeeCurrency(): ?string
Expand All @@ -72,7 +80,9 @@ public function getShipment(): ?ShipmentInterface

public function setShipment(?ShipmentInterface $shipment): self
{
return $this->getResource()->setShipment($shipment);
$this->getResource()->setShipment($shipment);

return $this;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/Proxy/ShopProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ public function getCreatedAt(): DateTime

public function setOrganization(OrganizationInterface $organization): self
{
return $this->getResource()->setOrganization($organization);
$this->getResource()->setOrganization($organization);

return $this;
}

public function getOrganization(): OrganizationInterface
Expand Down
18 changes: 18 additions & 0 deletions src/Resources/ResourceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ protected function shipmentFactory(array &$data): Shipment
unset($data['attributes']['recipient_tax_identification_numbers']);
}

if (isset($data['relationships']['service_options'])) {
$serviceOptions = $data['relationships']['service_options']['data'];

foreach ($serviceOptions as $serviceOption) {
$serviceOptionProxy = (new ServiceOptionProxy())
->setMyParcelComApi($this->api)
->setId($serviceOption['id']);

if (isset($serviceOption['meta']['values'])) {
$serviceOptionProxy->setValues($serviceOption['meta']['values']);
}

$shipment->addServiceOption($serviceOptionProxy);
}

unset($data['relationships']['service_options']);
}

return $shipment;
}

Expand Down
Loading