1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Shippinno\YahooShoppingJp\Request; |
4
|
|
|
|
5
|
|
|
use DateTimeZone; |
6
|
|
|
use FluidXml\FluidXml; |
7
|
|
|
use InvalidArgumentException; |
8
|
|
|
use LogicException; |
9
|
|
|
use Shippinno\YahooShoppingJp\Api\UpdateOrderShippingStatusApi; |
10
|
|
|
use Shippinno\YahooShoppingJp\Enum\ShipMethod; |
11
|
|
|
use Shippinno\YahooShoppingJp\Enum\ShipStatus; |
12
|
|
|
use Shippinno\YahooShoppingJp\Exception\InvalidRequestException; |
13
|
|
|
use Shippinno\YahooShoppingJp\Response\UpdateOrderShippingStatusResponse; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class UpdateOrderShippingStatusRequest |
17
|
|
|
* |
18
|
|
|
* @package Shippinno\YahooShoppingJp\Request |
19
|
|
|
*/ |
20
|
|
|
class UpdateOrderShippingStatusRequest extends AbstractRequest |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @return UpdateOrderShippingStatusApi |
24
|
|
|
*/ |
25
|
|
|
public function api() |
26
|
|
|
{ |
27
|
|
|
return new UpdateOrderShippingStatusApi; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return UpdateOrderShippingStatusResponse |
32
|
|
|
*/ |
33
|
|
|
public function response() |
34
|
|
|
{ |
35
|
|
|
return new UpdateOrderShippingStatusResponse; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @throws InvalidRequestException |
40
|
|
|
*/ |
41
|
|
|
protected function validateParams(): void |
42
|
|
|
{ |
43
|
|
|
if (!isset($this->params['SellerId'])) { |
44
|
|
|
throw new InvalidRequestException('SellerId is required.'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (!isset($this->params['Target']['OrderId'])) { |
48
|
|
|
throw new InvalidRequestException('OrderId is required.'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
if (!isset($this->params['Target']['IsPointFix'])) { |
52
|
|
|
throw new InvalidRequestException('IsPointFix is required.'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
if (!isset($this->params['Order']['Ship']['ShipStatus'])) { |
56
|
|
|
throw new InvalidRequestException('ShipStatus is required.'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getParams() |
64
|
|
|
{ |
65
|
|
|
$this->validateParams(); |
66
|
|
|
|
67
|
|
|
$fluidXml = new FluidXml('Req'); |
68
|
|
|
$fluidXml->add($this->params); |
69
|
|
|
|
70
|
|
|
return $fluidXml->xml(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $sellerId |
75
|
|
|
* @return self |
76
|
|
|
*/ |
77
|
|
View Code Duplication |
public function setSellerId(string $sellerId): self |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
if (isset($this->params['SellerId'])) { |
80
|
|
|
throw new LogicException('SellerId is already set.'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this->params['SellerId'] = $sellerId; |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param string $orderId |
90
|
|
|
* @return self |
91
|
|
|
*/ |
92
|
|
|
public function setOrderId(string $orderId): self |
93
|
|
|
{ |
94
|
|
|
if (isset($this->params['Target']['OrderId'])) { |
95
|
|
|
throw new LogicException('OrderId is already set.'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->params['Target']['OrderId'] = $orderId; |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param bool $isPointFix |
105
|
|
|
* @return self |
106
|
|
|
*/ |
107
|
|
|
public function setIsPointFix(bool $isPointFix): self |
108
|
|
|
{ |
109
|
|
|
if (isset($this->params['Target']['IsPointFix'])) { |
110
|
|
|
throw new LogicException('IsPointFix is already set.'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$this->params['Target']['IsPointFix'] = $isPointFix ? 'true' : 'false'; |
114
|
|
|
|
115
|
|
|
return $this; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param string $operationUser |
120
|
|
|
* @return self |
121
|
|
|
*/ |
122
|
|
|
public function setOperationUser(string $operationUser): self |
123
|
|
|
{ |
124
|
|
|
if (isset($this->params['Target']['OperationUser'])) { |
125
|
|
|
throw new LogicException('OperationUser is already set.'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
$this->params['Target']['OperationUser'] = $operationUser; |
129
|
|
|
|
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @param ShipStatus $shipStatus |
135
|
|
|
* @return self |
136
|
|
|
*/ |
137
|
|
|
public function setShipStatus(ShipStatus $shipStatus): self |
138
|
|
|
{ |
139
|
|
|
if (isset($this->params['Order']['Ship']['ShipStatus'])) { |
140
|
|
|
throw new LogicException('ShipStatus is already set.'); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$this->params['Order']['Ship']['ShipStatus'] = $shipStatus->getValue(); |
144
|
|
|
|
145
|
|
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param ShipMethod $shipMethod |
150
|
|
|
* @return self |
151
|
|
|
*/ |
152
|
|
|
public function setShipMethod(ShipMethod $shipMethod): self |
153
|
|
|
{ |
154
|
|
|
if (isset($this->params['Order']['Ship']['ShipMethod'])) { |
155
|
|
|
throw new LogicException('ShipMethod is already set.'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$this->params['Order']['Ship']['ShipMethod'] = $shipMethod->getValue(); |
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @param string $shipNotes |
165
|
|
|
* @return self |
166
|
|
|
*/ |
167
|
|
View Code Duplication |
public function setShipNotes(string $shipNotes): self |
|
|
|
|
168
|
|
|
{ |
169
|
|
|
if (isset($this->params['Order']['Ship']['ShipNotes'])) { |
170
|
|
|
throw new LogicException('ShipNotes is already set.'); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if (strlen($shipNotes) > 500) { |
174
|
|
|
throw new InvalidArgumentException('ShipNotes is invalid.'); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
$this->params['Order']['Ship']['ShipNotes'] = $shipNotes; |
178
|
|
|
|
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @param string $shipInvoiceNumber1 |
184
|
|
|
* @return self |
185
|
|
|
*/ |
186
|
|
View Code Duplication |
public function setShipInvoiceNumber1(string $shipInvoiceNumber1): self |
|
|
|
|
187
|
|
|
{ |
188
|
|
|
if (isset($this->params['Order']['Ship']['ShipInvoiceNumber1'])) { |
189
|
|
|
throw new LogicException('ShipInvoiceNumber1 is already set.'); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
$this->params['Order']['Ship']['ShipInvoiceNumber1'] = $shipInvoiceNumber1; |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param string $shipInvoiceNumber2 |
199
|
|
|
* @return self |
200
|
|
|
*/ |
201
|
|
View Code Duplication |
public function setShipInvoiceNumber2(string $shipInvoiceNumber2): self |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
if (isset($this->params['Order']['Ship']['ShipInvoiceNumber2'])) { |
204
|
|
|
throw new LogicException('ShipInvoiceNumber2 is already set.'); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
$this->params['Order']['Ship']['ShipInvoiceNumber2'] = $shipInvoiceNumber2; |
208
|
|
|
|
209
|
|
|
return $this; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @param string $shipUrl |
214
|
|
|
* @return self |
215
|
|
|
*/ |
216
|
|
View Code Duplication |
public function setShipUrl(string $shipUrl): self |
|
|
|
|
217
|
|
|
{ |
218
|
|
|
if (isset($this->params['Order']['Ship']['ShipUrl'])) { |
219
|
|
|
throw new LogicException('ShipUrl is already set.'); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
$this->params['Order']['Ship']['ShipUrl'] = '![CDATA[' . $shipUrl . ']]'; |
223
|
|
|
|
224
|
|
|
return $this; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @param \DateTimeImmutable $shipDate |
229
|
|
|
* @return self |
230
|
|
|
*/ |
231
|
|
View Code Duplication |
public function setShipDate(\DateTimeImmutable $shipDate): self |
|
|
|
|
232
|
|
|
{ |
233
|
|
|
if (isset($this->params['Order']['Ship']['ShipDate'])) { |
234
|
|
|
throw new LogicException('ShipDate is already set.'); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
$this->params['Order']['Ship']['ShipDate'] = $shipDate |
238
|
|
|
->setTimeZone(new DateTimeZone('Asia/Tokyo')) |
239
|
|
|
->format('Ymd'); |
240
|
|
|
|
241
|
|
|
return $this; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
/** |
245
|
|
|
* @param \DateTimeImmutable $arrivalDate |
246
|
|
|
* @return self |
247
|
|
|
*/ |
248
|
|
View Code Duplication |
public function setArrivalDate(\DateTimeImmutable $arrivalDate): self |
|
|
|
|
249
|
|
|
{ |
250
|
|
|
if (isset($this->params['Order']['Ship']['ArrivalDate'])) { |
251
|
|
|
throw new LogicException('ArrivalDate is already set.'); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
$this->params['Order']['Ship']['ArrivalDate'] = $arrivalDate |
255
|
|
|
->setTimeZone(new DateTimeZone('Asia/Tokyo')) |
256
|
|
|
->format('Ymd'); |
257
|
|
|
|
258
|
|
|
return $this; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
} |
262
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.