Passed
Pull Request — master (#4)
by Cesar
03:13
created

Order::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PagaMasTarde\OrdersApiClient\Model;
4
5
use PagaMasTarde\OrdersApiClient\Model\Order\ActionUrls;
6
use PagaMasTarde\OrdersApiClient\Model\Order\Configuration;
7
use PagaMasTarde\OrdersApiClient\Model\Order\Metadata;
8
use PagaMasTarde\OrdersApiClient\Model\Order\Refund;
9
use PagaMasTarde\OrdersApiClient\Model\Order\ShoppingCart;
10
use PagaMasTarde\OrdersApiClient\Model\Order\User;
11
12
/**
13
 * Class Order
14
 *
15
 * @package PagaMasTarde\OrdersApiClient\Model
16
 */
17
class Order extends AbstractModel
18
{
19
    /**
20
     * Initial status of a order.
21
     */
22
    const STATUS_CREATED = 'CREATED';
23
24
    /**
25
     * Order has been authorized and initial payment has been approved. For finalizing the order
26
     * it's mandatory to confirm it.
27
     */
28
    const STATUS_AUTHORIZED = 'AUTHORIZED';
29
30
    /**
31
     * Order confirmed has been paid by customer and merchant has confirmed it. Payment is completed
32
     * and settlement will be created.
33
     */
34
    const STATUS_CONFIRMED = 'CONFIRMED';
35
36
    /**
37
     * Rejected by the risk engine, the transaction has been rejected and payment is no longer
38
     * expected nor possible.
39
     */
40
    const STATUS_REJECTED = 'REJECTED';
41
42
    /**
43
     * The order has been invalidated due to the expiration limit. If no action happens during the
44
     * defined time, the order could turn to invalidated.
45
     */
46
    const STATUS_INVALIDATED = 'INVALIDATED';
47
48
    /**
49
     * Undefined ERROR has occurred, please double check with the account manager or PMT support channels.
50
     */
51
    const STATUS_ERROR = 'ERROR';
52
53
    /**
54
     * If a order is not confirmed given the default confirmation time, defined previously, it will turn to
55
     * unconfirmed and this will refund any possible payment taken from the customer. The loan shall not be created.
56
     */
57
    const STATUS_UNCONFIRMED = 'UNCONFIRMED';
58
59
    /**
60
     * The order cancelled is a consequence of a total refund or sum of partial refunds generating the total refund.
61
     */
62
    const STATUS_CANCELLED = 'CANCELLED';
63
64
    /**
65
     * @var ActionUrls $actionUrls
66
     */
67
    protected $actionUrls;
68
69
    /**
70
     * @var string $apiVersion
71
     */
72
    protected $apiVersion;
73
74
    /**
75
     * @var Configuration $configuration
76
     */
77
    protected $configuration;
78
79
    /**
80
     * @var \DateTime $confirmedAt
81
     */
82
    protected $confirmedAt;
83
84
    /**
85
     * @var \DateTime $createdAt
86
     */
87
    protected $createdAt;
88
89
    /**
90
     * @var \DateTime $expiresAt
91
     */
92
    protected $expiresAt;
93
94
    /**
95
     * @var \DateTime $unconfirmedAt
96
     */
97
    protected $unconfirmedAt;
98
99
    /**
100
     * @var string $gracePeriod
101
     */
102
    protected $gracePeriod;
103
104
    /**
105
     * @var string $gracePeriodMonth
106
     */
107
    protected $gracePeriodMonth;
108
109
    /**
110
     * @var string $id
111
     */
112
    protected $id;
113
114
    /**
115
     * @var Metadata $metadata
116
     */
117
    protected $metadata;
118
119
    /**
120
     * @var Refund[] $refunds
121
     */
122
    protected $refunds;
123
124
    /**
125
     * @var ShoppingCart $shoppingCart
126
     */
127
    protected $shoppingCart;
128
129
    /**
130
     * @var string $status
131
     */
132
    protected $status;
133
134
    /**
135
     * @var User $user
136
     */
137
    protected $user;
138
139
    /**
140
     * Order constructor.
141
     */
142
    public function __construct()
143
    {
144
        $this->configuration = new Configuration();
145
        $this->metadata = new Metadata();
146
        $this->shoppingCart = new ShoppingCart();
147
        $this->user = new User();
148
    }
149
150
    /**
151
     * @return ActionUrls
152
     */
153
    public function getActionUrls()
154
    {
155
        return $this->actionUrls;
156
    }
157
158
    /**
159
     * @param ActionUrls $actionUrls
160
     *
161
     * @return Order
162
     */
163
    public function setActionUrls($actionUrls)
164
    {
165
        $this->actionUrls = $actionUrls;
166
167
        return $this;
168
    }
169
170
    /**
171
     * @return string
172
     */
173
    public function getApiVersion()
174
    {
175
        return $this->apiVersion;
176
    }
177
178
    /**
179
     * @param string $apiVersion
180
     *
181
     * @return Order
182
     */
183
    public function setApiVersion($apiVersion)
184
    {
185
        $this->apiVersion = $apiVersion;
186
187
        return $this;
188
    }
189
190
    /**
191
     * @return Configuration
192
     */
193
    public function getConfiguration()
194
    {
195
        return $this->configuration;
196
    }
197
198
    /**
199
     * @param Configuration $configuration
200
     *
201
     * @return Order
202
     */
203
    public function setConfiguration($configuration)
204
    {
205
        $this->configuration = $configuration;
206
207
        return $this;
208
    }
209
210
    /**
211
     * @return \DateTime
212
     */
213
    public function getConfirmedAt()
214
    {
215
        return $this->confirmedAt;
216
    }
217
218
    /**
219
     * @param \DateTime $confirmedAt
220
     *
221
     * @return Order
222
     */
223
    public function setConfirmedAt($confirmedAt)
224
    {
225
        $this->confirmedAt = $confirmedAt;
226
227
        return $this;
228
    }
229
230
    /**
231
     * @return \DateTime
232
     */
233
    public function getCreatedAt()
234
    {
235
        return $this->createdAt;
236
    }
237
238
    /**
239
     * @param \DateTime $createdAt
240
     *
241
     * @return Order
242
     */
243
    public function setCreatedAt($createdAt)
244
    {
245
        $this->createdAt = $createdAt;
246
247
        return $this;
248
    }
249
250
    /**
251
     * @return \DateTime
252
     */
253
    public function getExpiresAt()
254
    {
255
        return $this->expiresAt;
256
    }
257
258
    /**
259
     * @param \DateTime $expiresAt
260
     *
261
     * @return Order
262
     */
263
    public function setExpiresAt($expiresAt)
264
    {
265
        $this->expiresAt = $expiresAt;
266
267
        return $this;
268
    }
269
270
    /**
271
     * @return \DateTime
272
     */
273
    public function getUnconfirmedAt()
274
    {
275
        return $this->unconfirmedAt;
276
    }
277
278
    /**
279
     * @param \DateTime $unconfirmedAt
280
     *
281
     * @return Order
282
     */
283
    public function setUnconfirmedAt($unconfirmedAt)
284
    {
285
        $this->unconfirmedAt = $unconfirmedAt;
286
287
        return $this;
288
    }
289
290
    /**
291
     * @return string
292
     */
293
    public function getGracePeriod()
294
    {
295
        return $this->gracePeriod;
296
    }
297
298
    /**
299
     * @param string $gracePeriod
300
     *
301
     * @return Order
302
     */
303
    public function setGracePeriod($gracePeriod)
304
    {
305
        $this->gracePeriod = $gracePeriod;
306
307
        return $this;
308
    }
309
310
    /**
311
     * @return string
312
     */
313
    public function getGracePeriodMonth()
314
    {
315
        return $this->gracePeriodMonth;
316
    }
317
318
    /**
319
     * @param string $gracePeriodMonth
320
     *
321
     * @return Order
322
     */
323
    public function setGracePeriodMonth($gracePeriodMonth)
324
    {
325
        $this->gracePeriodMonth = $gracePeriodMonth;
326
327
        return $this;
328
    }
329
330
    /**
331
     * @return string
332
     */
333
    public function getId()
334
    {
335
        return $this->id;
336
    }
337
338
    /**
339
     * @param string $id
340
     *
341
     * @return Order
342
     */
343
    public function setId($id)
344
    {
345
        $this->id = $id;
346
347
        return $this;
348
    }
349
350
    /**
351
     * @return Metadata
352
     */
353
    public function getMetadata()
354
    {
355
        return $this->metadata;
356
    }
357
358
    /**
359
     * @param Metadata $metadata
360
     *
361
     * @return Order
362
     */
363
    public function setMetadata($metadata)
364
    {
365
        $this->metadata = $metadata;
366
367
        return $this;
368
    }
369
370
    /**
371
     * @return Refund[]
372
     */
373
    public function getRefunds()
374
    {
375
        return $this->refunds;
376
    }
377
378
    /**
379
     * @param Refund $refund
380
     *
381
     * @return $this
382
     */
383
    public function addRefund(Refund $refund)
384
    {
385
        $this->refunds[] = $refund;
386
387
        return $this;
388
    }
389
390
    /**
391
     * @return ShoppingCart
392
     */
393
    public function getShoppingCart()
394
    {
395
        return $this->shoppingCart;
396
    }
397
398
    /**
399
     * @param ShoppingCart $shoppingCart
400
     *
401
     * @return Order
402
     */
403
    public function setShoppingCart($shoppingCart)
404
    {
405
        $this->shoppingCart = $shoppingCart;
406
407
        return $this;
408
    }
409
410
    /**
411
     * @return string
412
     */
413
    public function getStatus()
414
    {
415
        return $this->status;
416
    }
417
418
    /**
419
     * @param string $status
420
     *
421
     * @return Order
422
     */
423
    public function setStatus($status)
424
    {
425
        $this->status = $status;
426
427
        return $this;
428
    }
429
430
    /**
431
     * @return User
432
     */
433
    public function getUser()
434
    {
435
        return $this->user;
436
    }
437
438
    /**
439
     * @param User $user
440
     *
441
     * @return Order
442
     */
443
    public function setUser($user)
444
    {
445
        $this->user = $user;
446
447
        return $this;
448
    }
449
450
    /**
451
     * @param \stdClass $object
452
     */
453
    public function import($object)
454
    {
455
        $this->actionUrls = new ActionUrls();
456
        $this->configuration = new Configuration();
457
        $this->metadata = new Metadata();
458
        $this->refunds = array();
459
        $this->shoppingCart = new ShoppingCart();
460
        $this->user = new User();
461
462
        parent::import($object);
463
        $properties = get_object_vars($object);
464
        foreach ($properties as $key => $value) {
465
            if (is_array($value)) {
466
                if (is_array($this->{$key}) && $key == 'refunds') {
467
                    $this->refunds = array();
468
                    foreach ($value as $refund) {
469
                        $refundObject = new Refund();
470
                        $refundObject->import($refund);
471
                        $this->addRefund($refundObject);
472
                    }
473
                }
474
            }
475
        }
476
    }
477
}
478