|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Signifly\Shopify\REST\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
|
6
|
|
|
use Signifly\Shopify\REST\Cursor; |
|
7
|
|
|
use Signifly\Shopify\REST\Resources\ApiResource; |
|
8
|
|
|
use Signifly\Shopify\REST\Resources\DraftOrderResource; |
|
9
|
|
|
use Signifly\Shopify\REST\Resources\OrderResource; |
|
10
|
|
|
use Signifly\Shopify\REST\Resources\RefundResource; |
|
11
|
|
|
use Signifly\Shopify\REST\Resources\RiskResource; |
|
12
|
|
|
use Signifly\Shopify\REST\Resources\TransactionResource; |
|
13
|
|
|
use Signifly\Shopify\Shopify; |
|
14
|
|
|
|
|
15
|
|
|
/** @mixin Shopify */ |
|
16
|
|
|
trait ManagesOrders |
|
17
|
|
|
{ |
|
18
|
|
|
public function createOrder(array $data): OrderResource |
|
19
|
|
|
{ |
|
20
|
|
|
return $this->createResource('orders', $data); |
|
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function getOrdersCount(array $params = []): int |
|
24
|
|
|
{ |
|
25
|
|
|
return $this->getResourceCount('orders', $params); |
|
|
|
|
|
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function paginateOrders(array $params = []): Cursor |
|
29
|
|
|
{ |
|
30
|
|
|
return $this->cursor($this->getOrders($params)); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function getOrders(array $params = []): Collection |
|
34
|
|
|
{ |
|
35
|
|
|
return $this->getResources('orders', $params); |
|
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getOrder($orderId): OrderResource |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->getResource('orders', $orderId); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function updateOrder($orderId, $data): OrderResource |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->updateResource('orders', $orderId, $data); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function deleteOrder($orderId): void |
|
49
|
|
|
{ |
|
50
|
|
|
$this->deleteResource('orders', $orderId); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function closeOrder($orderId): OrderResource |
|
54
|
|
|
{ |
|
55
|
|
|
$response = $this->get("orders/{$orderId}/close.json"); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
return new OrderResource($response['order'], $this); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function openOrder($orderId): OrderResource |
|
61
|
|
|
{ |
|
62
|
|
|
$response = $this->get("orders/{$orderId}/open.json"); |
|
63
|
|
|
|
|
64
|
|
|
return new OrderResource($response['order'], $this); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function cancelOrder($orderId): OrderResource |
|
68
|
|
|
{ |
|
69
|
|
|
$response = $this->get("orders/{$orderId}/cancel.json"); |
|
70
|
|
|
|
|
71
|
|
|
return new OrderResource($response['order'], $this); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function createOrderRisk($orderId, array $data): RiskResource |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->createResource('risks', $data, ['orders', $orderId]); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function getOrderRisks($orderId, array $params = []): Collection |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->getResources('risks', $params, ['orders', $orderId]); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function getOrderRisk($orderId, $riskId): Collection |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->getResource('risks', $riskId, ['orders', $orderId]); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function updateOrderRisk($orderId, $riskId, array $data): RiskResource |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->updateResource('risks', $riskId, $data, ['orders', $orderId]); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function deleteOrderRisk($orderId, $riskId): void |
|
95
|
|
|
{ |
|
96
|
|
|
$this->deleteResource('risks', $riskId, ['orders', $orderId]); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function createOrderRefund($orderId, array $data): RefundResource |
|
100
|
|
|
{ |
|
101
|
|
|
return $this->createResource('refunds', $data, ['orders', $orderId]); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function getOrderRefunds($orderId, array $params = []): Collection |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->getResources('refunds', $params, ['orders', $orderId]); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getOrderRefund($orderId, $refundId): RefundResource |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->getResource('refunds', $refundId, ['orders', $orderId]); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function calculateOrderRefund($orderId, array $data): RefundResource |
|
115
|
|
|
{ |
|
116
|
|
|
$response = $this->post("orders/{$orderId}/refunds/calculate.json", ['refund' => $data]); |
|
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
return new RefundResource($response['refund'], $this); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
public function getOrderTransactionsCount($orderId, array $params = []): Collection |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->getResourceCount('transactions', $params, ['orders', $orderId]); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function getOrderTransactions($orderId, array $params = []): Collection |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->getResources('transactions', $params, ['orders', $orderId]); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function createOrderTransaction($orderId, array $data): TransactionResource |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->createResource('transactions', $data, ['orders', $orderId]); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function createDraftOrder(array $data): DraftOrderResource |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->createResource('draft_orders', $data); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getDraftOrdersCount(array $params = []): int |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->getResourceCount('draft_orders', $params); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function paginateDraftOrders(array $params = []): Cursor |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->cursor($this->getDraftOrders($params)); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function getDraftOrders(array $params = []): Collection |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->getResources('draft_orders', $params); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function getDraftOrder($orderId): OrderResource |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->getResource('draft_orders', $orderId); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function updateDraftOrder($orderId, $data): OrderResource |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->updateResource('draft_orders', $orderId, $data); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function deleteDraftOrder($orderId): void |
|
167
|
|
|
{ |
|
168
|
|
|
$this->deleteResource('draft_orders', $orderId); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function sendDraftOrderInvoice($orderId, array $data): ApiResource |
|
172
|
|
|
{ |
|
173
|
|
|
$response = $this->post("draft_orders/{$orderId}/send_invoice.json", ['draft_order_invoice' => $data]); |
|
174
|
|
|
|
|
175
|
|
|
return new ApiResource($response['draft_order_invoice'], $this); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function completeDraftOrder($orderId, bool $paymentPending = false): DraftOrderResource |
|
179
|
|
|
{ |
|
180
|
|
|
$response = $this->put("draft_orders/{$orderId}/complete.json", ['payment_pending' => $paymentPending]); |
|
|
|
|
|
|
181
|
|
|
|
|
182
|
|
|
return new DraftOrderResource($response['draft_order'], $this); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function getCheckoutsCount(array $params = []): int |
|
186
|
|
|
{ |
|
187
|
|
|
return $this->getResourceCount('checkouts', $params); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function getCheckouts(array $params = []): Collection |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->getResources('checkouts', $params); |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|