Skip to content

Commit

Permalink
Add CompleteStatusResponseShipment::$Amount alias
Browse files Browse the repository at this point in the history
  • Loading branch information
firstred committed Apr 10, 2023
1 parent 45c2c21 commit 1af52b6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Entity/Response/CompleteStatusResponseShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,15 @@ public static function jsonDeserialize(stdClass $json)
}
}

if (isset($json->CompleteStatusResponseShipment->Amount)) {
$json->CompleteStatusResponseShipment->Amounts = $json->CompleteStatusResponseShipment->Amount;
unset($json->CompleteStatusResponseShipment->Amount);

if (!is_array($json->CompleteStatusResponseShipment->Amounts)) {
$json->CompleteStatusResponseShipment->Amounts = [$json->CompleteStatusResponseShipment->Amounts];
}
}

return parent::jsonDeserialize($json);
}

Expand Down
12 changes: 11 additions & 1 deletion src/Entity/Response/CurrentStatusResponseShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Firstred\PostNL\Entity\StatusAddress;
use Firstred\PostNL\Entity\Warning;
use Firstred\PostNL\Exception\InvalidArgumentException;
use Firstred\PostNL\Exception\NotSupportedException;
use Firstred\PostNL\Service\BarcodeService;
use Firstred\PostNL\Service\ConfirmingService;
use Firstred\PostNL\Service\DeliveryDateService;
Expand Down Expand Up @@ -325,7 +326,7 @@ public function setDeliveryDate($deliveryDate = null)
* @return mixed|stdClass|null
*
* @throws InvalidArgumentException
* @throws \Firstred\PostNL\Exception\NotSupportedException
* @throws NotSupportedException
*
* @since 1.2.0
*/
Expand All @@ -340,6 +341,15 @@ public static function jsonDeserialize(stdClass $json)
}
}

if (isset($json->CurrentStatusResponseShipment->Amount)) {
$json->CurrentStatusResponseShipment->Amounts = $json->CurrentStatusResponseShipment->Amount;
unset($json->CurrentStatusResponseShipment->Amount);

if (!is_array($json->CurrentStatusResponseShipment->Amounts)) {
$json->CurrentStatusResponseShipment->Amounts = [$json->CurrentStatusResponseShipment->Amounts];
}
}

return parent::jsonDeserialize($json);
}

Expand Down
6 changes: 5 additions & 1 deletion tests/Service/ShippingStatusServiceRestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use DateTimeImmutable;
use DateTimeInterface;
use Firstred\PostNL\Entity\Address;
use Firstred\PostNL\Entity\Amount;
use Firstred\PostNL\Entity\Customer;
use Firstred\PostNL\Entity\Dimension;
use Firstred\PostNL\Entity\Message\Message;
Expand Down Expand Up @@ -255,7 +256,10 @@ public function testGetCompleteStatusByBarcodeRest($response)

$this->assertInstanceOf(CompleteStatusResponse::class, $completeStatusResponse);
$this->assertInstanceOf(StatusAddress::class, $completeStatusResponse->getShipments()[0]->getAddresses()[0]);
$this->assertNull($completeStatusResponse->getShipments()[0]->getAmounts());
$this->assertTrue(
null === $completeStatusResponse->getShipments()[0]->getAmounts()
|| $completeStatusResponse->getShipments()[0]->getAmounts()[0] instanceof Amount
);
if (is_array($completeStatusResponse->getShipments()[0]->getProductOptions())) {
$this->assertInstanceOf(ProductOption::class, $completeStatusResponse->getShipments()[0]->getProductOptions()[0]);
} else {
Expand Down

0 comments on commit 1af52b6

Please sign in to comment.