-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOrder.php
152 lines (135 loc) · 3.74 KB
/
Order.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace flydreamers\shipwire;
use flydreamers\shipwire\base\ShipwireComponent;
/**
* Class Order
* @package flydreamers\shipwire
* @author Sebastian Thierer <sebas@flydreamers.com>
*/
class Order extends ShipwireComponent
{
/**
* Lists all orders depending on your parameters.
* @param array $params
* @param int $page
* @param int $limit
* @return array
*/
public function listing($params = [], $page = 0, $limit = 50)
{
return $this->get('orders', $params, $page, $limit);
}
/**
* Gets order details
* @param $orderId
* @param bool $expand
* @return array
*/
public function orderDetails($orderId, $expand = false)
{
$params = [];
if ($expand) {
$params['expand'] = 'all';
}
return $this->get($this->getRoute('orders/{id}', $orderId), $params);
}
/**
* Cancels an Order
* @param $orderId
* @return bool
*/
public function cancel($orderId)
{
$ret = $this->post($this->getRoute('orders/{id}/cancel', $orderId), [], null, true);
return $ret['status'] == 200;
}
/**
* Transform the route with the given orderId
* @param $route
* @param null $orderId
* @return string
*/
private function getRoute($route, $orderId = null)
{
if ($orderId !== null) {
return strtr($route, ['{id}' => $orderId]);
}
return $route;
}
/**
* Get the list of holds, if any, on an order
* @param $orderId
* @param array $params
* @param int $page
* @param int $limit
* @return array
*/
public function holds($orderId, $includeCleared = false, $params = [], $page = 0, $limit = 50)
{
if (!isset($params['includeCleared'])) {
$params['includeCleared'] = $includeCleared ? 1 : 0;
}
return $this->get($this->getRoute('orders/{id}/holds', $orderId), $params, $page, $limit);
}
/**
* Get the product details for this order
* @param $orderId
* @param array $params
* @param int $page
* @param int $limit
* @return array
*/
public function items($orderId, $params = [], $page = 0, $limit = 50)
{
return $this->get($this->getRoute('orders/{id}/items', $orderId), $params, $page, $limit);
}
/**
* Get related return information for a specific order.
* @param $orderId
* @param array $params
* @param int $page
* @param int $limit
* @return array
*/
public function returns($orderId, $params = [], $page = 0, $limit = 50)
{
return $this->get($this->getRoute('orders/{id}/returns', $orderId), $params, $page, $limit);
}
/**
* Get tracking information for a specific order.
* @param $orderId
* @param array $params
* @param int $page
* @param int $limit
* @return array
*/
public function tracking($orderId, $params = [], $page = 0, $limit = 50)
{
return $this->get($this->getRoute('orders/{id}/trackings', $orderId), $params, $page, $limit);
}
/**
* Creates an order.
* @param $orderData
* @param array $params
* @return array|bool
*/
public function create($orderData, $params = [])
{
return $this->post('orders', $params, json_encode($orderData));
}
/**
* Modify order details.
* @param $orderData
* @param array $params
* @return array|bool
*/
public function update($orderId, $orderData, $params = [])
{
return $this->put($this->getRoute('orders/{id}', $orderId), $params, json_encode($orderData));
}
/**
* Errors related to validation errors
* @var array
*/
public $errors=[];
}