1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Bpost\BpostApiClient\Bpost\HttpRequestBuilder; |
5
|
|
|
|
6
|
|
|
use Bpost\BpostApiClient\Bpost\Order\Box; |
7
|
|
|
use Bpost\BpostApiClient\Common\ApiVersions; |
8
|
|
|
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException; |
9
|
|
|
use DOMDocument; |
10
|
|
|
|
11
|
|
|
class ModifyOrder implements HttpRequestBuilderInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @throws BpostInvalidValueException |
15
|
|
|
*/ |
16
|
|
|
public function __construct( |
17
|
|
|
private readonly string $reference, |
18
|
|
|
string $status |
19
|
|
|
) { |
20
|
|
|
$normalized = strtoupper($status); |
21
|
|
|
if (!in_array($normalized, Box::getPossibleStatusValues(), true)) { |
22
|
|
|
throw new BpostInvalidValueException('status', $normalized, Box::getPossibleStatusValues()); |
23
|
|
|
} |
24
|
|
|
$this->status = $normalized; |
25
|
|
|
} |
26
|
|
|
private string $status; |
27
|
|
|
|
28
|
|
|
public function getXml(): string |
29
|
|
|
{ |
30
|
|
|
$document = new DOMDocument('1.0', 'UTF-8'); |
31
|
|
|
$document->preserveWhiteSpace = false; |
32
|
|
|
$document->formatOutput = true; |
33
|
|
|
|
34
|
|
|
$orderUpdate = $document->createElement('orderUpdate'); |
35
|
|
|
$orderUpdate->setAttribute('xmlns', 'http://schema.post.be/shm/deepintegration/v3/'); |
36
|
|
|
$orderUpdate->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); |
37
|
|
|
$orderUpdate->appendChild($document->createElement('status', $this->status)); |
38
|
|
|
|
39
|
|
|
$document->appendChild($orderUpdate); |
40
|
|
|
|
41
|
|
|
return $document->saveXML() ?: ''; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
public function getHeaders(): array |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
'Content-Type: application/vnd.bpost.shm-orderUpdate-' . ApiVersions::V3 . '+XML', |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getUrl(): string |
53
|
|
|
{ |
54
|
|
|
return '/orders/' . $this->reference; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function isExpectXml(): bool |
58
|
|
|
{ |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function getMethod(): string |
63
|
|
|
{ |
64
|
|
|
return self::METHOD_POST; |
65
|
|
|
} |
66
|
|
|
} |