|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bpost\BpostApiClient\Bpost; |
|
4
|
|
|
|
|
5
|
|
|
use Bpost\BpostApiClient\Common\ValidatedValue\LabelFormat; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class CreateLabelInBulkForOrders |
|
9
|
|
|
*/ |
|
10
|
|
|
class CreateLabelInBulkForOrders |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @param string[] $references |
|
14
|
|
|
* @return string |
|
15
|
|
|
*/ |
|
16
|
1 |
|
public function getXml(array $references) |
|
17
|
|
|
{ |
|
18
|
1 |
|
$document = new \DOMDocument('1.0', 'UTF-8'); |
|
19
|
1 |
|
$document->preserveWhiteSpace = false; |
|
20
|
1 |
|
$document->formatOutput = true; |
|
21
|
|
|
|
|
22
|
1 |
|
$batchLabels = $document->createElement('batchLabels'); |
|
23
|
1 |
|
$batchLabels->setAttribute('xmlns', 'http://schema.post.be/shm/deepintegration/v3/'); |
|
24
|
1 |
|
foreach ($references as $reference) { |
|
25
|
1 |
|
$batchLabels->appendChild( |
|
26
|
1 |
|
$document->createElement('order', $reference) |
|
27
|
1 |
|
); |
|
28
|
1 |
|
} |
|
29
|
1 |
|
$document->appendChild($batchLabels); |
|
30
|
|
|
|
|
31
|
1 |
|
return $document->saveXML(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param bool $asPdf |
|
36
|
|
|
* @return string[] |
|
37
|
|
|
*/ |
|
38
|
1 |
|
public function getHeaders($asPdf) |
|
39
|
|
|
{ |
|
40
|
|
|
return array( |
|
41
|
1 |
|
'Accept: application/vnd.bpost.shm-label-' . ($asPdf ? 'pdf' : 'image') . '-v3+XML', |
|
42
|
1 |
|
'Content-Type: application/vnd.bpost.shm-labelRequest-v3+XML', |
|
43
|
1 |
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param LabelFormat $format |
|
48
|
|
|
* @param bool $withReturnLabels |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
1 |
|
public function getUrl(LabelFormat $format, $withReturnLabels, $forcePrinting = false) |
|
52
|
|
|
{ |
|
53
|
1 |
|
return '/labels/' . $format->getValue() |
|
54
|
|
|
. ($withReturnLabels ? '/withReturnLabels' : '') |
|
55
|
|
|
. ($forcePrinting ? '?forcePrinting=true' : ''); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|