diff --git a/README.md b/README.md new file mode 100755 index 00000000..580e5329 --- /dev/null +++ b/README.md @@ -0,0 +1,99 @@ +[![Latest Stable Version](https://poser.pugx.org/myparcelnl/sdk/v/stable)](https://packagist.org/packages/myparcelnl/sdk) +[![Latest Unstable Version](https://poser.pugx.org/myparcelnl/sdk/v/unstable)](https://packagist.org/packages/myparcelnl/sdk) +[![Build Status](https://travis-ci.org/myparcel/sdk.svg?branch=master)](https://travis-ci.org/myparcelnl/sdk) +# MyParcel SDK + +--- + +- [Installation](#installation) +- [Installation without composer](#installation-without-composer) +- [Requirements](#requirements) +- [Quick start and examples](#quick-start-and-examples) +- [Available Methods](#available-methods) +- [Contribute](#contribute) + +--- + +### Installation + +This SDK uses composer. + +Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you. + +For more information on how to use/install composer, please visit: [https://github.com/composer/composer](https://github.com/composer/composer) + +To install the MyParcel SDK into your project, simply + + $ composer require myparcelnl/sdk + +### Installation without composer + +If you don't have experience with composer, it is possible to use the SDK without using composer. + +You can download the zip on the projects [releases](https://github.com/myparcelnl/sdk/releases) page. + +1. Download the package zip (SDKvx.x.x.zip). +2. Unzip the contents of the zip, and upload the vendor directory to your server. +3. In your project, require the file vendor/autoload.php +4. You can now use the SDK in your project + +### Requirements + +The MyParcel SDK works on php versions 5.3, 5.4, 5.5, 5.6 and 7.0 +Also the php curl extension needs to be installed. + +### Quick start and examples + +```php +use DivideBV\Postnl\Postnl; +use DivideBV\Postnl\ComplexTypes; + +// Create client class using credentials received from PostNL. +$client = new Postnl( + 12345678, // Customer number + 'ABCD', // Customer code + 'Acme BV', // Customer name + 'Acme', // Username + 'Password', // Password + 123456, // Collection location + 'CD1234', // Globalpack + true // Whether to use PostNL's sandbox environment. +); + +/** + * Jan Smit + * Smit & Zonen + * Hoofdstraat 1A + * 1234 AB Heikant + * The Netherlands + */ +$receiverAddress = ComplexTypes\Address::create() + ->setAddressType('01') + ->setFirstName('Jan') + ->setName('Smit') + ->setCompanyName('Smit & Zonen') + ->setStreet('Hoofdstraat') + ->setHouseNr('1') + ->setHouseNrExt('A') + ->setZipcode('1234AB') + ->setCity('Heikant') + ->setCountrycode('NL'); + + +``` + +### Testing +Please run ```vendor/bin/phpunit --bootstrap vendor/autoload.php tests/``` to test the application + + +### Available Methods +```php +ConsignmentRepository::setName($name = null) +``` + +### Contribute +1. Check for open issues or open a new issue to start a discussion around a bug or feature. +1. Fork the repository on GitHub to start making your changes. +1. Write one or more tests for the new feature or that expose the bug. +1. Make code changes to implement the feature or fix the bug. +1. Send a pull request to get your changes merged and published. \ No newline at end of file diff --git a/Tests/CreateConsignments/InternationalFullStreetTest.php b/Tests/CreateConsignments/InternationalFullStreetTest.php new file mode 100755 index 00000000..dc455c54 --- /dev/null +++ b/Tests/CreateConsignments/InternationalFullStreetTest.php @@ -0,0 +1,59 @@ + + * @copyright 2010-2016 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 0.1.0 + */ + namespace MyParcel\sdk\tests\CreateConsignments\InternationalFullStreetTest; + use MyParcel\sdk\Model\Repository\MyParcelConsignmentRepository; + + + /** + * Class InternationalFullStreetTest + * @package MyParcel\sdk\tests\InternationalFullStreetTest + */ + class InternationalFullStreetTest extends \PHPUnit_Framework_TestCase + { + + /** + * Test setFullStreet() + */ + public function testSplitStreet() + { + foreach ($this->additionProvider() as $consignmentTest) { + + $consignment = new MyParcelConsignmentRepository(); + $consignment->setCc($consignmentTest['cc']); + $consignment->setFullStreet($consignmentTest['full_street']); + + $this->assertEquals($consignmentTest['full_street'], $consignment->getFullStreet(), 'Full street: ' . $consignmentTest['full_street']); + } + } + + /** + * Data for the test + * + * @return array + */ + public function additionProvider() + { + return [ + [ + 'cc' => 'FR', + 'full_street' => 'No. 7 street', + ], + ]; + } + } \ No newline at end of file diff --git a/Tests/CreateConsignments/InternationalStreetTest.php b/Tests/CreateConsignments/InternationalStreetTest.php new file mode 100755 index 00000000..0796f130 --- /dev/null +++ b/Tests/CreateConsignments/InternationalStreetTest.php @@ -0,0 +1,63 @@ + + * @copyright 2010-2016 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 0.1.0 + * @todo Allow street number for international shipment + */ + namespace MyParcel\sdk\tests\CreateConsignments\InternationalStreetTest; + + + /** + * Class InternationalStreetTest + * @package MyParcel\sdk\tests\InternationalStreetTest + */ + class InternationalStreetTest extends \PHPUnit_Framework_TestCase + { + + /** + * Test setFullStreet() + */ + public function testSplitStreet() + { + /*foreach ($this->additionProvider() as $consignmentTest) { + + $consignment = new MyParcelConsignmentRepository(); + $consignment->setCc($consignmentTest['cc']); + $consignment->setStreet($consignmentTest['street']); + $consignment->setNumber($consignmentTest['number']); + + $this->assertEquals($consignmentTest['number'], $consignment->getNumber(), 'Number from: ' . $consignmentTest['full_street_test']); + $this->assertEquals($consignmentTest['street'], $consignment->getStreet(), 'Street: ' . $consignmentTest['full_street_test']); + $this->assertEquals($consignmentTest['full_street'], $consignment->getFullStreet(), 'Full street: ' . $consignmentTest['full_street_test']); + }*/ + } + + /** + * Data for the test + * + * @return array + */ + public function additionProvider() + { + return [ + [ + 'cc' => 'FR', + 'street' => 'Street', + 'number' => 12 + ], + ]; + } + } \ No newline at end of file diff --git a/Tests/CreateConsignments/SplitStreetTest.php b/Tests/CreateConsignments/SplitStreetTest.php new file mode 100755 index 00000000..e051e0ba --- /dev/null +++ b/Tests/CreateConsignments/SplitStreetTest.php @@ -0,0 +1,177 @@ + + * @copyright 2010-2016 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 0.1.0 + */ +namespace MyParcel\sdk\tests\CreateConsignments\SplitStreetTest; +use MyParcel\sdk\Model\Repository\MyParcelConsignmentRepository; + + +/** + * Class SplitStreetTest + * @package MyParcel\sdk\tests\SplitStreetTest + */ +class SplitStreetTest extends \PHPUnit_Framework_TestCase +{ + + /** + * Test setFullStreet() + */ + public function testSplitStreet() + { + foreach ($this->additionProvider() as $consignmentTest) { + + $consignment = new MyParcelConsignmentRepository(); + $consignment->setCc('NL'); + $consignment->setFullStreet($consignmentTest['full_street_test']); + + $this->assertEquals($consignmentTest['number_suffix'], $consignment->getNumberSuffix(), 'Number suffix from: ' . $consignmentTest['full_street_test']); + $this->assertEquals($consignmentTest['number'], $consignment->getNumber(), 'Number from: ' . $consignmentTest['full_street_test']); + $this->assertEquals($consignmentTest['street'], $consignment->getStreet(), 'Street: ' . $consignmentTest['full_street_test']); + $this->assertEquals($consignmentTest['full_street'], $consignment->getFullStreet(), 'Full street: ' . $consignmentTest['full_street_test']); + } + } + + /** + * Data for the test + * + * @return array + */ + public function additionProvider() + { + return [ + [ + 'full_street_test' => 'Plein 1940-45 3b', + 'full_street' => 'Plein 1940-45 3 b', + 'street' => 'Plein 1940-45', + 'number' => 3, + 'number_suffix' => 'b', + ], + [ + 'full_street_test' => '300 laan 3', + 'full_street' => '300 laan 3', + 'street' => '300 laan', + 'number' => 3, + 'number_suffix' => '', + ], + [ + 'full_street_test' => 'A.B.C. straat 12', + 'full_street' => 'A.B.C. straat 12', + 'street' => 'A.B.C. straat', + 'number' => 12, + 'number_suffix' => '', + ], + [ + 'full_street_test' => 'straat straat 269-133', + 'full_street' => 'straat straat 269 133', + 'street' => 'straat straat', + 'number' => 269, + 'number_suffix' => '133', + ], + [ + 'full_street_test' => 'Abeelstraat H10', + 'full_street' => 'Abeelstraat H 10', + 'street' => 'Abeelstraat H', + 'number' => 10, + 'number_suffix' => '', + ], + [ + 'full_street_test' => 'straat straat 269-1001', + 'full_street' => 'straat straat 269 1001', + 'street' => 'straat straat', + 'number' => 269, + 'number_suffix' => '1001', + ], + [ + 'full_street_test' => 'Meijhorst 50e 26', + 'full_street' => 'Meijhorst 50e 26', + 'street' => 'Meijhorst 50e', + 'number' => 26, + 'number_suffix' => '', + ], + [ + 'full_street_test' => 'straat straat 12 ZW', + 'full_street' => 'straat straat 12 ZW', + 'street' => 'straat straat', + 'number' => 12, + 'number_suffix' => 'ZW', + ], + [ + 'full_street_test' => 'straat 12', + 'full_street' => 'straat 12', + 'street' => 'straat', + 'number' => 12, + 'number_suffix' => '', + ], + [ + 'full_street_test' => 'Biltstraat 113 A BS', + 'full_street' => 'Biltstraat 113 A BS', + 'street' => 'Biltstraat', + 'number' => 113, + 'number_suffix' => 'A BS', + ], + [ + 'full_street_test' => 'Zonegge 23 12', + 'full_street' => 'Zonegge 23 12', + 'street' => 'Zonegge 23', + 'number' => 12, + 'number_suffix' => '', + ], + [ + 'full_street_test' => 'Markerkant 10 142', + 'full_street' => 'Markerkant 10 142', + 'street' => 'Markerkant 10', + 'number' => 142, + 'number_suffix' => '', + ], + [ + 'full_street_test' => 'Markerkant 10 11e', + 'full_street' => 'Markerkant 10 11 e', + 'street' => 'Markerkant 10', + 'number' => 11, + 'number_suffix' => 'e', + ], + [ + 'full_street_test' => 'Sir Winston Churchillln 283 F008', + 'full_street' => 'Sir Winston Churchillln 283 F008', + 'street' => 'Sir Winston Churchillln', + 'number' => 283, + 'number_suffix' => 'F008', + ], + [ + 'full_street_test' => 'Sir Winston Churchilllaan 283 59', + 'full_street' => 'Sir Winston Churchilllaan 283 59', + 'street' => 'Sir Winston Churchilllaan 283', + 'number' => 59, + 'number_suffix' => '', + ], + [ + 'full_street_test' => 'Insulindestraat 69 B03', + 'full_street' => 'Insulindestraat 69 B03', + 'street' => 'Insulindestraat', + 'number' => 69, + 'number_suffix' => 'B03', + ], + [ + 'full_street_test' => 'Scheepvaartlaan 34/302', + 'full_street' => 'Scheepvaartlaan 34 /302', + 'street' => 'Scheepvaartlaan', + 'number' => 34, + 'number_suffix' => '/302', + ], + ]; + } +} \ No newline at end of file diff --git a/Tests/SendConsignments/SendOneShipmentTest.php b/Tests/SendConsignments/SendOneShipmentTest.php new file mode 100755 index 00000000..cdaa3729 --- /dev/null +++ b/Tests/SendConsignments/SendOneShipmentTest.php @@ -0,0 +1,71 @@ + + * @copyright 2010-2016 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 0.1.0 + */ +namespace MyParcel\sdk\tests\SendConsignments\ +SendOneConsignmentTest; + +use MyParcel\sdk\Helper\MyParcelAPI; +use MyParcel\sdk\Model\Repository\MyParcelConsignmentRepository; + + +/** + * Class SendOneConsignmentTest + * @package MyParcel\sdk\tests\SendOneConsignmentTest + */ +class SendOneConsignmentTest extends \PHPUnit_Framework_TestCase +{ + + /** + * Test one send() + */ + public function testSendOneConsignment() + { + $myParcelAPI = new MyParcelAPI(); + + foreach ($this->additionProvider() as $consignmentTest) { + + + $consignment = new MyParcelConsignmentRepository(); + $consignment->setApiKey('NL'); + $consignment->setCc('NL'); + $consignment->setFullStreet($consignmentTest['full_street_test']); + + $myParcelAPI->addConsignment($consignment); + } + $myParcelAPI->registerConcept(); + } + + /** + * Data for the test + * + * @return array + */ + public function additionProvider() + { + return [ + [ + 'cc' => 'NL', + 'full_street_test' => 'Plein 1940-45 3b', + 'full_street' => 'Plein 1940-45 3 b', + 'street' => 'Plein 1940-45', + 'number' => 3, + 'number_suffix' => 'b', + ] + ]; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100755 index 00000000..4d4173de --- /dev/null +++ b/composer.json @@ -0,0 +1,29 @@ +{ + "name": "myparcelnl/sdk", + "version": "0.1.0", + "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", + "authors": [ + { + "name": "Reindert Vetter", + "email": "reindert@myparcel.nl" + } + ], + "repository": { + "type": "git", + "url": "https://github.com/myparcelnl/sdk" + }, + "bugs": { + "url": "https://github.com/myparcelnl/sdk/issues" + }, + "require-dev": { + "phpunit/phpunit": "^4.8" + }, + "autoload": { + "classmap": [ + "src/" + ] + } +} diff --git a/src/AutoLoader.php b/src/AutoLoader.php new file mode 100755 index 00000000..cff5a959 --- /dev/null +++ b/src/AutoLoader.php @@ -0,0 +1,6 @@ + + * @copyright 2010-2016 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 0.1.0 + */ + +namespace MyParcel\sdk\Helper; +use MyParcel\sdk\Model\Repository\MyParcelConsignmentRepository; + + +/** + * Stores all data to communicate with the MyParcel API + * + * Class MyParcelAPI + * @package Model + */ +class MyParcelAPI +{ + /** + * @var array + */ + private $consignments = []; + + /** + * @return array + */ + public function getConsignments() + { + return $this->consignments; + } + + public function getConsignmentById($id) + { + return $this->consignments[$id]; + } + + /** + * @param MyParcelConsignmentRepository $consignment + * + * @throws \Exception + */ + public function addConsignment(MyParcelConsignmentRepository $consignment) + { + if ($consignment->getApiKey() === null) { + throw new \Exception('First set the API key with setCc() before running addConsignment()'); + } + + $this->consignments[][$consignment->getApiKey()] = $consignment; + } + + public function registerConcept() + { + var_dump($this->consignments); + } + + public function getLabel() + { + var_dump($this->consignments); + } + + public function getReturnLabel() + { + var_dump($this->consignments); + } +} \ No newline at end of file diff --git a/src/Model/MyParcelConsignment.php b/src/Model/MyParcelConsignment.php new file mode 100755 index 00000000..f1ad2c1b --- /dev/null +++ b/src/Model/MyParcelConsignment.php @@ -0,0 +1,758 @@ + + * @copyright 2010-2016 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 0.1.0 + */ +namespace MyParcel\sdk\Model; + + +/** + * A model of a consignment + * + * Class Consignment + * @package MyParcel\sdk\Model + */ +class MyParcelConsignment +{ + /** + * @var int + */ + private $id; + + /** + * @var string + */ + private $apiKey; + + /** + * @var int + */ + private $status = 0; + + /** + * @var integer + */ + private $shop_id; + + /** + * @var string + */ + private $cc; + + /** + * @var string + */ + private $city; + + /** + * @var string + */ + private $street; + + /** + * @var integer + */ + private $number; + + /** + * @var string + */ + private $number_suffix; + + /** + * @var string + */ + private $postal_code; + + /** + * @var string + */ + private $person; + + /** + * @var string + */ + private $company; + + /** + * @var string + */ + private $email; + + /** + * @var string + */ + private $phone; + + /** + * @var integer + */ + private $package_type; + + /** + * @var integer + */ + private $delivery_type; + + /** + * @var string + */ + private $delivery_date; + + /** + * @var string + */ + private $delivery_remark; + + /** + * @var boolean + */ + private $only_recipient; + + /** + * @var boolean + */ + private $signature; + + /** + * @var boolean + */ + private $return; + + /** + * @var boolean + */ + private $large_format; + + /** + * @var string + */ + private $label_description; + + /** + * @var array + */ + private $insurance = []; + + /** + * @var int + */ + private $contents; + + /** + * @var string + */ + private $invoice; + + /** + * @var array + */ + private $items = []; + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * The id of the consignment + * + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return string + */ + public function getApiKey() + { + return $this->apiKey; + } + + /** + * Set the api key for each shipment. + * + * The key must be given to each shipment. So you can create multiple shipments + * in one time for different shops. This way you will not have to ask for the + * shop ID. The field shop ID is therefore not necessary. + * + * @param string $apiKey + */ + public function setApiKey($apiKey) + { + $this->apiKey = $apiKey; + } + + /** + * @return int + */ + public function getStatus() + { + return $this->status; + } + + /** + * Status of the consignment + * + * Pattern: [1 – 99] + * Example: 1 pending - concept + * 2 pending - registered + * 3 enroute - handed to carrier + * 4 enroute - sorting + * 5 enroute - distribution + * 6 enroute - customs + * 7 delivered - at recipient + * 8 delivered - ready for pickup + * 9 delivered - package picked up + * 10 delivered - return shipment ready for pickup + * 11 delivered - return shipment package picked up + * 12 printed - letter + * 13 credit + * 30 inactive - concept + * 31 inactive - registered + * 32 inactive - enroute - handed to carrier + * 33 inactive - enroute - sorting + * 34 inactive - enroute - distribution + * 35 inactive - enroute - customs + * 36 inactive - delivered - at recipient + * 37 inactive - delivered - ready for pickup + * 38 inactive - delivered - package picked up + * 99 inactive - unknown + * + * @param int $status + */ + public function setStatus($status) + { + $this->status = $status; + } + + /** + * @return mixed + */ + public function getShopId() + { + return $this->shop_id; + } + + /** + * The shop id to which this shipment belongs + * + * When the store ID is not specified, the API will look at the API key. + * Required: No + * + * @param mixed $shop_id + */ + public function setShopId($shop_id) + { + $this->shop_id = $shop_id; + } + + /** + * @return string + */ + public function getCc() + { + return $this->cc; + } + + /** + * The address country code + * + * ISO3166-1 alpha2 country code + * Pattern: [A-Z]{2,2} + * Example: NL, BE, CW + * Required: Yes + * + * @param string $cc + */ + public function setCc($cc) + { + $this->cc = $cc; + } + + /** + * @return string + */ + public function getCity() + { + return $this->city; + } + + /** + * The address city + * + * Required: Yes + * + * @param string $city + */ + public function setCity($city) + { + $this->city = $city; + } + + /** + * @return string + */ + public function getStreet() + { + return $this->street; + } + + /** + * The address street name + * + * Required: Yes, for international shipment use setFullStreet() + * + * @param string $street + */ + public function setStreet($street) + { + $this->street = $street; + } + + /** + * @return int + */ + public function getNumber() + { + return $this->number; + } + + /** + * Street number + * + * Whole numeric value + * Pattern: [0-9]+ + * Example: 10. 20. NOT 2,3 + * Required: Yes for NL + * + * @param int $number + */ + public function setNumber($number) + { + $this->number = $number; + } + + /** + * @return string + */ + public function getNumberSuffix() + { + return $this->number_suffix; + } + + /** + * Street number suffix. + * + * Required: no + * + * @param string $number_suffix + */ + public function setNumberSuffix($number_suffix) + { + $this->number_suffix = $number_suffix; + } + + /** + * @return string + */ + public function getPostalCode() + { + return $this->postal_code; + } + + /** + * The address postal code + * + * Required: Yes for NL and EU destinations except for IE + * + * @param string $postal_code + */ + public function setPostalCode($postal_code) + { + $this->postal_code = $postal_code; + } + + /** + * @return string + */ + public function getPerson() + { + return $this->person; + } + + /** + * The person at this address + * + * Required: Yes + * + * @param string $person + */ + public function setPerson($person) + { + $this->person = $person; + } + + /** + * @return string + */ + public function getCompany() + { + return $this->company; + } + + /** + * Company name + * + * Required: no + * + * @param string $company + */ + public function setCompany($company) + { + $this->company = $company; + } + + /** + * @return string + */ + public function getEmail() + { + return $this->email; + } + + /** + * The address email + * + * Required: no + * + * @param string $email + */ + public function setEmail($email) + { + $this->email = $email; + } + + /** + * @return string + */ + public function getPhone() + { + return $this->phone; + } + + /** + * The address phone + * + * Required: no + * + * @param string $phone + */ + public function setPhone($phone) + { + $this->phone = $phone; + } + + /** + * @return int + */ + public function getPackageType() + { + return $this->package_type; + } + + /** + * The package type + * + * For international shipment only package type 1 is allowed + * Pattern: [1 – 3] + * Example: 1. package + * 2. mailbox package + * 3. letter + * + * Required: Yes + * + * @param int $package_type + */ + public function setPackageType($package_type) + { + $this->package_type = $package_type; + } + + /** + * @return int + */ + public function getDeliveryType() + { + return $this->delivery_type; + } + + /** + * The delivery type for the package + * + * Required: Yes if delivery_date has been specified + * + * @param int $delivery_type + */ + public function setDeliveryType($delivery_type) + { + $this->delivery_type = $delivery_type; + } + + /** + * @return string + */ + public function getDeliveryDate() + { + return $this->delivery_date; + } + + /** + * The delivery date time for this shipment + * Pattern: YYYY-MM-DD + * Example: 2017-01-01 + * Required: Yes if delivery type has been specified + * + * @param string $delivery_date + */ + public function setDeliveryDate($delivery_date) + { + $this->delivery_date = $delivery_date; + } + + /** + * @return string + */ + public function getDeliveryRemark() + { + return $this->delivery_remark; + } + + /** + * The delivery remark. + * + * Required: No + * + * @param string $delivery_remark + */ + public function setDeliveryRemark($delivery_remark) + { + $this->delivery_remark = $delivery_remark; + } + + /** + * @return boolean + */ + public function isOnlyRecipient() + { + return $this->only_recipient; + } + + /** + * Deliver the package to the recipient only + * + * Required: No + * + * @param boolean $only_recipient + */ + public function setOnlyRecipient($only_recipient) + { + $this->only_recipient = $only_recipient; + } + + /** + * @return boolean + */ + public function isSignature() + { + return $this->signature; + } + + /** + * Package must be signed for + * + * Required: No + * + * @param boolean $signature + */ + public function setSignature($signature) + { + $this->signature = $signature; + } + + /** + * @return boolean + */ + public function isReturn() + { + return $this->return; + } + + /** + * Return the package if the recipient is not home + * + * Required: No + * + * @param boolean $return + */ + public function setReturn($return) + { + $this->return = $return; + } + + /** + * @return boolean + */ + public function isLargeFormat() + { + return $this->large_format; + } + + /** + * Large format package + * + * Required: No + * + * @param boolean $large_format + */ + public function setLargeFormat($large_format) + { + $this->large_format = $large_format; + } + + /** + * @return mixed + */ + public function getLabelDescription() + { + return $this->label_description; + } + + /** + * This description will appear on the shipment label + * + * Note: This will be overridden for return shipment by the following: Retour – 3SMYPAMYPAXXXXXX + * + * Required: No + * + * @param mixed $label_description + */ + public function setLabelDescription($label_description) + { + $this->label_description = $label_description; + } + + /** + * @return array + */ + public function getInsurance() + { + return $this->insurance; + } + + /** + * Insurance price for the package. + * + * Composite type containing integer and currency. The amount is without decimal + * separators (in cents). + * Pattern: {"amount": integer, "currency": currency } + * Example: {"amount": 5000, "currency": "EUR"} + * Required: No + * + * @param array $insurance + */ + public function setInsurance($insurance) + { + $this->insurance = $insurance; + } + + /** + * @return mixed + */ + public function getContents() + { + return $this->contents; + } + + /** + * The type of contents in the package. + * + * The package contents are only needed in case of shipping outside EU, + * this is mandatory info for customs form. + * Pattern: [1 - 5] + * Example 1. commerial goods + * 2. commercial samples + * 3. documents + * 4. gifts + * 5. return shipment + * Required: Yes + * + * @param int $contents + */ + public function setContents($contents) + { + $this->contents = $contents; + } + + + /** + * @return string + */ + public function getInvoice() + { + return $this->invoice; + } + + /** + * The invoice number for the commercial goods or samples of package contents. + * + * Required: Yes for commercial goods, commercial samples and return shipment package contents. + * + * @param string $invoice + */ + public function setInvoice($invoice) + { + $this->invoice = $invoice; + } + + /** + * @return array + */ + public function getItems() + { + return $this->items; + } + + /** + * An array containing CustomsItem objects with description for each item + * in the package. + * + * Required: Yes for international shipments + * + * @param array $item + */ + public function addItems($item) + { + $this->items[] = $item; + } + +} \ No newline at end of file diff --git a/src/Model/MyParcelCustomsItem.php b/src/Model/MyParcelCustomsItem.php new file mode 100644 index 00000000..735c9143 --- /dev/null +++ b/src/Model/MyParcelCustomsItem.php @@ -0,0 +1,173 @@ + + * @copyright 2010-2016 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 0.1.0 + */ + +namespace MyParcel\sdk\Model; + + +/** + * This object is embedded in the MyParcelConsignment object for global shipments and is + * mandatory for non-EU shipments. + * + * Class MyParcelCustomsItem + * @package Model\Repository + */ +class MyParcelCustomsItem +{ + private $description; + private $amount; + private $weight; + private $item_value; + private $classification; + private $country; + + /** + * @return mixed + */ + public function getDescription() + { + return $this->description; + } + + /** + * The description of the item + * + * Required: Yes + * + * @param mixed $description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * @return int + */ + public function getAmount() + { + return $this->amount; + } + + /** + * The amount of this item in the package. The minimum amount is 1. + * + * Required: Yes + * + * @param int $amount + */ + public function setAmount($amount) + { + $this->amount = $amount; + } + + /** + * @return int + */ + public function getWeight() + { + return $this->weight; + } + + /** + * The total weight for these items in whole grams. Between 0 and 20000 grams. + * + * Required: Yes + * + * @param int $weight + */ + public function setWeight($weight) + { + $this->weight = $weight; + } + + /** + * Item value. + * + * @return int + */ + public function getItemValue() + { + return $this->item_value; + } + + /** + * Item value + * + * Composite type containing integer and currency. The amount is without decimal + * separators (in cents). + * Pattern: {"amount": integer, "currency": currency } + * Example {"amount": 5000, "currency": "EUR"} + * Required: Yes + * + * @param int $item_value + */ + public function setItemValue($item_value) + { + $this->item_value = $item_value; + } + + /** + * @return int + */ + public function getClassification() + { + return $this->classification; + } + + /** + * International Standard Industry Classification + * + * Pattern: [0-9]{1,4} + * Example: 0111 (Growing of cereals (except rice), leguminous crops and oil seeds) + * Required: Yes + * + * @link http://gebruikstarief.douane.nl/ + * + * @param int $classification + */ + public function setClassification($classification) + { + $this->classification = $classification; + } + + /** + * @return string + */ + public function getCountry() + { + return $this->country; + } + + /** + * The country of origin for this item + * + * ISO3166-1 alpha2 country code + * Pattern: [A-Z]{2,2} + * Example: NL, BE, CW + * Required: Yes + * + * @param string $country + */ + public function setCountry($country) + { + $this->country = $country; + } + + +} \ No newline at end of file diff --git a/src/Model/Repository/MyParcelConsignmentRepository.php b/src/Model/Repository/MyParcelConsignmentRepository.php new file mode 100755 index 00000000..ee89c60a --- /dev/null +++ b/src/Model/Repository/MyParcelConsignmentRepository.php @@ -0,0 +1,142 @@ + + * @copyright 2010-2016 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 0.1.0 + */ +namespace MyParcel\sdk\Model\Repository; + + +use MyParcel\sdk\Model\MyParcelConsignment; + +/** + * The repository of a MyParcel consignment + * + * Class MyParcelConsignmentRepository + * @package MyParcel\sdk\Model\Repository + */ +class MyParcelConsignmentRepository extends MyParcelConsignment +{ + /** + * Regular expression used to split street name from house number. + * + * For the full description go to: + * @link https://gist.github.com/reindert-vetter/a90fdffe7d452f92d1c65bbf759f6e38 + */ + const SPLIT_STREET_REGEX = '~(?P.*?)\s?(?P(?P[\d]+)-?(?P[a-zA-Z/\s]{0,5}$|[0-9/]{0,5}$|\s[a-zA-Z]{1}[0-9]{0,3}$))$~'; + + /** + * Get entire street + * + * @return string Entire street + */ + public function getFullStreet() + { + $fullStreet = $this->getStreet(); + + if ($this->getNumber()) + $fullStreet .= ' ' . $this->getNumber(); + + if ($this->getNumberSuffix()) + $fullStreet .= ' ' . $this->getNumberSuffix(); + + return trim($fullStreet); + } + + /** + * Splitting a full NL address and save it in this class + * + * Required: Yes for international shipment + * + * @param $fullStreet + * + * @throws \Exception + */ + public function setFullStreet($fullStreet) + { + if ($this->getCc() === null) { + throw new \Exception('First set the country code with setCc() before running setFullStreet()'); + } + + if ($this->getCc() == 'NL') { + $streetData = $this->_splitStreet($fullStreet); + $this->setStreet($streetData['street']); + $this->setNumber($streetData['number']); + $this->setNumberSuffix($streetData['number_suffix']); + } else { + $this->setStreet($fullStreet); + } + } + + + /** + * Splits street data into separate parts for street name, house number and extension. + * + * @param string $fullStreet The full street name including all parts + * + * @return array + * + * @throws \Exception + */ + protected function _splitStreet($fullStreet) + { + $street = ''; + $number = ''; + $number_suffix = ''; + + $fullStreet = preg_replace("/[\n\r]/", "", $fullStreet); + $result = preg_match(self::SPLIT_STREET_REGEX, $fullStreet, $matches); + + if (!$result || !is_array($matches) || $fullStreet != $matches[0]) { + if ($fullStreet != $matches[0]) { + // Characters are gone by preg_match + throw new \Exception('Something went wrong with splitting up address ' . $fullStreet); + } else { + // Invalid full street supplied + throw new \Exception('Invalid full street supplied: ' . $fullStreet); + } + } + + if (isset($matches['street'])) { + $street = $matches['street']; + } + + if (isset($matches['number'])) { + $number = $matches['number']; + } + + if (isset($matches['number_suffix'])) { + $number_suffix = trim($matches['number_suffix']); + } + + $streetData = array( + 'street' => $street, + 'number' => $number, + 'number_suffix' => $number_suffix, + ); + + return $streetData; + } + + /** + * The total weight for all items in whole grams + * + * @todo get weight of all items + * + * @return int + */ + public function getTotalWeight() + { + return; + } +} \ No newline at end of file