|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Billogram\Api; |
|
6
|
|
|
|
|
7
|
|
|
use Billogram\Exception\Domain\NotFoundException; |
|
8
|
|
|
use Billogram\Exception\Domain\ValidationException; |
|
9
|
|
|
use Billogram\Model\Customer\Customer as Model; |
|
10
|
|
|
use Billogram\Model\Customer\CustomerCollection; |
|
11
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @author Ibrahim Hizeoui <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class Customer extends HttpApi |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param array $param |
|
20
|
|
|
* |
|
21
|
|
|
* @return CustomerCollection|ResponseInterface |
|
22
|
|
|
* |
|
23
|
|
|
* @see https://billogram.com/api/documentation#customers_list |
|
24
|
|
|
*/ |
|
25
|
1 |
|
public function search(array $param = []) |
|
26
|
|
|
{ |
|
27
|
1 |
|
$param = array_merge(['page' => 1, 'page_size' => 100], $param); |
|
28
|
1 |
|
$response = $this->httpGet('/customer', $param); |
|
29
|
|
|
|
|
30
|
1 |
|
return $this->handleResponse($response, CustomerCollection::class); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param int $customerNo |
|
35
|
|
|
* |
|
36
|
|
|
* @return Model|ResponseInterface |
|
37
|
|
|
* |
|
38
|
|
|
* @throws NotFoundException |
|
39
|
|
|
* |
|
40
|
|
|
* @see https://billogram.com/api/documentation#customers_fetch |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function fetch(int $customerNo) |
|
43
|
|
|
{ |
|
44
|
1 |
|
$response = $this->httpGet('/customer/'.$customerNo); |
|
45
|
|
|
|
|
46
|
1 |
|
return $this->handleResponse($response, Model::class); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param array $customer |
|
51
|
|
|
* |
|
52
|
|
|
* @return Model|ResponseInterface |
|
53
|
|
|
* |
|
54
|
|
|
* @throws ValidationException |
|
55
|
|
|
* |
|
56
|
|
|
* @see https://billogram.com/api/documentation#customers_create |
|
57
|
|
|
*/ |
|
58
|
1 |
|
public function create(array $customer) |
|
59
|
|
|
{ |
|
60
|
1 |
|
$response = $this->httpPost('/customer', $customer); |
|
61
|
|
|
|
|
62
|
1 |
|
return $this->handleResponse($response, Model::class); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param int $customerNo |
|
67
|
|
|
* @param array $customer with the fields you want to update |
|
68
|
|
|
* |
|
69
|
|
|
* @return Model|ResponseInterface |
|
70
|
|
|
* |
|
71
|
|
|
* @throws NotFoundException |
|
72
|
|
|
* @throws ValidationException |
|
73
|
|
|
* |
|
74
|
|
|
* @see https://billogram.com/api/documentation#customers_edit |
|
75
|
|
|
*/ |
|
76
|
1 |
|
public function update(int $customerNo, array $customer) |
|
77
|
|
|
{ |
|
78
|
1 |
|
$response = $this->httpPut('/customer/'.$customerNo, $customer); |
|
79
|
|
|
|
|
80
|
1 |
|
return $this->handleResponse($response, Model::class); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|