From 972c205cd5caf6f59cb3ba6bf14f9d4ad981283d Mon Sep 17 00:00:00 2001 From: Reindert Date: Thu, 26 Oct 2017 15:14:42 +0200 Subject: [PATCH 1/7] Set php doc --- src/Helper/MyParcelCollection.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Helper/MyParcelCollection.php b/src/Helper/MyParcelCollection.php index 2e704779..1164c5ac 100644 --- a/src/Helper/MyParcelCollection.php +++ b/src/Helper/MyParcelCollection.php @@ -392,6 +392,8 @@ public function setPdfOfLabels($positions = false) /** * Download labels * + * @param bool $inline_download + * * @return $this * @throws \Exception */ From cd1b97a4f58214fdf82da4f304832a5539d8f305 Mon Sep 17 00:00:00 2001 From: Reindert Date: Mon, 29 Jan 2018 10:03:37 +0100 Subject: [PATCH 2/7] Update license GPL --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 57a32dce..dcf34d6a 100755 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "This package is designed to send and receive data from MyParcel by means of an API.", "homepage": "https://www.myparcel.nl", "tags": ["MyParcel", "My Parcel", "Post NL", "PostNL"], - "license": "CC BY-NC-ND 3.0 NL", + "license": "GPL-3.0-or-later", "authors": [ { "name": "Reindert Vetter", From 14caf6cccfbed3c172e1e16311dbfe4d03ff1fcc Mon Sep 17 00:00:00 2001 From: Reindert Date: Thu, 1 Mar 2018 14:45:36 +0100 Subject: [PATCH 3/7] Set default package type --- .../MyParcelConsignmentRepository.php | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Model/Repository/MyParcelConsignmentRepository.php b/src/Model/Repository/MyParcelConsignmentRepository.php index 9255576b..07e7dbff 100755 --- a/src/Model/Repository/MyParcelConsignmentRepository.php +++ b/src/Model/Repository/MyParcelConsignmentRepository.php @@ -37,16 +37,18 @@ class MyParcelConsignmentRepository extends MyParcelConsignment /** * Consignment types */ - const TYPE_MORNING = 1; - const TYPE_STANDARD = 2; - const TYPE_NIGHT = 3; - const TYPE_RETAIL = 4; - const TYPE_RETAIL_EXPRESS = 5; + const DELIVERY_TYPE_MORNING = 1; + const DELIVERY_TYPE_STANDARD = 2; + const DELIVERY_TYPE_NIGHT = 3; + const DELIVERY_TYPE_RETAIL = 4; + const DELIVERY_TYPE_RETAIL_EXPRESS = 5; + + const PACKAGE_TYPE_NORMAL = 2; /** * @var array */ - private $consignmentEncoded = []; + private $consignmentEncoded = []; /** * Get entire street @@ -159,11 +161,11 @@ public function apiDecode($data) public function getDeliveryTypeFromCheckout($checkoutData) { if ($checkoutData === null) { - return self::TYPE_STANDARD; + return self::DELIVERY_TYPE_STANDARD; } $aCheckoutData = json_decode($checkoutData, true); - $deliveryType = self::TYPE_STANDARD; + $deliveryType = self::DELIVERY_TYPE_STANDARD; if (key_exists('time', $aCheckoutData) && key_exists('price_comment', $aCheckoutData['time'][0]) && @@ -171,22 +173,22 @@ public function getDeliveryTypeFromCheckout($checkoutData) ) { switch ($aCheckoutData['time'][0]['price_comment']) { case 'morning': - $deliveryType = self::TYPE_MORNING; + $deliveryType = self::DELIVERY_TYPE_MORNING; break; case 'standard': - $deliveryType = self::TYPE_STANDARD; + $deliveryType = self::DELIVERY_TYPE_STANDARD; break; case 'night': - $deliveryType = self::TYPE_NIGHT; + $deliveryType = self::DELIVERY_TYPE_NIGHT; break; } } elseif (key_exists('price_comment', $aCheckoutData) && $aCheckoutData['price_comment'] !== null) { switch ($aCheckoutData['price_comment']) { case 'retail': - $deliveryType = self::TYPE_RETAIL; + $deliveryType = self::DELIVERY_TYPE_RETAIL; break; case 'retailexpress': - $deliveryType = self::TYPE_RETAIL_EXPRESS; + $deliveryType = self::DELIVERY_TYPE_RETAIL_EXPRESS; break; } } @@ -617,12 +619,14 @@ private function decodeExtraOptions($data) $this->setInsurance($insuranceAmount / 100); } - if (key_exists('delivery_date', $options)) { + if (isset($options['delivery_date'])) { $this->setDeliveryDate($options['delivery_date']); } - if (key_exists('delivery_type', $options)) { + if (isset($options['delivery_type'])) { $this->setDeliveryType($options['delivery_type']); + } else { + $this->setDeliveryType(self::PACKAGE_TYPE_NORMAL); } return $this; From ebc492212beb6e9d48d0cf578162875a40860ff5 Mon Sep 17 00:00:00 2001 From: Reindert Date: Thu, 1 Mar 2018 14:47:12 +0100 Subject: [PATCH 4/7] Set default package type --- src/Model/Repository/MyParcelConsignmentRepository.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Model/Repository/MyParcelConsignmentRepository.php b/src/Model/Repository/MyParcelConsignmentRepository.php index 07e7dbff..f75d49ae 100755 --- a/src/Model/Repository/MyParcelConsignmentRepository.php +++ b/src/Model/Repository/MyParcelConsignmentRepository.php @@ -45,6 +45,8 @@ class MyParcelConsignmentRepository extends MyParcelConsignment const PACKAGE_TYPE_NORMAL = 2; + const DEFAULT_PACKAGE_TYPE = self::PACKAGE_TYPE_NORMAL; + /** * @var array */ @@ -626,7 +628,7 @@ private function decodeExtraOptions($data) if (isset($options['delivery_type'])) { $this->setDeliveryType($options['delivery_type']); } else { - $this->setDeliveryType(self::PACKAGE_TYPE_NORMAL); + $this->setDeliveryType(self::DEFAULT_PACKAGE_TYPE); } return $this; From b6f381a28108f2ff29143effbfcfbb4380e75e90 Mon Sep 17 00:00:00 2001 From: Reindert Date: Thu, 1 Mar 2018 16:41:59 +0100 Subject: [PATCH 5/7] Support long streetnames --- .../SendOneConsignmentTest.php | 20 ++++ Tests/SplitStreet/SplitLongStreetTest.php | 91 +++++++++++++++++++ src/Model/MyParcelConsignment.php | 34 ++++++- .../MyParcelConsignmentRepository.php | 12 ++- 4 files changed, 152 insertions(+), 5 deletions(-) create mode 100755 Tests/SplitStreet/SplitLongStreetTest.php diff --git a/Tests/SendConsignments/SendOneConsignmentTest.php b/Tests/SendConsignments/SendOneConsignmentTest.php index c63677e4..e5946b13 100755 --- a/Tests/SendConsignments/SendOneConsignmentTest.php +++ b/Tests/SendConsignments/SendOneConsignmentTest.php @@ -185,6 +185,26 @@ public function additionProvider() 'return' => false, 'label_description' => 'Label description', ], + [ + 'api_key' => getenv('API_KEY'), + 'cc' => 'NL', + 'person' => 'Piet', + 'company' => 'Mega Store', + 'full_street_test' => 'testtienpp testtienpp testtienpp testtienpp testtienpp 14 t', + 'full_street' => 'testtienpp testtienpp testtienpp testtienpp testtienpp 14 t', + 'street' => 'testtienpp testtienpp testtienpp testtienpp testtienpp', + 'number' => 14, + 'number_suffix' => 't', + 'postal_code' => '2231JE', + 'city' => 'Katwijk', + 'phone' => '123-45-235-435', + 'package_type' => 1, + 'large_format' => false, + 'only_recipient' => false, + 'signature' => false, + 'return' => false, + 'label_description' => 'Label description', + ], [ 'api_key' => getenv('API_KEY'), 'cc' => 'NL', diff --git a/Tests/SplitStreet/SplitLongStreetTest.php b/Tests/SplitStreet/SplitLongStreetTest.php new file mode 100755 index 00000000..5b494d6e --- /dev/null +++ b/Tests/SplitStreet/SplitLongStreetTest.php @@ -0,0 +1,91 @@ + + * @copyright 2010-2017 MyParcel + * @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US CC BY-NC-ND 3.0 NL + * @link https://github.com/myparcelnl/sdk + * @since File available since Release v0.1.0 + */ + +namespace MyParcelNL\Sdk\tests\CreateConsignments\SplitStreetTest; +use MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepository; + + +/** + * Class SplitStreetTest + * @package MyParcelNL\Sdk\tests\SplitStreetTest + */ +class SplitLongStreetTest extends \PHPUnit_Framework_TestCase +{ + + /** + * @covers \MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepository::setFullStreet + * @dataProvider additionProvider() + */ + public function testSplitStreet($country, $fullStreetTest, $street, $streetAdditionalInfo) + { + $consignment = (new MyParcelConsignmentRepository()) + ->setCountry($country) + ->setFullStreet($fullStreetTest); + + $this->assertEquals( + $street, + $consignment->getFullStreet(true), + 'Street: ' . $street + ); + + $this->assertEquals( + $streetAdditionalInfo, + $consignment->getStreetAdditionalInfo(), + 'Street additional info: ' . $streetAdditionalInfo + ); + } + + /** + * Data for the test + * + * @return array + */ + public function additionProvider() + { + return [ + [ + 'BE', + 'full_street_test' => 'testtienpp testtienpp testtienpp testtienpp testtienpp 14 t', + 'street' => 'testtienpp testtienpp testtienpp', + 'street_additional_info' => 'testtienpp testtienpp 14 t', + ], + [ + 'BE', + 'full_street_test' => 'testtienpp testtienpp', + 'street' => 'testtienpp testtienpp', + 'street_additional_info' => '', + ], + [ + 'BE', + 'full_street_test' => 'Wethouder Fierman Eduard Meerburg senior kade 14 t', + 'street' => 'Wethouder Fierman Eduard Meerburg senior 14 t', + 'street_additional_info' => 'kade', + ], + [ + 'NL', + 'full_street_test' => 'Ir. Mr. Dr. van Waterschoot van der Grachtstraat 14 t', + 'street' => 'Ir. Mr. Dr. van Waterschoot van der 14 t', + 'street_additional_info' => 'Grachtstraat', + ], + [ + 'NL', + 'full_street_test' => 'Koestraat 554 t', + 'street' => 'Koestraat 554 t', + 'street_additional_info' => '', + ], + ]; + } +} \ No newline at end of file diff --git a/src/Model/MyParcelConsignment.php b/src/Model/MyParcelConsignment.php index 191b69fe..d2170844 100755 --- a/src/Model/MyParcelConsignment.php +++ b/src/Model/MyParcelConsignment.php @@ -31,6 +31,7 @@ class MyParcelConsignment extends MyParcelClassConstants const DATE_TIME_REGEX = '~(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})$~'; const INSURANCE_POSSIBILITIES = [0, 50, 250, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000]; const STATUS_CONCEPT = 1; + const MAX_STREET_LENTH = 40; /** * @var string @@ -423,13 +424,34 @@ public function setCity($city) } /** + * @var bool * @return string */ - public function getStreet() + public function getStreet($useStreetAdditionalInfo = false) { + if ($useStreetAdditionalInfo && strlen($this->street) >= self::MAX_STREET_LENTH) { + $streetParts = $this->getStreetParts(); + + return $streetParts[0]; + } + return $this->street; } + /** + * Get additional information for the street that should not be included in the street field + */ + public function getStreetAdditionalInfo() + { + $streetParts = $this->getStreetParts(); + + if (isset($streetParts[1])) { + return $streetParts[1]; + } + + return ''; + } + /** * The address street name * @@ -1121,4 +1143,14 @@ private function canHaveOption($option = true) return $this->getPackageType() == 1 ? $option : false; } + + /** + * Wraps a street to max street lenth + * + * @return array + */ + private function getStreetParts () + { + return explode("\n", wordwrap($this->street, self::MAX_STREET_LENTH)); + } } diff --git a/src/Model/Repository/MyParcelConsignmentRepository.php b/src/Model/Repository/MyParcelConsignmentRepository.php index f75d49ae..8f7ccf53 100755 --- a/src/Model/Repository/MyParcelConsignmentRepository.php +++ b/src/Model/Repository/MyParcelConsignmentRepository.php @@ -55,11 +55,13 @@ class MyParcelConsignmentRepository extends MyParcelConsignment /** * Get entire street * + * @var bool + * * @return string Entire street */ - public function getFullStreet() + public function getFullStreet($useStreetAdditionalInfo = false) { - $fullStreet = $this->getStreet(); + $fullStreet = $this->getStreet($useStreetAdditionalInfo); if ($this->getNumber()) { $fullStreet .= ' ' . $this->getNumber(); @@ -406,14 +408,16 @@ private function encodeStreet() $this->consignmentEncoded, [ 'recipient' => [ - 'street' => $this->getStreet(), + 'street' => $this->getStreet(true), + 'street_additional_info' => $this->getStreetAdditionalInfo(), 'number' => $this->getNumber(), 'number_suffix' => $this->getNumberSuffix(), ], ] ); } else { - $this->consignmentEncoded['recipient']['street'] = $this->getFullStreet(); + $this->consignmentEncoded['recipient']['street'] = $this->getFullStreet(true); + $this->consignmentEncoded['recipient']['street_additional_info'] = $this->getStreetAdditionalInfo(); } return $this; From 91de816ca01d8cd05f7e94310059b6465b6ed1bd Mon Sep 17 00:00:00 2001 From: Reindert Date: Thu, 1 Mar 2018 16:45:17 +0100 Subject: [PATCH 6/7] Support long streetnames --- Tests/SplitStreet/SplitLongStreetTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/SplitStreet/SplitLongStreetTest.php b/Tests/SplitStreet/SplitLongStreetTest.php index 5b494d6e..877cf5e8 100755 --- a/Tests/SplitStreet/SplitLongStreetTest.php +++ b/Tests/SplitStreet/SplitLongStreetTest.php @@ -71,8 +71,8 @@ public function additionProvider() [ 'BE', 'full_street_test' => 'Wethouder Fierman Eduard Meerburg senior kade 14 t', - 'street' => 'Wethouder Fierman Eduard Meerburg senior 14 t', - 'street_additional_info' => 'kade', + 'street' => 'Wethouder Fierman Eduard Meerburg senior', + 'street_additional_info' => 'kade 14 t', ], [ 'NL', From 2962df5739c31164804b5025c4625deb29024008 Mon Sep 17 00:00:00 2001 From: Richard Perdaan Date: Fri, 2 Mar 2018 13:18:52 +0100 Subject: [PATCH 7/7] update version to v1.3.7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index eea3a26c..dfa30f32 100755 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "myparcelnl/sdk", - "version": "v1.3.6", + "version": "v1.3.7", "description": "This package is designed to send and receive data from MyParcel by means of an API.", "homepage": "https://www.myparcel.nl", "tags": ["MyParcel", "My Parcel", "Post NL", "PostNL"],