Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Bpost/Order/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ public static function createFromXML(SimpleXMLElement $xml)
$nationalBoxData = $xml->nationalBox->children(Bpost::NS_V3_NATIONAL);

// build classname based on the tag name
$className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\' . ucfirst($nationalBoxData->getName());
if ($nationalBoxData->getName() == 'at24-7') {
$className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\At247';
} else {
$className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\' . ucfirst($nationalBoxData->getName());
}

XmlHelper::assertMethodCreateFromXmlExists($className);
Expand Down
80 changes: 34 additions & 46 deletions src/Bpost/Order/Box/At247.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Bpost\BpostApiClient\Common\XmlHelper;
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException;
use Bpost\BpostApiClient\Exception\BpostNotImplementedException;
use Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException;
use DOMDocument;
use DOMElement;
use SimpleXMLElement;
Expand Down Expand Up @@ -313,70 +314,57 @@ protected function addToXmlUnregistered(DOMDocument $document, DOMElement $typeE
*/
public static function createFromXML(SimpleXMLElement $xml, National $self = null)
{
$at247 = new At247();

if (isset($xml->{'at24-7'}->product) && $xml->{'at24-7'}->product != '') {
$at247->setProduct(
(string) $xml->{'at24-7'}->product
);
if ($self === null) {
$self = new self();
}
if (isset($xml->{'at24-7'}->options)) {
/** @var SimpleXMLElement $optionData */
foreach ($xml->{'at24-7'}->options as $optionData) {
$optionData = $optionData->children(Bpost::NS_V3_COMMON);

if (in_array($optionData->getName(), array(Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED))) {
$option = Messaging::createFromXML($optionData);
} else {
$option = self::getOptionFromOptionData($optionData);
}

$at247->addOption($option);
}
}
if (isset($xml->{'at24-7'}->weight) && $xml->{'at24-7'}->weight != '') {
$at247->setWeight(
(int) $xml->{'at24-7'}->weight
);

if (!isset($xml->{'at24-7'})) {
throw new BpostXmlInvalidItemException();
}
if (isset($xml->{'at24-7'}->memberId) && $xml->{'at24-7'}->memberId != '') {
$at247->setMemberId(
(string) $xml->{'at24-7'}->memberId

$at247Xml = $xml->{'at24-7'}[0];

/** @var static $self */
$self = parent::createFromXML($at247Xml, $self);

if (!empty($at247Xml->memberId)) {
$self->setMemberId(
(string) $at247Xml->memberId
);
}
if (isset($xml->{'at24-7'}->receiverName) && $xml->{'at24-7'}->receiverName != '') {
$at247->setReceiverName(
(string) $xml->{'at24-7'}->receiverName
if (!empty($at247Xml->receiverName)) {
$self->setReceiverName(
(string) $at247Xml->receiverName
);
}
if (isset($xml->{'at24-7'}->receiverCompany) && $xml->{'at24-7'}->receiverCompany != '') {
$at247->setReceiverCompany(
(string) $xml->{'at24-7'}->receiverCompany
if (!empty($at247Xml->receiverCompany)) {
$self->setReceiverCompany(
(string) $at247Xml->receiverCompany
);
}
if (isset($xml->{'at24-7'}->parcelsDepotId) && $xml->{'at24-7'}->parcelsDepotId != '') {
$at247->setParcelsDepotId(
(string) $xml->{'at24-7'}->parcelsDepotId
if (!empty($at247Xml->parcelsDepotId)) {
$self->setParcelsDepotId(
(string) $at247Xml->parcelsDepotId
);
}
if (isset($xml->{'at24-7'}->parcelsDepotName) && $xml->{'at24-7'}->parcelsDepotName != '') {
$at247->setParcelsDepotName(
(string) $xml->{'at24-7'}->parcelsDepotName
if (!empty($at247Xml->parcelsDepotName)) {
$self->setParcelsDepotName(
(string) $at247Xml->parcelsDepotName
);
}
if (isset($xml->{'at24-7'}->parcelsDepotAddress)) {
if (isset($at247Xml->parcelsDepotAddress)) {
/** @var SimpleXMLElement $parcelsDepotAddressData */
$parcelsDepotAddressData = $xml->{'at24-7'}->parcelsDepotAddress->children(Bpost::NS_V3_COMMON);
$at247->setParcelsDepotAddress(
$parcelsDepotAddressData = $at247Xml->parcelsDepotAddress->children(Bpost::NS_V3_COMMON);
$self->setParcelsDepotAddress(
ParcelsDepotAddress::createFromXML($parcelsDepotAddressData)
);
}
if (isset($xml->{'at24-7'}->requestedDeliveryDate) && $xml->{'at24-7'}->requestedDeliveryDate != '') {
$at247->setRequestedDeliveryDate(
(string) $xml->{'at24-7'}->requestedDeliveryDate
if (!empty($at247Xml->requestedDeliveryDate)) {
$self->setRequestedDeliveryDate(
(string) $at247Xml->requestedDeliveryDate
);
}

return $at247;
return $self;
}
}
77 changes: 27 additions & 50 deletions src/Bpost/Order/Box/AtBpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Bpost\BpostApiClient\Common\XmlHelper;
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException;
use Bpost\BpostApiClient\Exception\BpostNotImplementedException;
use Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException;
use DOMDocument;
use DOMElement;
use SimpleXMLElement;
Expand Down Expand Up @@ -272,81 +273,57 @@ private function addToXmlShopHandlingInstruction(DOMDocument $document, DOMEleme
*/
public static function createFromXML(SimpleXMLElement $xml, National $self = null)
{
$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(Bpost::NS_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 {
$option = self::getOptionFromOptionData($optionData);
}

$atBpost->addOption($option);
}
if ($self === null) {
$self = new self();
}
if (isset($xml->atBpost->weight) && $xml->atBpost->weight != '') {
$atBpost->setWeight(
(int) $xml->atBpost->weight
);

if (!isset($xml->atBpost)) {
throw new BpostXmlInvalidItemException();
}
if (isset($xml->atBpost->receiverName) && $xml->atBpost->receiverName != '') {
$atBpost->setReceiverName(

$atBpostXml = $xml->atBpost[0];

/** @var static $self */
$self = parent::createFromXML($atBpostXml, $self);

if (!empty($atBpostXml->receiverName)) {
$self->setReceiverName(
(string) $xml->atBpost->receiverName
);
}
if (isset($xml->atBpost->receiverCompany) && $xml->atBpost->receiverCompany != '') {
$atBpost->setReceiverCompany(
if (!empty($atBpostXml->receiverCompany)) {
$self->setReceiverCompany(
(string) $xml->atBpost->receiverCompany
);
}
if (isset($xml->atBpost->pugoId) && $xml->atBpost->pugoId != '') {
$atBpost->setPugoId(
if (!empty($atBpostXml->pugoId)) {
$self->setPugoId(
(string) $xml->atBpost->pugoId
);
}
if (isset($xml->atBpost->pugoName) && $xml->atBpost->pugoName != '') {
$atBpost->setPugoName(
if (!empty($atBpostXml->pugoName)) {
$self->setPugoName(
(string) $xml->atBpost->pugoName
);
}
if (isset($xml->atBpost->pugoAddress)) {
/** @var SimpleXMLElement $pugoAddressData */
$pugoAddressData = $xml->atBpost->pugoAddress->children(
Bpost::NS_V3_COMMON
);
$atBpost->setPugoAddress(
$pugoAddressData = $atBpostXml->pugoAddress->children(Bpost::NS_V3_COMMON);
$self->setPugoAddress(
PugoAddress::createFromXML($pugoAddressData)
);
}
if (isset($xml->atBpost->requestedDeliveryDate) && $xml->atBpost->requestedDeliveryDate != '') {
$atBpost->setRequestedDeliveryDate(
if (!empty($atBpostXml->requestedDeliveryDate)) {
$self->setRequestedDeliveryDate(
(string) $xml->atBpost->requestedDeliveryDate
);
}
if (isset($xml->atBpost->shopHandlingInstruction) && $xml->atBpost->shopHandlingInstruction != '') {
$atBpost->setShopHandlingInstruction(
if (!empty($atBpostXml->shopHandlingInstruction)) {
$self->setShopHandlingInstruction(
(string) $xml->atBpost->shopHandlingInstruction
);
}

return $atBpost;
return $self;
}
}
52 changes: 28 additions & 24 deletions src/Bpost/Order/Box/National.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

use Bpost\BpostApiClient\Bpost;
use Bpost\BpostApiClient\Bpost\Order\Box\OpeningHour\Day;
use Bpost\BpostApiClient\Bpost\Order\Box\Option\CashOnDelivery;
use Bpost\BpostApiClient\Bpost\Order\Box\Option\Messaging;
use Bpost\BpostApiClient\Bpost\Order\Box\Option\Option;
use Bpost\BpostApiClient\BpostException;
use Bpost\BpostApiClient\Common\ComplexAttribute;
use Bpost\BpostApiClient\Common\XmlHelper;
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException;
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException;
use Bpost\BpostApiClient\Exception\BpostNotImplementedException;
use Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException;
use DomDocument;
Expand Down Expand Up @@ -215,7 +218,7 @@ public function toXML(DOMDocument $document, $prefix = null, $type = null)
* @param SimpleXMLElement $nationalXml
* @param National $self
*
* @return AtHome
* @return National
*
* @throws BpostException
* @throws BpostXmlInvalidItemException
Expand All @@ -232,24 +235,10 @@ public static function createFromXML(SimpleXMLElement $nationalXml, National $se
);
}

if (isset($nationalXml->options) && !empty($nationalXml->options)) {
if (!empty($nationalXml->options)) {
/** @var SimpleXMLElement $optionData */
foreach ($nationalXml->options as $optionData) {
$optionData = $optionData->children(Bpost::NS_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 {
$option = self::getOptionFromOptionData($optionData);
}

$self->addOption($option);
foreach ($nationalXml->options->children(Bpost::NS_V3_COMMON) as $optionData) {
$self->addOption(self::getOptionFromOptionData($optionData));
}
}

Expand Down Expand Up @@ -280,15 +269,30 @@ public static function createFromXML(SimpleXMLElement $nationalXml, National $se
* @return Option
*
* @throws BpostNotImplementedException
* @throws BpostInvalidLengthException
* @throws BpostInvalidValueException
*/
protected static function getOptionFromOptionData(SimpleXMLElement $optionData)
{
$className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\Option\\' . ucfirst($optionData->getName());
XmlHelper::assertMethodCreateFromXmlExists($className);
switch ($optionData->getName()) {
case Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED:
case Messaging::MESSAGING_TYPE_INFO_NEXT_DAY:
case Messaging::MESSAGING_TYPE_INFO_REMINDER:
case Messaging::MESSAGING_TYPE_KEEP_ME_INFORMED:
return Messaging::createFromXML($optionData);

return call_user_func(
array($className, 'createFromXML'),
$optionData
);
case 'cod':
return CashOnDelivery::createFromXML($optionData);

default:
$className = '\\Bpost\\BpostApiClient\\Bpost\\Order\\Box\\Option\\' . ucfirst($optionData->getName());

XmlHelper::assertMethodCreateFromXmlExists($className);

return call_user_func(
array($className, 'createFromXML'),
$optionData
);
}
}
}
10 changes: 0 additions & 10 deletions src/Bpost/Order/Box/Option/AutomaticSecondPresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,4 @@ public function toXML(DOMDocument $document, $prefix = 'common')
{
return $document->createElement(XmlHelper::getPrefixedTagName('automaticSecondPresentation', $prefix));
}

/**
* @param SimpleXMLElement $xml
*
* @return static
*/
public static function createFromXML(SimpleXMLElement $xml)
{
return new static();
}
}
19 changes: 19 additions & 0 deletions src/Bpost/Order/Box/Option/CashOnDelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace Bpost\BpostApiClient\Bpost\Order\Box\Option;

use Bpost\BpostApiClient\Bpost;
use Bpost\BpostApiClient\Common\XmlHelper;
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException;
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException;
use DomDocument;
use DomElement;
use SimpleXMLElement;

/**
* bPost CashOnDelivery class
Expand Down Expand Up @@ -132,4 +136,19 @@ public function toXML(DOMDocument $document, $prefix = 'common')

return $cod;
}

/**
* @param SimpleXMLElement $xml
*
* @return static
*
* @throws BpostInvalidLengthException
* @throws BpostInvalidValueException
*/
public static function createFromXML(SimpleXMLElement $xml)
{
$details = $xml->children(Bpost::NS_V3_COMMON);

return new static(floatval($details->codAmount), (string) $details->iban, (string) $details->bic);
}
}
5 changes: 2 additions & 3 deletions src/Bpost/Order/Box/Option/Insured.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@ public function toXML(DOMDocument $document, $prefix = 'common')
*/
public static function createFromXML(SimpleXMLElement $xml)
{
$insuranceDetail = $xml->children('common', true);

$insuranceDetail = $xml->children(Bpost::NS_V3_COMMON);
$type = $insuranceDetail->getName();
$value = $insuranceDetail->attributes()->value !== null ? (int) $insuranceDetail->attributes()->value : null;
$value = intval($insuranceDetail->attributes()->value) ?: null;

if ($type === static::INSURANCE_TYPE_ADDITIONAL_INSURANCE && $value === 1) {
$type = static::INSURANCE_TYPE_BASIC_INSURANCE;
Expand Down
Loading
Loading