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..877cf5e8 --- /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', + 'street_additional_info' => 'kade 14 t', + ], + [ + '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/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"], diff --git a/src/Helper/MyParcelCollection.php b/src/Helper/MyParcelCollection.php index e20a419f..3d6f9226 100644 --- a/src/Helper/MyParcelCollection.php +++ b/src/Helper/MyParcelCollection.php @@ -388,6 +388,8 @@ public function setPdfOfLabels($positions = false) /** * Download labels * + * @param bool $inline_download + * * @return $this * @throws \Exception */ 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 5f8f7ce9..5e56bce6 100755 --- a/src/Model/Repository/MyParcelConsignmentRepository.php +++ b/src/Model/Repository/MyParcelConsignmentRepository.php @@ -34,19 +34,34 @@ class MyParcelConsignmentRepository extends MyParcelConsignment */ const SPLIT_STREET_REGEX = '~(?P.*?)\s?(?P(?P[\d]+)[\s-]{0,2}(?P[a-zA-Z/\s]{0,5}$|[0-9/]{0,5}$|\s[a-zA-Z]{1}[0-9]{0,3}$|\s[0-9]{2}[a-zA-Z]{0,3}$))$~'; + /** + * Consignment types + */ + 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; + + const DEFAULT_PACKAGE_TYPE = self::PACKAGE_TYPE_NORMAL; + /** * @var array */ - private $consignmentEncoded = []; + private $consignmentEncoded = []; /** * 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(); @@ -150,11 +165,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]) && @@ -162,22 +177,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; } } @@ -392,14 +407,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; @@ -607,15 +624,15 @@ private function decodeExtraOptions($data) $this->setInsurance($insuranceAmount / 100); } - if (isset($options['delivery_date'])) { - $this->setDeliveryDate($options['delivery_date']); - } + if (isset($options['delivery_date'])) { + $this->setDeliveryDate($options['delivery_date']); + } - if (isset($options['delivery_type'])) { - $this->setDeliveryType($options['delivery_type']); - } else { - $this->setDeliveryType(self::TYPE_STANDARD); - } + if (isset($options['delivery_type'])) { + $this->setDeliveryType($options['delivery_type']); + } else { + $this->setDeliveryType(self::DEFAULT_PACKAGE_TYPE); + } return $this; }