diff --git a/composer.json b/composer.json index 4265b7df..cd6ad9c3 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "antidot-be/bpost-api-library", - "version": "3.4.7", + "version": "3.4.8", "type": "library", "description": "bpost API library is a PHP library to communicate with the bpost API.", "homepage": "https://github.com/Antidot-be/bpost-api-library", @@ -28,7 +28,7 @@ "ext-mbstring": "*", "psr/log": "^1.0", "ext-dom": "20031129", - "ext-SimpleXML": "^7.2" + "ext-SimpleXML": "*" }, "require-dev": { "phpunit/phpunit": "^4.8 || ^5.3" diff --git a/composer.lock b/composer.lock index 1b8ba375..fb00ed3d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f3420661fd270f0b94093a5349d2b8ea", + "content-hash": "4e9b91a18511a913c3a9e4cc681c4162", "packages": [ { "name": "psr/log", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", "shasum": "" }, "require": { @@ -51,7 +51,7 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2018-11-20T15:27:04+00:00" } ], "packages-dev": [ @@ -113,16 +113,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.9.1", + "version": "1.9.3", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72" + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", - "reference": "e6828efaba2c9b79f4499dae1d66ef8bfa7b2b72", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/007c053ae6f31bba39dfa19a7726f56e9763bbea", + "reference": "007c053ae6f31bba39dfa19a7726f56e9763bbea", "shasum": "" }, "require": { @@ -157,39 +157,37 @@ "object", "object graph" ], - "time": "2019-04-07T13:18:21+00:00" + "time": "2019-08-09T12:45:53+00:00" }, { "name": "phpdocumentor/reflection-common", - "version": "1.0.1", + "version": "2.0.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionCommon.git", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6" + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", - "reference": "21bdeb5f65d7ebf9f43b1b25d404f87deab5bfb6", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/63a995caa1ca9e5590304cd845c15ad6d482a62a", + "reference": "63a995caa1ca9e5590304cd845c15ad6d482a62a", "shasum": "" }, "require": { - "php": ">=5.5" + "php": ">=7.1" }, "require-dev": { - "phpunit/phpunit": "^4.6" + "phpunit/phpunit": "~6" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src" - ] + "phpDocumentor\\Reflection\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -211,30 +209,30 @@ "reflection", "static analysis" ], - "time": "2017-09-11T18:02:19+00:00" + "time": "2018-08-07T13:53:10+00:00" }, { "name": "phpdocumentor/reflection-docblock", - "version": "4.3.0", + "version": "4.3.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08" + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/94fd0001232e47129dd3504189fa1c7225010d08", - "reference": "94fd0001232e47129dd3504189fa1c7225010d08", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/b83ff7cfcfee7827e1e78b637a5904fe6a96698e", + "reference": "b83ff7cfcfee7827e1e78b637a5904fe6a96698e", "shasum": "" }, "require": { "php": "^7.0", - "phpdocumentor/reflection-common": "^1.0.0", - "phpdocumentor/type-resolver": "^0.4.0", + "phpdocumentor/reflection-common": "^1.0.0 || ^2.0.0", + "phpdocumentor/type-resolver": "~0.4 || ^1.0.0", "webmozart/assert": "^1.0" }, "require-dev": { - "doctrine/instantiator": "~1.0.5", + "doctrine/instantiator": "^1.0.5", "mockery/mockery": "^1.0", "phpunit/phpunit": "^6.4" }, @@ -262,41 +260,40 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2017-11-30T07:14:17+00:00" + "time": "2019-09-12T14:27:41+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "0.4.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7" + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/9c977708995954784726e25d0cd1dddf4e65b0f7", - "reference": "9c977708995954784726e25d0cd1dddf4e65b0f7", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", + "reference": "2e32a6d48972b2c1976ed5d8967145b6cec4a4a9", "shasum": "" }, "require": { - "php": "^5.5 || ^7.0", - "phpdocumentor/reflection-common": "^1.0" + "php": "^7.1", + "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "mockery/mockery": "^0.9.4", - "phpunit/phpunit": "^5.2||^4.8.24" + "ext-tokenizer": "^7.1", + "mockery/mockery": "~1", + "phpunit/phpunit": "^7.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { "psr-4": { - "phpDocumentor\\Reflection\\": [ - "src/" - ] + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -309,20 +306,21 @@ "email": "me@mikevanriel.com" } ], - "time": "2017-07-14T14:27:02+00:00" + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "time": "2019-08-22T18:11:29+00:00" }, { "name": "phpspec/prophecy", - "version": "1.8.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06" + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4ba436b55987b4bf311cb7c6ba82aa528aac0a06", - "reference": "4ba436b55987b4bf311cb7c6ba82aa528aac0a06", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/1927e75f4ed19131ec9bcc3b002e07fb1173ee76", + "reference": "1927e75f4ed19131ec9bcc3b002e07fb1173ee76", "shasum": "" }, "require": { @@ -343,8 +341,8 @@ } }, "autoload": { - "psr-0": { - "Prophecy\\": "src/" + "psr-4": { + "Prophecy\\": "src/Prophecy" } }, "notification-url": "https://packagist.org/downloads/", @@ -372,7 +370,7 @@ "spy", "stub" ], - "time": "2018-08-05T17:53:17+00:00" + "time": "2019-06-13T12:50:23+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1280,16 +1278,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.11.0", + "version": "v1.12.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "82ebae02209c21113908c229e9883c419720738a" + "reference": "550ebaac289296ce228a706d0867afc34687e3f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/82ebae02209c21113908c229e9883c419720738a", - "reference": "82ebae02209c21113908c229e9883c419720738a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/550ebaac289296ce228a706d0867afc34687e3f4", + "reference": "550ebaac289296ce228a706d0867afc34687e3f4", "shasum": "" }, "require": { @@ -1301,7 +1299,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11-dev" + "dev-master": "1.12-dev" } }, "autoload": { @@ -1317,13 +1315,13 @@ "MIT" ], "authors": [ - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - }, { "name": "Gert de Pagter", "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" } ], "description": "Symfony polyfill for ctype functions", @@ -1334,20 +1332,20 @@ "polyfill", "portable" ], - "time": "2019-02-06T07:57:58+00:00" + "time": "2019-08-06T08:03:45+00:00" }, { "name": "symfony/yaml", - "version": "v4.2.7", + "version": "v4.3.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "6712daf03ee25b53abb14e7e8e0ede1a770efdb1" + "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/6712daf03ee25b53abb14e7e8e0ede1a770efdb1", - "reference": "6712daf03ee25b53abb14e7e8e0ede1a770efdb1", + "url": "https://api.github.com/repos/symfony/yaml/zipball/5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", + "reference": "5a0b7c32dc3ec56fd4abae8a4a71b0cf05013686", "shasum": "" }, "require": { @@ -1366,7 +1364,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -1393,20 +1391,20 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2019-03-30T15:58:42+00:00" + "time": "2019-08-20T14:27:59+00:00" }, { "name": "webmozart/assert", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/webmozart/assert.git", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9" + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webmozart/assert/zipball/83e253c8e0be5b0257b881e1827274667c5c17a9", - "reference": "83e253c8e0be5b0257b881e1827274667c5c17a9", + "url": "https://api.github.com/repos/webmozart/assert/zipball/88e6d84706d09a236046d686bbea96f07b3a34f4", + "reference": "88e6d84706d09a236046d686bbea96f07b3a34f4", "shasum": "" }, "require": { @@ -1414,8 +1412,7 @@ "symfony/polyfill-ctype": "^1.8" }, "require-dev": { - "phpunit/phpunit": "^4.6", - "sebastian/version": "^1.0.1" + "phpunit/phpunit": "^4.8.36 || ^7.5.13" }, "type": "library", "extra": { @@ -1444,7 +1441,7 @@ "check", "validate" ], - "time": "2018-12-25T11:19:39+00:00" + "time": "2019-08-24T08:43:50+00:00" } ], "aliases": [], @@ -1457,7 +1454,7 @@ "ext-curl": "*", "ext-mbstring": "*", "ext-dom": "20031129", - "ext-simplexml": "^7.2" + "ext-simplexml": "*" }, "platform-dev": [] } diff --git a/src/Bpost.php b/src/Bpost.php index e1b6ab78..b8e20dba 100644 --- a/src/Bpost.php +++ b/src/Bpost.php @@ -2,6 +2,7 @@ namespace Bpost\BpostApiClient; use Bpost\BpostApiClient\ApiCaller\ApiCaller; +use Psr\Log\LoggerInterface; use Bpost\BpostApiClient\Bpost\CreateLabelInBulkForOrders; use Bpost\BpostApiClient\Bpost\Labels; use Bpost\BpostApiClient\Bpost\Order; @@ -14,7 +15,6 @@ use Bpost\BpostApiClient\Exception\BpostApiResponseException\BpostInvalidSelectionException; use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException; use Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException; -use Psr\Log\LoggerInterface; /** * Bpost class @@ -26,7 +26,6 @@ */ class Bpost { - const LABEL_FORMAT_A4 = 'A4'; const LABEL_FORMAT_A6 = 'A6'; @@ -221,7 +220,6 @@ private function doCall($url, $body = null, $headers = array(), $method = 'GET', $headers[] = 'Authorization: Basic ' . $this->getAuthorizationHeader(); // set options - $options = array(); $options[CURLOPT_URL] = $this->apiUrl . '/' . $this->accountId . $url; if ($this->getPort() != 0) { $options[CURLOPT_PORT] = $this->getPort(); @@ -367,7 +365,7 @@ public function setUserAgent($userAgent) } // webservice methods -// orders + // orders /** * Creates a new order. If an order with the same orderReference already exists * @@ -408,6 +406,60 @@ public function createOrReplaceOrder(Order $order) ); } + /** + * Get List of Internationnal Pugo available near the shipping location + * @param string $userLanguage The language of the client (the only two letter of it. e.g. : fr/en/de/nl/... + * @param string $country The country of the shipping Address (transform just below to take the first two letter) + * @param string $streetName The street name of the shipping Address (transform just below to replace space into +) + * @param int $streetNumber The number of the house of the shipping Address + * @param int $postalCode The postal code of the shipping Address + * @return SimpleXMLElement Return the pugo point, if the pugo no more exist, return the first of the list + */ + public function getPugoInformation($userLanguage, $country, $street, $streetNumber, $postalCode) + { + $country = substr($country, 0, 2); + $streetName = str_replace(" ", "+", $street); + + $url = "http://pudo.bpost.be/Locator?Function=search". + "&Partner=".$this->accountId. + "&Language=".$userLanguage. + "&Zone=".$postalCode. + "&Country=".$country. + "&Type=2"; + + // build Authorization header + $headers[] = 'Authorization: Basic ' . $this->getAuthorizationHeader(); + + // set options + $options[CURLOPT_URL] = $url; + if ($this->getPort() != 0) { + $options[CURLOPT_PORT] = $this->getPort(); + } + $options[CURLOPT_USERAGENT] = $this->getUserAgent(); + $options[CURLOPT_RETURNTRANSFER] = true; + $options[CURLOPT_TIMEOUT] = (int)$this->getTimeOut(); + $options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; + $options[CURLOPT_HTTPHEADER] = $headers; + + $this->getApiCaller()->doCall($options); + + $response = $this->getApiCaller()->getResponseBody(); + + $Pois = simplexml_load_string($response)->PoiList->Poi; + + $pugo = null; + foreach ($Pois as $Poi) { + if ((string) $Poi->Record->Street == $street && (string) $Poi->Record->Number == $streetNumber) { + $pugo = $Poi->Record; + } + } + if ($pugo == null) { + $pugo = $Pois[0]->Record; + } + + return $pugo; + } + /** * Fetch an order * @@ -508,7 +560,7 @@ public function modifyOrderStatus($reference, $status) ); } -// labels + // labels /** * Get the possible label formats * diff --git a/src/Bpost/Order/Address.php b/src/Bpost/Order/Address.php index 8bd9bbac..67403b43 100644 --- a/src/Bpost/Order/Address.php +++ b/src/Bpost/Order/Address.php @@ -213,9 +213,12 @@ public function __construct( * @param string $prefix * @return \DOMElement */ - public function toXML(\DOMDocument $document, $prefix = 'common') + public function toXML(\DOMDocument $document, $prefix = 'common', $international = false) { $tagName = static::TAG_NAME; + if ($tagName =="pugoAddress" and $international == true){ + $tagName="international:pugoAddress"; + } $address = $document->createElement($tagName); $document->appendChild($address); diff --git a/src/Bpost/Order/Box/AtIntlPugo.php b/src/Bpost/Order/Box/AtIntlPugo.php new file mode 100644 index 00000000..4dee41c7 --- /dev/null +++ b/src/Bpost/Order/Box/AtIntlPugo.php @@ -0,0 +1,337 @@ + + * @version 3.0.0 + * @copyright Copyright (c), Tijs Verkoyen. All rights reserved. + * @license BSD License + */ +class AtIntlPugo extends International +{ + /** @var string */ + protected $product = Product::PRODUCT_NAME_BPACK_AT_BPOST_INTERNATIONAL; + + /** @var string */ + private $pugoId; + + /** @var string */ + private $pugoName; + + /** @var \Bpost\BpostApiClient\Bpost\Order\PugoAddress */ + private $pugoAddress; + + /** @var string */ + private $receiverName; + + /** @var string */ + private $receiverCompany; + + /** @var string */ + protected $requestedDeliveryDate; + + /** @var ShopHandlingInstruction */ + private $shopHandlingInstruction; + + /** + * @param string $product Possible values are: bpack@bpost + * @throws BpostInvalidValueException + */ + public function setProduct($product) + { + if (!in_array($product, self::getPossibleProductValues())) { + throw new BpostInvalidValueException('product', $product, self::getPossibleProductValues()); + } + + parent::setProduct($product); + } + + /** + * @return array + */ + public static function getPossibleProductValues() + { + return array( + Product::PRODUCT_NAME_BPACK_AT_BPOST, + ); + } + + /** + * @param \Bpost\BpostApiClient\Bpost\Order\PugoAddress $pugoAddress + */ + public function setPugoAddress($pugoAddress) + { + $this->pugoAddress = $pugoAddress; + } + + /** + * @return \Bpost\BpostApiClient\Bpost\Order\PugoAddress + */ + public function getPugoAddress() + { + return $this->pugoAddress; + } + + /** + * @param string $pugoId + */ + public function setPugoId($pugoId) + { + $this->pugoId = $pugoId; + } + + /** + * @return string + */ + public function getPugoId() + { + return $this->pugoId; + } + + /** + * @param string $pugoName + */ + public function setPugoName($pugoName) + { + $this->pugoName = $pugoName; + } + + /** + * @return string + */ + public function getPugoName() + { + return $this->pugoName; + } + + /** + * @param string $receiverCompany + */ + public function setReceiverCompany($receiverCompany) + { + $this->receiverCompany = $receiverCompany; + } + + /** + * @return string + */ + public function getReceiverCompany() + { + return $this->receiverCompany; + } + + /** + * @param string $receiverName + */ + public function setReceiverName($receiverName) + { + $this->receiverName = $receiverName; + } + + /** + * @return string + */ + public function getReceiverName() + { + return $this->receiverName; + } + + /** + * @return string + */ + public function getRequestedDeliveryDate() + { + return $this->requestedDeliveryDate; + } + + /** + * @param string $requestedDeliveryDate + */ + public function setRequestedDeliveryDate($requestedDeliveryDate) + { + $this->requestedDeliveryDate = $requestedDeliveryDate; + } + + /** + * @return string + */ + public function getShopHandlingInstruction() + { + if ($this->shopHandlingInstruction !== null) { + return $this->shopHandlingInstruction->getValue(); + } + return null; + } + + /** + * @param string $shopHandlingInstruction + */ + public function setShopHandlingInstruction($shopHandlingInstruction) + { + $this->shopHandlingInstruction = new ShopHandlingInstruction($shopHandlingInstruction); + } + + /** + * Return the object as an array for usage in the XML + * + * @param \DomDocument $document + * @param string $prefix + * @param string $type + * @return \DomElement + */ + public function toXML(\DOMDocument $document, $prefix = null, $type = null) + { + $internationalBox = $document->createElement($this->getPrefixedTagName('internationalBox', 'tns')); + $boxElement = parent::toPugoXML($document, 'international', 'atIntlPugo'); + + $internationalBox->appendChild($boxElement); + + if ($this->getPugoId() !== null) { + $boxElement->appendChild( + $document->createElement('international:pugoId', $this->getPugoId()) + ); + } + if ($this->getPugoName() !== null) { + $boxElement->appendChild( + $document->createElement('international:pugoName', $this->getPugoName()) + ); + } + + if ($this->getPugoAddress() !== null) { + $boxElement->appendChild( + $this->getPugoAddress()->toXML($document, 'common', true) + ); + } + + $this->addToXmlRequestedDeliveryDate($document, $boxElement, $prefix); + $this->addToXmlShopHandlingInstruction($document, $boxElement, $prefix); + return $internationalBox; + } + + /** + * @param \DOMDocument $document + * @param \DOMElement $typeElement + * @param string $prefix + */ + protected function addToXmlRequestedDeliveryDate(\DOMDocument $document, \DOMElement $typeElement, $prefix) + { + if ($this->getRequestedDeliveryDate() !== null) { + $typeElement->appendChild( + $document->createElement('requestedDeliveryDate', $this->getRequestedDeliveryDate()) + ); + } + } + + private function addToXmlShopHandlingInstruction(\DOMDocument $document, \DOMElement $typeElement, $prefix) + { + if ($this->getShopHandlingInstruction() !== null) { + $typeElement->appendChild( + $document->createElement('shopHandlingInstruction', $this->getShopHandlingInstruction()) + ); + } + } + + /** + * @param \SimpleXMLElement $xml + * + * @return AtBpost + * @throws BpostInvalidValueException + * @throws BpostNotImplementedException + */ + public static function createFromXML(\SimpleXMLElement $xml) + { + dump(__METHOD__); + $atBpost = new AtBpost(); + + if (isset($xml->atBpost->product) && $xml->atBpost->product != '') { + $atBpost->setProduct( + (string)$xml->atBpost->product + ); + } + if (isset($xml->atBpost->options)) { + /** @var \SimpleXMLElement $optionData */ + foreach ($xml->atBpost->options as $optionData) { + $optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common'); + + if (in_array( + $optionData->getName(), + array( + Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED, + Messaging::MESSAGING_TYPE_INFO_NEXT_DAY, + Messaging::MESSAGING_TYPE_INFO_REMINDER, + Messaging::MESSAGING_TYPE_KEEP_ME_INFORMED, + ) + ) + ) { + $option = Messaging::createFromXML($optionData); + } else { + $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\Option\\' . ucfirst($optionData->getName()); + if (!method_exists($className, 'createFromXML')) { + throw new BpostNotImplementedException(); + } + $option = call_user_func( + array($className, 'createFromXML'), + $optionData + ); + } + + $atBpost->addOption($option); + } + } + if (isset($xml->atBpost->weight) && $xml->atBpost->weight != '') { + $atBpost->setWeight( + (int)$xml->atBpost->weight + ); + } + if (isset($xml->atBpost->receiverName) && $xml->atBpost->receiverName != '') { + $atBpost->setReceiverName( + (string)$xml->atBpost->receiverName + ); + } + if (isset($xml->atBpost->receiverCompany) && $xml->atBpost->receiverCompany != '') { + $atBpost->setReceiverCompany( + (string)$xml->atBpost->receiverCompany + ); + } + if (isset($xml->atBpost->pugoId) && $xml->atBpost->pugoId != '') { + $atBpost->setPugoId( + (string)$xml->atBpost->pugoId + ); + } + if (isset($xml->atBpost->pugoName) && $xml->atBpost->pugoName != '') { + $atBpost->setPugoName( + (string)$xml->atBpost->pugoName + ); + } + if (isset($xml->atBpost->pugoAddress)) { + /** @var \SimpleXMLElement $pugoAddressData */ + $pugoAddressData = $xml->atBpost->pugoAddress->children( + 'http://schema.post.be/shm/deepintegration/v3/common' + ); + $atBpost->setPugoAddress( + PugoAddress::createFromXML($pugoAddressData) + ); + } + if (isset($xml->atBpost->requestedDeliveryDate) && $xml->atBpost->requestedDeliveryDate != '') { + $atBpost->setRequestedDeliveryDate( + (string)$xml->atBpost->requestedDeliveryDate + ); + } + if (isset($xml->atBpost->shopHandlingInstruction) && $xml->atBpost->shopHandlingInstruction != '') { + $atBpost->setShopHandlingInstruction( + (string)$xml->atBpost->shopHandlingInstruction + ); + } + + return $atBpost; + } +} diff --git a/src/Bpost/Order/Box/International.php b/src/Bpost/Order/Box/International.php index e04dd68e..73cfe5d3 100644 --- a/src/Bpost/Order/Box/International.php +++ b/src/Bpost/Order/Box/International.php @@ -131,6 +131,7 @@ public static function getPossibleProductValues() Product::PRODUCT_NAME_BPACK_WORLD_EASY_RETURN, Product::PRODUCT_NAME_BPACK_WORLD_EXPRESS_PRO, Product::PRODUCT_NAME_BPACK_EUROPE_BUSINESS, + Product::PRODUCT_NAME_BPACK_AT_BPOST_INTERNATIONAL, ); } @@ -212,6 +213,61 @@ public function toXML(\DOMDocument $document, $prefix = null) return $internationalBox; } + /** + * Return the object as an array for usage in the XML + * + * @param \DomDocument $document + * @param string $prefix + * @return \DomElement + */ + public function toPugoXML(\DOMDocument $document, $prefix = null, $tagName = 'internationalBox') + { + if ($tagName != "atIntlPugo") { + throw new \Exception("tagName is not correct :". $tagName." instead of atIntlPugo", 1); + } + if ($prefix !== null) { + $tagName = $prefix . ':' . $tagName; + } + + $internationalBox = $document->createElement($tagName); + $international = $document->createElement('international:product', Product::PRODUCT_NAME_BPACK_AT_BPOST_INTERNATIONAL); + $internationalBox->appendChild($international); + + $options = $this->getOptions(); + if (!empty($options)) { + $optionsElement = $document->createElement('international:options'); + foreach ($options as $option) { + $optionsElement->appendChild( + $option->toXML($document) + ); + } + $internationalBox->appendChild($optionsElement); + } + + if ($this->getReceiver() !== null) { + $internationalBox->appendChild( + $this->getReceiver()->toXML($document, 'international') + ); + } + + if ($this->getParcelWeight() !== null) { + $internationalBox->appendChild( + $document->createElement( + 'international:parcelWeight', + $this->getParcelWeight() + ) + ); + } + + if ($this->getCustomsInfo() !== null) { + $internationalBox->appendChild( + $this->getCustomsInfo()->toXML($document, 'international') + ); + } + + return $internationalBox; + } + /** * @param \SimpleXMLElement $xml * @@ -240,10 +296,14 @@ public static function createFromXML(\SimpleXMLElement $xml) case 'insured': $class = 'Insurance'; break; + case 'keepMeInformed': + $class = 'Messaging'; + break; default: $class = ucfirst($optionData->getName()); } $className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\Option\\' . $class; + if (!method_exists($className, 'createFromXML')) { throw new BpostNotImplementedException('No createFromXML found into ' . $className); } @@ -277,4 +337,18 @@ public static function createFromXML(\SimpleXMLElement $xml) return $international; } + + /** + * Prefix $tagName with the $prefix, if needed + * @param string $prefix + * @param string $tagName + * @return string + */ + public function getPrefixedTagName($tagName, $prefix = null) + { + if (empty($prefix)) { + return $tagName; + } + return $prefix . ':' . $tagName; + } } diff --git a/src/Bpost/Order/Box/Option/Messaging.php b/src/Bpost/Order/Box/Option/Messaging.php index acbbb96f..76297b5a 100644 --- a/src/Bpost/Order/Box/Option/Messaging.php +++ b/src/Bpost/Order/Box/Option/Messaging.php @@ -73,7 +73,12 @@ public function getEmailAddress() */ public function setLanguage($language) { - $language = strtoupper($language); + if (empty($language)) { + $language = self::MESSAGING_LANGUAGE_EN; + } + else{ + $language = strtoupper($language); + } if (!in_array($language, self::getPossibleLanguageValues())) { throw new BpostInvalidValueException('language', $language, self::getPossibleLanguageValues()); diff --git a/src/Bpost/ProductConfiguration/Product.php b/src/Bpost/ProductConfiguration/Product.php index 8a5adfff..085ab09b 100644 --- a/src/Bpost/ProductConfiguration/Product.php +++ b/src/Bpost/ProductConfiguration/Product.php @@ -22,6 +22,7 @@ class Product const PRODUCT_NAME_BPACK_WORLD_EXPRESS_PRO = 'bpack World Express Pro'; const PRODUCT_NAME_BPACK_WORLD_BUSINESS = 'bpack World Business'; const PRODUCT_NAME_BPACK_EUROPE_BUSINESS = 'bpack Europe Business'; + const PRODUCT_NAME_BPACK_AT_BPOST_INTERNATIONAL = 'bpack@bpost international'; /** @var bool */ private $default; @@ -150,6 +151,7 @@ public function isForNationalShipping() case self::PRODUCT_NAME_BPACK_WORLD_EXPRESS_PRO: case self::PRODUCT_NAME_BPACK_WORLD_BUSINESS: case self::PRODUCT_NAME_BPACK_EUROPE_BUSINESS: + case self::PRODUCT_NAME_BPACK_AT_BPOST_INTERNATIONAL: default: return false; }