1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Billogram\Api; |
6
|
|
|
|
7
|
|
|
use Billogram\Exception\Domain\ValidationException; |
8
|
|
|
use Billogram\Model\Item\Item as Model; |
9
|
|
|
use Billogram\Model\Item\CollectionItem; |
10
|
|
|
use Psr\Http\Message\ResponseInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Ibrahim Hizeoui <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class Item extends HttpApi |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array $param |
19
|
|
|
* |
20
|
|
|
* @return CollectionItem|ResponseInterface |
21
|
|
|
* |
22
|
|
|
* @see https://billogram.com/api/documentation#items_list |
23
|
|
|
*/ |
24
|
1 |
|
public function search(array $param = []) |
25
|
|
|
{ |
26
|
1 |
|
$param = array_merge(['page' => 1, 'page_size' => 100], $param); |
27
|
1 |
|
$response = $this->httpGet('/item', $param); |
28
|
|
|
|
29
|
1 |
|
return $this->handleResponse($response, CollectionItem::class); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param string $itemNo |
34
|
|
|
* |
35
|
|
|
* @return Model|ResponseInterface |
36
|
|
|
* |
37
|
|
|
* @see https://billogram.com/api/documentation#items_fetch |
38
|
|
|
*/ |
39
|
1 |
|
public function fetch(string $itemNo) |
40
|
|
|
{ |
41
|
1 |
|
$response = $this->httpGet('/item/'.$itemNo); |
42
|
|
|
|
43
|
1 |
|
return $this->handleResponse($response, Model::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param Model $item |
48
|
|
|
* |
49
|
|
|
* @return Model|ResponseInterface |
50
|
|
|
* |
51
|
|
|
* @throws ValidationException |
52
|
|
|
* |
53
|
|
|
* @see https://billogram.com/api/documentation#items_create |
54
|
|
|
*/ |
55
|
1 |
|
public function create(array $item) |
56
|
|
|
{ |
57
|
1 |
|
$response = $this->httpPost('/item', $item); |
58
|
|
|
|
59
|
1 |
|
return $this->handleResponse($response, Model::class); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $itemNo |
64
|
|
|
* @param array $item |
65
|
|
|
* |
66
|
|
|
* @return Model|ResponseInterface |
67
|
|
|
* |
68
|
|
|
* @throws ValidationException |
69
|
|
|
* |
70
|
|
|
* @see https://billogram.com/api/documentation#items_edit |
71
|
|
|
*/ |
72
|
1 |
|
public function update(string $itemNo, array $item) |
73
|
|
|
{ |
74
|
1 |
|
$response = $this->httpPut('/item/'.$itemNo, $item); |
75
|
|
|
|
76
|
1 |
|
return $this->handleResponse($response, Model::class); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $itemNo |
81
|
|
|
* |
82
|
|
|
* @return Model|ResponseInterface |
83
|
|
|
* |
84
|
|
|
* @throws ValidationException |
85
|
|
|
* |
86
|
|
|
* @see https://billogram.com/api/documentation#items_delete |
87
|
|
|
*/ |
88
|
1 |
|
public function delete(string $itemNo) |
89
|
|
|
{ |
90
|
1 |
|
$response = $this->httpDelete('/item/'.$itemNo); |
91
|
|
|
|
92
|
1 |
|
return $this->handleResponse($response, Model::class); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|