1 | <?php |
||
6 | class OrderLine extends Payload implements OrderLineInterface |
||
7 | { |
||
8 | const GOODS_TYPE_SHIPMENT = 'shipment'; |
||
9 | const GOODS_TYPE_HANDLING = 'handling'; |
||
10 | const GOODS_TYPE_ITEM = 'item'; |
||
11 | const GOODS_TYPE_REFUND = 'refund'; |
||
12 | |||
13 | /** |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $description; |
||
17 | |||
18 | /** |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $itemId; |
||
22 | |||
23 | /** |
||
24 | * @var float |
||
25 | */ |
||
26 | protected $quantity; |
||
27 | |||
28 | /** |
||
29 | * @var float |
||
30 | */ |
||
31 | protected $unitPrice; |
||
32 | |||
33 | /** |
||
34 | * @var float |
||
35 | */ |
||
36 | protected $taxPercent; |
||
37 | |||
38 | /** |
||
39 | * @var float |
||
40 | */ |
||
41 | protected $taxAmount; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $unitCode; |
||
47 | |||
48 | /** |
||
49 | * @var float |
||
50 | */ |
||
51 | protected $discount; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $goodsType; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | 3 | protected $imageUrl; |
|
62 | |||
63 | public function __construct(string $description, string $itemId, float $quantity, float $unitPrice) |
||
64 | { |
||
65 | $this->description = $description; |
||
66 | $this->itemId = $itemId; |
||
67 | $this->quantity = $quantity; |
||
68 | $this->unitPrice = $unitPrice; |
||
69 | } |
||
70 | |||
71 | public function getPayload() : array |
||
72 | { |
||
73 | $payload = [ |
||
74 | 3 | 'description' => $this->description, |
|
75 | 3 | 'itemId' => $this->itemId, |
|
76 | 3 | 'quantity' => $this->quantity, |
|
77 | 3 | 'unitPrice' => $this->unitPrice, |
|
78 | 3 | 'taxPercent' => $this->taxPercent, |
|
79 | 3 | 'taxAmount' => $this->taxAmount, |
|
80 | 3 | 'unitCode' => $this->unitCode, |
|
81 | 3 | 'discount' => $this->discount, |
|
82 | 3 | 'goodsType' => $this->goodsType, |
|
83 | 3 | 'imageUrl' => $this->imageUrl, |
|
84 | 3 | ]; |
|
85 | |||
86 | 3 | $this->validate(); |
|
87 | |||
88 | return static::simplePayload($payload); |
||
89 | 3 | } |
|
90 | 3 | ||
91 | 3 | public function validate() |
|
92 | 3 | { |
|
93 | 3 | Assert::that($this->description)->string(); |
|
94 | 3 | Assert::that($this->itemId)->string(); |
|
95 | 3 | Assert::that($this->quantity)->float(); |
|
96 | 3 | Assert::that($this->unitPrice)->float(); |
|
97 | 3 | Assert::thatNullOr($this->taxPercent)->float(); |
|
98 | 3 | Assert::thatNullOr($this->taxAmount)->float(); |
|
99 | 2 | Assert::thatNullOr($this->unitCode)->string(); |
|
100 | Assert::thatNullOr($this->discount)->float(); |
||
101 | 3 | Assert::thatNullOr($this->goodsType)->string()->inArray(static::getGoodsTypes()); |
|
102 | Assert::thatNullOr($this->imageUrl)->string(); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @return array |
||
107 | 3 | */ |
|
108 | public static function getGoodsTypes() : array |
||
109 | { |
||
110 | 3 | return [ |
|
111 | 3 | self::GOODS_TYPE_HANDLING, |
|
112 | 3 | self::GOODS_TYPE_ITEM, |
|
113 | 3 | self::GOODS_TYPE_REFUND, |
|
114 | 2 | self::GOODS_TYPE_SHIPMENT, |
|
115 | ]; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * @return string |
||
120 | 3 | */ |
|
121 | public function getDescription() : string |
||
122 | 3 | { |
|
123 | return $this->description; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @param string $description |
||
128 | * @return OrderLine |
||
129 | 3 | */ |
|
130 | public function setDescription(string $description) : self |
||
131 | 3 | { |
|
132 | 3 | $this->description = $description; |
|
133 | 3 | return $this; |
|
134 | } |
||
135 | |||
136 | /** |
||
137 | * @return string |
||
138 | */ |
||
139 | 3 | public function getItemId() : string |
|
143 | |||
144 | /** |
||
145 | * @param string $itemId |
||
146 | * @return OrderLine |
||
147 | */ |
||
148 | 3 | public function setItemId(string $itemId) : self |
|
149 | { |
||
153 | |||
154 | /** |
||
155 | * @return float |
||
156 | */ |
||
157 | public function getQuantity() : float |
||
161 | |||
162 | /** |
||
163 | * @param float $quantity |
||
164 | * @return OrderLine |
||
165 | */ |
||
166 | public function setQuantity(float $quantity) : self |
||
171 | 3 | ||
172 | /** |
||
173 | * @return float |
||
174 | */ |
||
175 | public function getUnitPrice() : float |
||
179 | 3 | ||
180 | /** |
||
181 | * @param float $unitPrice |
||
182 | * @return OrderLine |
||
183 | */ |
||
184 | public function setUnitPrice(float $unitPrice) : self |
||
189 | 3 | ||
190 | 3 | /** |
|
191 | * @return float |
||
192 | */ |
||
193 | public function getTaxPercent() : ?float |
||
197 | |||
198 | 3 | /** |
|
199 | * @param float $taxPercent |
||
200 | * @return OrderLine |
||
201 | */ |
||
202 | public function setTaxPercent(float $taxPercent) : self |
||
207 | 3 | ||
208 | 3 | /** |
|
209 | 3 | * @return float |
|
210 | */ |
||
211 | public function getTaxAmount() : ?float |
||
215 | 3 | ||
216 | /** |
||
217 | 3 | * @param float $taxAmount |
|
218 | * @return OrderLine |
||
219 | */ |
||
220 | public function setTaxAmount(float $taxAmount) : self |
||
225 | |||
226 | 3 | /** |
|
227 | 3 | * @return string |
|
228 | 3 | */ |
|
229 | public function getUnitCode() : ?string |
||
233 | |||
234 | 3 | /** |
|
235 | * @param string $unitCode |
||
236 | 3 | * @return OrderLine |
|
237 | */ |
||
238 | public function setUnitCode(string $unitCode) : self |
||
243 | 3 | ||
244 | /** |
||
245 | 3 | * @return float |
|
246 | 3 | */ |
|
247 | 3 | public function getDiscount() : ?float |
|
251 | |||
252 | /** |
||
253 | 3 | * @param float $discount |
|
254 | * @return OrderLine |
||
255 | 3 | */ |
|
256 | public function setDiscount(float $discount) : self |
||
261 | |||
262 | 3 | /** |
|
263 | * @return string |
||
264 | 3 | */ |
|
265 | 3 | public function getGoodsType() : ?string |
|
269 | |||
270 | /** |
||
271 | * @param string $goodsType |
||
272 | 3 | * @return OrderLine |
|
273 | */ |
||
274 | 3 | public function setGoodsType(string $goodsType) : self |
|
279 | |||
280 | /** |
||
281 | 3 | * @return string |
|
282 | */ |
||
283 | 3 | public function getImageUrl() : ?string |
|
287 | |||
288 | /** |
||
289 | * @param string $imageUrl |
||
290 | * @return OrderLine |
||
291 | 3 | */ |
|
292 | public function setImageUrl(string $imageUrl) : self |
||
297 | } |
||
298 |