Skip to content

Commit 57d1f14

Browse files
committed
tickets, ticket messages and login links
1 parent f4a7a9b commit 57d1f14

File tree

2 files changed

+159
-1
lines changed

2 files changed

+159
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,38 @@ $sppApi->deleteOrderMessage($orderID, $messageID);
125125

126126
#### Get all order messages
127127
```
128-
$sppApi->getOrderMessages($orderID);
128+
$sppApi->getOrderMessages($orderID);
129+
```
130+
131+
### Tickets
132+
133+
#### Create a ticket
134+
```
135+
$sppApi->createTicket($ticketData);
136+
```
137+
138+
#### Get a ticket
139+
```
140+
$sppApi->getTicket($ticketID);
141+
```
142+
143+
#### Update a ticket
144+
```
145+
$sppApi->updateTicket($ticketData);
146+
```
147+
148+
#### Delete a ticket
149+
```
150+
$sppApi->deleteTicket($ticketID);
151+
```
152+
153+
#### Get all tickets
154+
```
155+
$sppApi->getTickets();
156+
```
157+
158+
159+
### Login Links
160+
```
161+
$sppApi->loginLink($userID);
162+
```

src/Api.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,128 @@ public function getOrderMessages($orderID) : array
230230

231231
return $data;
232232
}
233+
234+
public function createTicket($subject, $note, $user_id, $status = 1)
235+
{
236+
$response = $this->client->request('POST', 'tickets', [
237+
'auth' => [$this->apiKey, ''],
238+
'form_params' => [
239+
'user_id' => $user_id,
240+
'status' => $status,
241+
'subject' => $subject,
242+
'note' => $note,
243+
],
244+
]);
245+
246+
return $response->getStatusCode();
247+
}
248+
249+
public function getTicket($ticketID)
250+
{
251+
$response = $this->client->request('GET', 'tickets/' . $ticketID, [
252+
'auth' => [$this->apiKey, ''],
253+
]);
254+
255+
$data = json_decode($response->getBody()->getContents(), true);
256+
257+
return $data;
258+
}
259+
260+
public function updateTicket($ticketID, $subject = null, $note = null, $status = null, $employees = null, $tags = null)
261+
{
262+
$formParams = [];
263+
264+
if ($subject) {
265+
$formParams['subject'] = $subject;
266+
}
267+
268+
if ($note) {
269+
$formParams['note'] = $note;
270+
}
271+
272+
if ($status) {
273+
$formParams['status'] = $status;
274+
}
275+
276+
if ($employees) {
277+
$formParams['employees'] = $employees;
278+
}
279+
280+
if ($tags) {
281+
$formParams['tags'] = $tags;
282+
}
283+
284+
$response = $this->client->request('POST', 'tickets/' . $ticketID, [
285+
'auth' => [$this->apiKey, ''],
286+
'form_params' => $formParams,
287+
]);
288+
289+
return $response->getStatusCode();
290+
}
291+
292+
public function deleteTicket($ticketID)
293+
{
294+
$response = $this->client->request('DELETE', 'tickets/' . $ticketID, [
295+
'auth' => [$this->apiKey, ''],
296+
]);
297+
298+
return $response->getStatusCode();
299+
}
300+
301+
public function getTickets(array $options = []) : array
302+
{
303+
$response = $this->client->request('GET', 'tickets', [
304+
'query' => $options,
305+
'auth' => [$this->apiKey, ''],
306+
]);
307+
308+
$data = json_decode($response->getBody()->getContents(), true);
309+
310+
return $data;
311+
}
312+
313+
public function createTicketMessage($ticketID, $message, $user_id, $staff_only = 0)
314+
{
315+
$response = $this->client->request('POST', 'ticket_messages/' . $ticketID , [
316+
'auth' => [$this->apiKey, ''],
317+
'form_params' => [
318+
'user_id' => $user_id,
319+
'staff_only' => $staff_only,
320+
'message' => $message,
321+
],
322+
]);
323+
324+
return $response->getStatusCode();
325+
}
326+
327+
public function deleteTicketMessage($ticketID, $messageID)
328+
{
329+
$response = $this->client->request('DELETE', 'ticket_messages/' . $ticketID . '/' . $messageID, [
330+
'auth' => [$this->apiKey, ''],
331+
]);
332+
333+
return $response->getStatusCode();
334+
}
335+
336+
public function getTicketMessages($ticketID) : array
337+
{
338+
$response = $this->client->request('GET', 'ticket_messages/' . $ticketID, [
339+
'auth' => [$this->apiKey, ''],
340+
]);
341+
342+
$data = json_decode($response->getBody()->getContents(), true);
343+
344+
return $data;
345+
}
346+
347+
public function loginLink($clientID) : string
348+
{
349+
$response = $this->client->request('GET', 'login_links/' . $clientID, [
350+
'auth' => [$this->apiKey, ''],
351+
]);
352+
353+
$data = json_decode($response->getBody()->getContents(), true);
354+
355+
return $data['link'];
356+
}
233357
}

0 commit comments

Comments
 (0)