1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lifeboat\Services; |
4
|
|
|
|
5
|
|
|
use Lifeboat\Exceptions\ApiException; |
6
|
|
|
use Lifeboat\Exceptions\OAuthException; |
7
|
|
|
use Lifeboat\Models\Order; |
8
|
|
|
use Lifeboat\Resource\ListResource; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Orders |
12
|
|
|
* @package Lifeboat\Services |
13
|
|
|
*/ |
14
|
|
|
class Orders extends ApiService { |
15
|
|
|
|
16
|
|
|
const PERIOD_ALL = 'all'; |
17
|
|
|
const PERIOD_DAY = '1'; |
18
|
|
|
const PERIOD_7 = '7'; |
19
|
|
|
const PERIOD_30 = '30'; |
20
|
|
|
const PERIOD_90 = '90'; |
21
|
|
|
const PERIOD_120 = '120'; |
22
|
|
|
|
23
|
|
|
const STATUS_OPEN = 1; |
24
|
|
|
const STATUS_PAID = 2; |
25
|
|
|
|
26
|
|
|
const FULFILLMENT_PENDING = 1; |
27
|
|
|
const FULFILLMENT_FULFILLED = 2; |
28
|
|
|
const FULFILLMENT_DELIVERED = 3; |
29
|
|
|
|
30
|
|
|
const FULFILLMENT_SHIP = 0; |
31
|
|
|
const FULFILLMENT_DELIVER = 1; |
32
|
|
|
const FULFILLMENT_PICKUP = 2; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param int $id |
36
|
|
|
* @return Order|null |
37
|
|
|
* @throws ApiException |
38
|
|
|
* @throws OAuthException |
39
|
|
|
*/ |
40
|
|
|
public function fetch(int $id): ?Order |
41
|
|
|
{ |
42
|
|
|
/** @var Order|null $fetch */ |
43
|
|
|
$fetch = $this->_get('api/orders/order' . $id); |
44
|
|
|
return $fetch; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param array $data |
49
|
|
|
* @return Order|null |
50
|
|
|
* @throws ApiException |
51
|
|
|
* @throws OAuthException |
52
|
|
|
*/ |
53
|
|
|
public function create(array $data): ?Order |
54
|
|
|
{ |
55
|
|
|
/** @var Order|null $create */ |
56
|
|
|
$create = $this->_post('api/orders/order', $data); |
57
|
|
|
return $create; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param int $id |
62
|
|
|
* @param array $data |
63
|
|
|
* @return Order|null |
64
|
|
|
* @throws ApiException |
65
|
|
|
* @throws OAuthException |
66
|
|
|
*/ |
67
|
|
|
public function update(int $id, array $data): ?Order |
68
|
|
|
{ |
69
|
|
|
/** @var Order|null $post */ |
70
|
|
|
$post = $this->_post('api/orders/order/' . $id, $data); |
71
|
|
|
return $post; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param string $period |
76
|
|
|
* @param int $status |
77
|
|
|
* @param int $fulfillment |
78
|
|
|
* @return ListResource |
79
|
|
|
*/ |
80
|
|
|
public function all( |
81
|
|
|
string $period = self::PERIOD_7, |
82
|
|
|
int $status = self::STATUS_PAID, |
83
|
|
|
int $fulfillment = self::FULFILLMENT_PENDING |
84
|
|
|
): ListResource { |
85
|
|
|
$data = [ |
86
|
|
|
'period' => $period, |
87
|
|
|
'status' => $status, |
88
|
|
|
'fulfillment' => $fulfillment |
89
|
|
|
]; |
90
|
|
|
|
91
|
|
|
return new ListResource($this->getClient(), 'api/orders/all', $data, 20); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @return ListResource |
96
|
|
|
*/ |
97
|
|
|
public function deliveries(): ListResource |
98
|
|
|
{ |
99
|
|
|
return new ListResource($this->getClient(), 'api/orders/delivery', [], 20); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return ListResource |
104
|
|
|
*/ |
105
|
|
|
public function pickups(): ListResource |
106
|
|
|
{ |
107
|
|
|
return new ListResource($this->getClient(), 'api/orders/pickup', [], 20); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|