1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bpost\BpostApiClient\Bpost\Order\Box; |
4
|
|
|
|
5
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Box\National\ShopHandlingInstruction; |
6
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Box\Option\Messaging; |
7
|
|
|
use Bpost\BpostApiClient\Bpost\Order\PugoAddress; |
8
|
|
|
use Bpost\BpostApiClient\Bpost\ProductConfiguration\Product; |
9
|
|
|
use Bpost\BpostApiClient\Common\XmlHelper; |
10
|
|
|
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException; |
11
|
|
|
use Bpost\BpostApiClient\Exception\BpostNotImplementedException; |
12
|
|
|
use DOMDocument; |
13
|
|
|
use DOMElement; |
14
|
|
|
use SimpleXMLElement; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* bPost AtBpost class |
18
|
|
|
* |
19
|
|
|
* @author Tijs Verkoyen <[email protected]> |
20
|
|
|
* |
21
|
|
|
* @version 3.0.0 |
22
|
|
|
* |
23
|
|
|
* @copyright Copyright (c), Tijs Verkoyen. All rights reserved. |
24
|
|
|
* @license BSD License |
25
|
|
|
*/ |
26
|
|
|
class AtBpost extends National |
27
|
|
|
{ |
28
|
|
|
/** @var string */ |
29
|
|
|
protected $product = Product::PRODUCT_NAME_BPACK_AT_BPOST; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
private $pugoId; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
private $pugoName; |
36
|
|
|
|
37
|
|
|
/** @var \Bpost\BpostApiClient\Bpost\Order\PugoAddress */ |
38
|
|
|
private $pugoAddress; |
39
|
|
|
|
40
|
|
|
/** @var string */ |
41
|
|
|
private $receiverName; |
42
|
|
|
|
43
|
|
|
/** @var string */ |
44
|
|
|
private $receiverCompany; |
45
|
|
|
|
46
|
|
|
/** @var string */ |
47
|
|
|
protected $requestedDeliveryDate; |
48
|
|
|
|
49
|
|
|
/** @var ShopHandlingInstruction */ |
50
|
|
|
private $shopHandlingInstruction; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $product Possible values are: bpack@bpost |
54
|
|
|
* |
55
|
|
|
* @throws BpostInvalidValueException |
56
|
|
|
*/ |
57
|
|
|
public function setProduct($product) |
58
|
|
|
{ |
59
|
|
|
if (!in_array($product, self::getPossibleProductValues())) { |
60
|
|
|
throw new BpostInvalidValueException('product', $product, self::getPossibleProductValues()); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
parent::setProduct($product); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
public static function getPossibleProductValues() |
70
|
|
|
{ |
71
|
|
|
return array( |
72
|
|
|
Product::PRODUCT_NAME_BPACK_AT_BPOST, |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @param \Bpost\BpostApiClient\Bpost\Order\PugoAddress $pugoAddress |
78
|
|
|
*/ |
79
|
|
|
public function setPugoAddress($pugoAddress) |
80
|
|
|
{ |
81
|
|
|
$this->pugoAddress = $pugoAddress; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return \Bpost\BpostApiClient\Bpost\Order\PugoAddress |
86
|
|
|
*/ |
87
|
|
|
public function getPugoAddress() |
88
|
|
|
{ |
89
|
|
|
return $this->pugoAddress; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $pugoId |
94
|
|
|
*/ |
95
|
|
|
public function setPugoId($pugoId) |
96
|
|
|
{ |
97
|
|
|
$this->pugoId = $pugoId; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getPugoId() |
104
|
|
|
{ |
105
|
|
|
return $this->pugoId; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param string $pugoName |
110
|
|
|
*/ |
111
|
|
|
public function setPugoName($pugoName) |
112
|
|
|
{ |
113
|
|
|
$this->pugoName = $pugoName; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function getPugoName() |
120
|
|
|
{ |
121
|
|
|
return $this->pugoName; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @param string $receiverCompany |
126
|
|
|
*/ |
127
|
|
|
public function setReceiverCompany($receiverCompany) |
128
|
|
|
{ |
129
|
|
|
$this->receiverCompany = $receiverCompany; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getReceiverCompany() |
136
|
|
|
{ |
137
|
|
|
return $this->receiverCompany; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param string $receiverName |
142
|
|
|
*/ |
143
|
|
|
public function setReceiverName($receiverName) |
144
|
|
|
{ |
145
|
|
|
$this->receiverName = $receiverName; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @return string |
150
|
|
|
*/ |
151
|
|
|
public function getReceiverName() |
152
|
|
|
{ |
153
|
|
|
return $this->receiverName; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @return string |
158
|
|
|
*/ |
159
|
|
|
public function getRequestedDeliveryDate() |
160
|
|
|
{ |
161
|
|
|
return $this->requestedDeliveryDate; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param string $requestedDeliveryDate |
166
|
|
|
*/ |
167
|
|
|
public function setRequestedDeliveryDate($requestedDeliveryDate) |
168
|
|
|
{ |
169
|
|
|
$this->requestedDeliveryDate = $requestedDeliveryDate; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
|
|
public function getShopHandlingInstruction() |
176
|
|
|
{ |
177
|
|
|
if ($this->shopHandlingInstruction !== null) { |
178
|
|
|
return $this->shopHandlingInstruction->getValue(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return null; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @param string $shopHandlingInstruction |
186
|
|
|
*/ |
187
|
|
|
public function setShopHandlingInstruction($shopHandlingInstruction) |
188
|
|
|
{ |
189
|
|
|
$this->shopHandlingInstruction = new ShopHandlingInstruction($shopHandlingInstruction); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Return the object as an array for usage in the XML |
194
|
|
|
* |
195
|
|
|
* @param DomDocument $document |
196
|
|
|
* @param string $prefix |
197
|
|
|
* @param string $type |
198
|
|
|
* |
199
|
|
|
* @return DomElement |
200
|
|
|
*/ |
201
|
|
|
public function toXML(DOMDocument $document, $prefix = null, $type = null) |
202
|
|
|
{ |
203
|
|
|
$nationalElement = $document->createElement(XmlHelper::getPrefixedTagName('nationalBox', $prefix)); |
204
|
|
|
$boxElement = parent::toXML($document, null, 'atBpost'); |
205
|
|
|
$nationalElement->appendChild($boxElement); |
206
|
|
|
|
207
|
|
|
if ($this->getPugoId() !== null) { |
|
|
|
|
208
|
|
|
$boxElement->appendChild( |
209
|
|
|
$document->createElement('pugoId', $this->getPugoId()) |
210
|
|
|
); |
211
|
|
|
} |
212
|
|
|
if ($this->getPugoName() !== null) { |
|
|
|
|
213
|
|
|
$boxElement->appendChild( |
214
|
|
|
$document->createElement('pugoName', $this->getPugoName()) |
215
|
|
|
); |
216
|
|
|
} |
217
|
|
|
if ($this->getPugoAddress() !== null) { |
218
|
|
|
$boxElement->appendChild( |
219
|
|
|
$this->getPugoAddress()->toXML($document, 'common') |
220
|
|
|
); |
221
|
|
|
} |
222
|
|
|
if ($this->getReceiverName() !== null) { |
|
|
|
|
223
|
|
|
$boxElement->appendChild( |
224
|
|
|
$document->createElement('receiverName', $this->getReceiverName()) |
225
|
|
|
); |
226
|
|
|
} |
227
|
|
|
if ($this->getReceiverCompany() !== null) { |
|
|
|
|
228
|
|
|
$boxElement->appendChild( |
229
|
|
|
$document->createElement('receiverCompany', $this->getReceiverCompany()) |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
$this->addToXmlRequestedDeliveryDate($document, $boxElement, $prefix); |
233
|
|
|
$this->addToXmlShopHandlingInstruction($document, $boxElement, $prefix); |
234
|
|
|
|
235
|
|
|
return $nationalElement; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param DOMDocument $document |
240
|
|
|
* @param DOMElement $typeElement |
241
|
|
|
* @param string $prefix |
242
|
|
|
*/ |
243
|
|
|
protected function addToXmlRequestedDeliveryDate(DOMDocument $document, DOMElement $typeElement, $prefix) |
|
|
|
|
244
|
|
|
{ |
245
|
|
|
if ($this->getRequestedDeliveryDate() !== null) { |
|
|
|
|
246
|
|
|
$typeElement->appendChild( |
247
|
|
|
$document->createElement('requestedDeliveryDate', $this->getRequestedDeliveryDate()) |
248
|
|
|
); |
249
|
|
|
} |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
private function addToXmlShopHandlingInstruction(DOMDocument $document, DOMElement $typeElement, $prefix) |
|
|
|
|
253
|
|
|
{ |
254
|
|
|
if ($this->getShopHandlingInstruction() !== null) { |
|
|
|
|
255
|
|
|
$typeElement->appendChild( |
256
|
|
|
$document->createElement('shopHandlingInstruction', $this->getShopHandlingInstruction()) |
257
|
|
|
); |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @param SimpleXMLElement $xml |
263
|
|
|
* @param National|null $self |
264
|
|
|
* |
265
|
|
|
* @return AtBpost |
266
|
|
|
* |
267
|
|
|
* @throws BpostInvalidValueException |
268
|
|
|
* @throws BpostNotImplementedException |
269
|
|
|
* @throws \Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException |
270
|
|
|
* @throws \Bpost\BpostApiClient\Exception\XmlException\BpostXmlInvalidItemException |
271
|
|
|
*/ |
272
|
|
|
public static function createFromXML(SimpleXMLElement $xml, National $self = null) |
273
|
|
|
{ |
274
|
|
|
$atBpost = new AtBpost(); |
275
|
|
|
|
276
|
|
|
if (isset($xml->atBpost->product) && $xml->atBpost->product != '') { |
277
|
|
|
$atBpost->setProduct( |
278
|
|
|
(string) $xml->atBpost->product |
279
|
|
|
); |
280
|
|
|
} |
281
|
|
|
if (isset($xml->atBpost->options)) { |
282
|
|
|
/** @var SimpleXMLElement $optionData */ |
283
|
|
|
foreach ($xml->atBpost->options as $optionData) { |
284
|
|
|
$optionData = $optionData->children('http://schema.post.be/shm/deepintegration/v3/common'); |
|
|
|
|
285
|
|
|
|
286
|
|
|
if (in_array( |
287
|
|
|
$optionData->getName(), |
288
|
|
|
array( |
289
|
|
|
Messaging::MESSAGING_TYPE_INFO_DISTRIBUTED, |
290
|
|
|
Messaging::MESSAGING_TYPE_INFO_NEXT_DAY, |
291
|
|
|
Messaging::MESSAGING_TYPE_INFO_REMINDER, |
292
|
|
|
Messaging::MESSAGING_TYPE_KEEP_ME_INFORMED, |
293
|
|
|
) |
294
|
|
|
) |
295
|
|
|
) { |
296
|
|
|
$option = Messaging::createFromXML($optionData); |
297
|
|
|
} else { |
298
|
|
|
$option = self::getOptionFromOptionData($optionData); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
$atBpost->addOption($option); |
302
|
|
|
} |
303
|
|
|
} |
304
|
|
|
if (isset($xml->atBpost->weight) && $xml->atBpost->weight != '') { |
305
|
|
|
$atBpost->setWeight( |
306
|
|
|
(int) $xml->atBpost->weight |
307
|
|
|
); |
308
|
|
|
} |
309
|
|
|
if (isset($xml->atBpost->receiverName) && $xml->atBpost->receiverName != '') { |
310
|
|
|
$atBpost->setReceiverName( |
311
|
|
|
(string) $xml->atBpost->receiverName |
312
|
|
|
); |
313
|
|
|
} |
314
|
|
|
if (isset($xml->atBpost->receiverCompany) && $xml->atBpost->receiverCompany != '') { |
315
|
|
|
$atBpost->setReceiverCompany( |
316
|
|
|
(string) $xml->atBpost->receiverCompany |
317
|
|
|
); |
318
|
|
|
} |
319
|
|
|
if (isset($xml->atBpost->pugoId) && $xml->atBpost->pugoId != '') { |
320
|
|
|
$atBpost->setPugoId( |
321
|
|
|
(string) $xml->atBpost->pugoId |
322
|
|
|
); |
323
|
|
|
} |
324
|
|
|
if (isset($xml->atBpost->pugoName) && $xml->atBpost->pugoName != '') { |
325
|
|
|
$atBpost->setPugoName( |
326
|
|
|
(string) $xml->atBpost->pugoName |
327
|
|
|
); |
328
|
|
|
} |
329
|
|
|
if (isset($xml->atBpost->pugoAddress)) { |
330
|
|
|
/** @var SimpleXMLElement $pugoAddressData */ |
331
|
|
|
$pugoAddressData = $xml->atBpost->pugoAddress->children( |
332
|
|
|
'http://schema.post.be/shm/deepintegration/v3/common' |
333
|
|
|
); |
334
|
|
|
$atBpost->setPugoAddress( |
335
|
|
|
PugoAddress::createFromXML($pugoAddressData) |
336
|
|
|
); |
337
|
|
|
} |
338
|
|
|
if (isset($xml->atBpost->requestedDeliveryDate) && $xml->atBpost->requestedDeliveryDate != '') { |
339
|
|
|
$atBpost->setRequestedDeliveryDate( |
340
|
|
|
(string) $xml->atBpost->requestedDeliveryDate |
341
|
|
|
); |
342
|
|
|
} |
343
|
|
|
if (isset($xml->atBpost->shopHandlingInstruction) && $xml->atBpost->shopHandlingInstruction != '') { |
344
|
|
|
$atBpost->setShopHandlingInstruction( |
345
|
|
|
(string) $xml->atBpost->shopHandlingInstruction |
346
|
|
|
); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
return $atBpost; |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
|