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