1
|
|
|
<?php namespace Ntholenaar\MultiSafepayClient\Request; |
2
|
|
|
|
3
|
|
|
class CreateOrderRequest extends AbstractRequest implements RequestInterface |
4
|
|
|
{ |
5
|
|
|
/** |
6
|
|
|
* {@inheritdoc} |
7
|
|
|
*/ |
8
|
|
|
protected $httpMethod = 'POST'; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* {@inheritdoc} |
12
|
|
|
*/ |
13
|
|
|
protected $path = 'orders'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* {@inheritdoc} |
17
|
|
|
*/ |
18
|
|
|
public function validate() |
19
|
|
|
{ |
20
|
|
|
if (! isset($this->getPaymentOptions()['cancel_url']) || |
21
|
|
|
! isset($this->getPaymentOptions()['notification_url']) || |
22
|
|
|
! isset($this->getPaymentOptions()['redirect_url']) || |
23
|
|
|
is_null($this->getAmount()) || |
24
|
|
|
is_null($this->getCurrency()) || |
25
|
|
|
is_null($this->getDescription()) || |
26
|
|
|
is_null($this->getOrderId()) || |
27
|
|
|
is_null($this->getPaymentOptions()) || |
28
|
|
|
is_null($this->getType()) |
29
|
|
|
) { |
30
|
|
|
return false; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return true; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the type. |
38
|
|
|
* |
39
|
|
|
* @return string|null |
40
|
|
|
*/ |
41
|
|
|
public function getType() |
42
|
|
|
{ |
43
|
|
|
return $this->getRequestBodyParameter('type'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Set the type. |
48
|
|
|
* |
49
|
|
|
* @param $type |
50
|
|
|
* @return $this |
51
|
|
|
* @throws \InvalidArgumentException |
52
|
|
|
*/ |
53
|
|
|
public function setType($type) |
54
|
|
|
{ |
55
|
|
|
if ($type !== 'direct' && $type !== 'redirect') { |
56
|
|
|
throw new \InvalidArgumentException('Invalid type provided.'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->setRequestBodyParameter('type', $type); |
60
|
|
|
|
61
|
|
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the order identifier. |
66
|
|
|
* |
67
|
|
|
* @return mixed|null |
68
|
|
|
*/ |
69
|
|
|
public function getOrderId() |
70
|
|
|
{ |
71
|
|
|
return $this->getRequestBodyParameter('order_id'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Set the order identifier. |
76
|
|
|
* |
77
|
|
|
* @param $orderId |
78
|
|
|
* @return $this |
79
|
|
|
*/ |
80
|
|
|
public function setOrderId($orderId) |
81
|
|
|
{ |
82
|
|
|
$this->setRequestBodyParameter('order_id', $orderId); |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get the currency. |
89
|
|
|
* |
90
|
|
|
* @return null |
91
|
|
|
*/ |
92
|
|
|
public function getCurrency() |
93
|
|
|
{ |
94
|
|
|
return $this->getRequestBodyParameter('currency'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Set the currency. |
99
|
|
|
* |
100
|
|
|
* @param $currency |
101
|
|
|
* @return $this |
102
|
|
|
*/ |
103
|
|
|
public function setCurrency($currency) |
104
|
|
|
{ |
105
|
|
|
$this->setRequestBodyParameter('currency', $currency); |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get the amount. |
112
|
|
|
* |
113
|
|
|
* @return double|null |
114
|
|
|
*/ |
115
|
|
|
public function getAmount() |
116
|
|
|
{ |
117
|
|
|
return $this->getRequestBodyParameter('amount'); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set the amount. |
122
|
|
|
* |
123
|
|
|
* @param $amount |
124
|
|
|
* @return $this |
125
|
|
|
*/ |
126
|
|
|
public function setAmount($amount) |
127
|
|
|
{ |
128
|
|
|
$this->setRequestBodyParameter('amount', $amount); |
129
|
|
|
|
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Get the description. |
135
|
|
|
* |
136
|
|
|
* @return string|null |
137
|
|
|
*/ |
138
|
|
|
public function getDescription() |
139
|
|
|
{ |
140
|
|
|
return $this->getRequestBodyParameter('description'); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Set the description. |
145
|
|
|
* |
146
|
|
|
* @param $description |
147
|
|
|
* @return $this |
148
|
|
|
*/ |
149
|
|
|
public function setDescription($description) |
150
|
|
|
{ |
151
|
|
|
$this->setRequestBodyParameter('description', $description); |
152
|
|
|
|
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get the gateway identifier. |
158
|
|
|
* |
159
|
|
|
* @return string|null |
160
|
|
|
*/ |
161
|
|
|
public function getGatewayId() |
162
|
|
|
{ |
163
|
|
|
return $this->getRequestBodyParameter('gateway_id'); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Set the gateway identifier. |
168
|
|
|
* |
169
|
|
|
* @param $gatewayId |
170
|
|
|
* @return $this |
171
|
|
|
*/ |
172
|
|
|
public function setGatewayId($gatewayId) |
173
|
|
|
{ |
174
|
|
|
$this->setRequestBodyParameter('gateway_id', $gatewayId); |
175
|
|
|
|
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Get the value of var1. |
181
|
|
|
* |
182
|
|
|
* @return string|null |
183
|
|
|
*/ |
184
|
|
|
public function getVar1() |
185
|
|
|
{ |
186
|
|
|
return $this->getRequestBodyParameter('var1'); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Set the value of var1. |
191
|
|
|
* |
192
|
|
|
* @param $var1 |
193
|
|
|
* @return $this |
194
|
|
|
*/ |
195
|
|
|
public function setVar1($var1) |
196
|
|
|
{ |
197
|
|
|
$this->setRequestBodyParameter('var1', $var1); |
198
|
|
|
|
199
|
|
|
return $this; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Get the value of var2. |
204
|
|
|
* |
205
|
|
|
* @return string|null |
206
|
|
|
*/ |
207
|
|
|
public function getVar2() |
208
|
|
|
{ |
209
|
|
|
return $this->getRequestBodyParameter('var2'); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Set the value of var2. |
214
|
|
|
* |
215
|
|
|
* @param $var2 |
216
|
|
|
* @return $this |
217
|
|
|
*/ |
218
|
|
|
public function setVar2($var2) |
219
|
|
|
{ |
220
|
|
|
$this->setRequestBodyParameter('var2', $var2); |
221
|
|
|
|
222
|
|
|
return $this; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* Get the value of var3. |
227
|
|
|
* |
228
|
|
|
* @return string|null |
229
|
|
|
*/ |
230
|
|
|
public function getVar3() |
231
|
|
|
{ |
232
|
|
|
return $this->getRequestBodyParameter('var3'); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* Set the value of var3. |
237
|
|
|
* |
238
|
|
|
* @param $var3 |
239
|
|
|
* @return $this |
240
|
|
|
*/ |
241
|
|
|
public function setVar3($var3) |
242
|
|
|
{ |
243
|
|
|
$this->setRequestBodyParameter('var3', $var3); |
244
|
|
|
|
245
|
|
|
return $this; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Get the items. |
250
|
|
|
* |
251
|
|
|
* @return array|null |
252
|
|
|
*/ |
253
|
|
|
public function getItems() |
254
|
|
|
{ |
255
|
|
|
return $this->getRequestBodyParameter('items'); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Set the items. |
260
|
|
|
* |
261
|
|
|
* @param array $items |
262
|
|
|
* @return $this |
263
|
|
|
*/ |
264
|
|
|
public function setItems(array $items) |
265
|
|
|
{ |
266
|
|
|
$this->setRequestBodyParameter('items', $items); |
267
|
|
|
|
268
|
|
|
return $this; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* |
273
|
|
|
* @return boolean|null |
274
|
|
|
*/ |
275
|
|
|
public function isManual() |
276
|
|
|
{ |
277
|
|
|
return $this->getRequestBodyParameter('manual'); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @param $manual |
282
|
|
|
* @return $this |
283
|
|
|
*/ |
284
|
|
|
public function setManual($manual) |
285
|
|
|
{ |
286
|
|
|
$this->setRequestBodyParameter('manual', $manual); |
287
|
|
|
|
288
|
|
|
return $this; |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @return int|null |
293
|
|
|
*/ |
294
|
|
|
public function getDaysActive() |
295
|
|
|
{ |
296
|
|
|
return $this->getRequestBodyParameter('days_active'); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* @param $days |
301
|
|
|
* @return $this |
302
|
|
|
*/ |
303
|
|
|
public function setDaysActive($days) |
304
|
|
|
{ |
305
|
|
|
$this->setRequestBodyParameter('days_active', $days); |
306
|
|
|
|
307
|
|
|
return $this; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Get the payment options. |
312
|
|
|
* |
313
|
|
|
* @return mixed|null |
314
|
|
|
*/ |
315
|
|
|
public function getPaymentOptions() |
316
|
|
|
{ |
317
|
|
|
return $this->getRequestBodyParameter('payment_options'); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Set the payment options. |
322
|
|
|
* |
323
|
|
|
* @param array $paymentOptions |
324
|
|
|
* @return $this |
325
|
|
|
*/ |
326
|
|
|
public function setPaymentOptions(array $paymentOptions) |
327
|
|
|
{ |
328
|
|
|
// @todo filter array keys. |
329
|
|
|
// Check of er geen invalid keys in staan. |
330
|
|
|
|
331
|
|
|
$this->setRequestBodyParameter('payment_options', $paymentOptions); |
332
|
|
|
|
333
|
|
|
return $this; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Get the customer details. |
338
|
|
|
* |
339
|
|
|
* @return mixed|null |
340
|
|
|
*/ |
341
|
|
|
public function getCustomer() |
342
|
|
|
{ |
343
|
|
|
return $this->getRequestBodyParameter('customer'); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* Set the customer details. |
348
|
|
|
* |
349
|
|
|
* @param array $customer |
350
|
|
|
* @return $this |
351
|
|
|
*/ |
352
|
|
|
public function setCustomer(array $customer) |
353
|
|
|
{ |
354
|
|
|
$this->setRequestBodyParameter('customer', $customer); |
355
|
|
|
|
356
|
|
|
return $this; |
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
|