diff --git a/src/Model/ParcelItem.php b/src/Model/ParcelItem.php index e89e243..debd610 100644 --- a/src/Model/ParcelItem.php +++ b/src/Model/ParcelItem.php @@ -12,7 +12,7 @@ public static function fromData(array $data): self return new self( (string)$data['description'], (int)$data['quantity'], - round(((float)$data['weight']) * 1000), + (int)round(((float)$data['weight']) * 1000), (float)$data['value'], isset($data['hs_code']) ? (string)$data['hs_code'] : null, isset($data['origin_country']) ? (string)$data['origin_country'] : null, diff --git a/src/Model/ShippingMethod.php b/src/Model/ShippingMethod.php index 8bb3ba7..fd2d39b 100644 --- a/src/Model/ShippingMethod.php +++ b/src/Model/ShippingMethod.php @@ -14,8 +14,8 @@ public static function fromData(array $data): self return new self( (int)$data['id'], (string)$data['name'], - (int)($data['min_weight'] * 1000), - (int)($data['max_weight'] * 1000), + (int)round($data['min_weight'] * 1000.0), + (int)round($data['max_weight'] * 1000.0), (string)$data['carrier'], $prices, $data['service_point_input'] !== 'none', diff --git a/test/ClientTest.php b/test/ClientTest.php index e24a1eb..23954aa 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -69,7 +69,7 @@ public function testGetShippingMethods(): void return new Response( 200, [], - '{"shipping_methods": [{"service_point_input": "none","max_weight": "1.000","name": "Low weight shipment","carrier": "carrier_code","countries": [{"iso_2": "BE","iso_3": "BEL","id": 1,"price": 3.50,"name": "Belgium"},{"iso_2": "NL","iso_3": "NLD","id": 2,"price": 4.20,"name": "Netherlands"}],"min_weight": "0.001","id": 1,"price": 0}]}' + '{"shipping_methods": [{"service_point_input": "none","min_weight": "0.001","max_weight": "1.001","name": "Low weight shipment","carrier": "carrier_code","countries": [{"iso_2": "BE","iso_3": "BEL","id": 1,"price": 3.50,"name": "Belgium"},{"iso_2": "NL","iso_3": "NLD","id": 2,"price": 4.20,"name": "Netherlands"}],"min_weight": "0.001","id": 1,"price": 0}]}' ); }); @@ -78,7 +78,7 @@ public function testGetShippingMethods(): void $this->assertCount(1, $shippingMethods); $this->assertEquals(1, $shippingMethods[0]->getId()); $this->assertEquals(1, $shippingMethods[0]->getMinimumWeight()); - $this->assertEquals(1000, $shippingMethods[0]->getMaximumWeight()); + $this->assertEquals(1001, $shippingMethods[0]->getMaximumWeight()); $this->assertEquals('carrier_code', $shippingMethods[0]->getCarrier()); $this->assertEquals(['BE' => 350, 'NL' => 420], $shippingMethods[0]->getPrices()); $this->assertEquals(420, $shippingMethods[0]->getPriceForCountry('NL'));