1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Bpost\BpostApiClient\Bpost\Order\Box\International; |
5
|
|
|
|
6
|
|
|
use Bpost\BpostApiClient\Common\XmlHelper; |
7
|
|
|
use DOMDocument; |
8
|
|
|
use DOMElement; |
9
|
|
|
use DOMException; |
10
|
|
|
use SimpleXMLElement; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* bpost ParcelContent for international shipment. |
14
|
|
|
*/ |
15
|
|
|
class ParcelContent |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* Number of items of each type for the specified parcel content. |
19
|
|
|
*/ |
20
|
|
|
private ?int $numberOfItemType = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Value for the number of items and NOT per item |
24
|
|
|
* Max length = 50 |
25
|
|
|
* Integer format in cents, for example for 10€, you must sent 1000, NO decimal. |
26
|
|
|
*/ |
27
|
|
|
private ?int $valueOfItem = null; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* description of parcel content |
31
|
|
|
* Max length = 30 characters. |
32
|
|
|
*/ |
33
|
|
|
private ?string $itemDescription = null; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
/** |
37
|
|
|
* Weight for the number of items of each type and NOT per item. |
38
|
|
|
* Integer format, NO decimal ! In gramme (gr). |
39
|
|
|
* Range 1-30000. |
40
|
|
|
*/ |
41
|
|
|
private ?int $nettoWeight = null; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* HS stands for Harmonized System. |
45
|
|
|
* It’s a multipurpose international product nomenclature that describes the type of good that is shipped. |
46
|
|
|
* Today, customs officers must use HS code to clear every commodity that enters or crosses any international borders. |
47
|
|
|
* Integer format, maximum 9 digits |
48
|
|
|
* you can find the code on https://www.tariffnumber.com/. |
49
|
|
|
*/ |
50
|
|
|
private ?string $hsTariffCode = null; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* 2 letters country code from the orign of goods |
54
|
|
|
* you can find the code on https://countrycode.org/. |
55
|
|
|
*/ |
56
|
|
|
private ?string $originOfGoods = null; |
57
|
|
|
|
58
|
|
|
public function getNumberOfItemType(): ?int |
59
|
|
|
{ |
60
|
|
|
return $this->numberOfItemType; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function setNumberOfItemType(?int $numberOfItemType): void |
64
|
|
|
{ |
65
|
|
|
$this->numberOfItemType = $numberOfItemType; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function getValueOfItem(): ?int |
69
|
|
|
{ |
70
|
|
|
return $this->valueOfItem; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function setValueOfItem(?int $valueOfItem): void |
74
|
|
|
{ |
75
|
|
|
$this->valueOfItem = $valueOfItem; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getItemDescription(): ?string |
79
|
|
|
{ |
80
|
|
|
return $this->itemDescription; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function setItemDescription(?string $itemDescription): void |
84
|
|
|
{ |
85
|
|
|
$itemDescription = (string) $itemDescription; |
86
|
|
|
if (strlen($itemDescription) > 30) { |
87
|
|
|
$itemDescription = substr($itemDescription, 0, 30); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$this->itemDescription = $itemDescription; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function getNettoWeight(): ?int |
94
|
|
|
{ |
95
|
|
|
return $this->nettoWeight; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function setNettoWeight(?int $nettoWeight): void |
99
|
|
|
{ |
100
|
|
|
$this->nettoWeight = $nettoWeight; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getHsTariffCode(): ?string |
104
|
|
|
{ |
105
|
|
|
return $this->hsTariffCode; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function setHsTariffCode(?string $hsTariffCode): void |
109
|
|
|
{ |
110
|
|
|
$this->hsTariffCode = $hsTariffCode; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getOriginOfGoods(): ?string |
114
|
|
|
{ |
115
|
|
|
return $this->originOfGoods; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function setOriginOfGoods(?string $originOfGoods): void |
119
|
|
|
{ |
120
|
|
|
$this->originOfGoods = $originOfGoods; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @throws DOMException |
125
|
|
|
*/ |
126
|
|
|
public function toXML(DOMDocument $document, ?string $prefix = null): DOMElement |
127
|
|
|
{ |
128
|
|
|
$parcelContent = $document->createElement(XmlHelper::getPrefixedTagName('parcelContent', $prefix)); |
129
|
|
|
|
130
|
|
|
$parcelContent->appendChild( |
131
|
|
|
$document->createElement( |
132
|
|
|
XmlHelper::getPrefixedTagName('numberOfItemType', $prefix), |
133
|
|
|
(string) $this->getNumberOfItemType() |
134
|
|
|
) |
135
|
|
|
); |
136
|
|
|
$parcelContent->appendChild( |
137
|
|
|
$document->createElement( |
138
|
|
|
XmlHelper::getPrefixedTagName('valueOfItem', $prefix), |
139
|
|
|
(string) $this->getValueOfItem() |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
$parcelContent->appendChild( |
143
|
|
|
$document->createElement( |
144
|
|
|
XmlHelper::getPrefixedTagName('itemDescription', $prefix), |
145
|
|
|
(string) $this->getItemDescription() |
146
|
|
|
) |
147
|
|
|
); |
148
|
|
|
$parcelContent->appendChild( |
149
|
|
|
$document->createElement( |
150
|
|
|
XmlHelper::getPrefixedTagName('nettoWeight', $prefix), |
151
|
|
|
(string) $this->getNettoWeight() |
152
|
|
|
) |
153
|
|
|
); |
154
|
|
|
$parcelContent->appendChild( |
155
|
|
|
$document->createElement( |
156
|
|
|
XmlHelper::getPrefixedTagName('hsTariffCode', $prefix), |
157
|
|
|
(string) $this->getHsTariffCode() |
158
|
|
|
) |
159
|
|
|
); |
160
|
|
|
$parcelContent->appendChild( |
161
|
|
|
$document->createElement( |
162
|
|
|
XmlHelper::getPrefixedTagName('originOfGoods', $prefix), |
163
|
|
|
(string) $this->getOriginOfGoods() |
164
|
|
|
) |
165
|
|
|
); |
166
|
|
|
|
167
|
|
|
return $parcelContent; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public static function createFromXML(SimpleXMLElement $xml): self |
171
|
|
|
{ |
172
|
|
|
$parcelContent = new self(); |
173
|
|
|
|
174
|
|
|
if (isset($xml->numberOfItemType) && (string)$xml->numberOfItemType !== '') { |
175
|
|
|
$parcelContent->setNumberOfItemType((int)$xml->numberOfItemType); |
176
|
|
|
} |
177
|
|
|
if (isset($xml->valueOfItem) && (string)$xml->valueOfItem !== '') { |
178
|
|
|
// XML porte des cents → int |
179
|
|
|
$parcelContent->setValueOfItem((int)$xml->valueOfItem); |
180
|
|
|
} |
181
|
|
|
if (isset($xml->itemDescription) && (string)$xml->itemDescription !== '') { |
182
|
|
|
$parcelContent->setItemDescription((string)$xml->itemDescription); |
183
|
|
|
} |
184
|
|
|
if (isset($xml->nettoWeight) && (string)$xml->nettoWeight !== '') { |
185
|
|
|
$parcelContent->setNettoWeight((int)$xml->nettoWeight); |
186
|
|
|
} |
187
|
|
|
if (isset($xml->hsTariffCode) && (string)$xml->hsTariffCode !== '') { |
188
|
|
|
// FIX: garder en string (pas (int)) |
189
|
|
|
$parcelContent->setHsTariffCode((string)$xml->hsTariffCode); |
190
|
|
|
} |
191
|
|
|
if (isset($xml->originOfGoods) && (string)$xml->originOfGoods !== '') { |
192
|
|
|
$parcelContent->setOriginOfGoods((string)$xml->originOfGoods); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
return $parcelContent; |
196
|
|
|
} |
197
|
|
|
} |