@@ 17-123 (lines=107) @@ | ||
14 | * |
|
15 | * @author Tobias Nyholm <[email protected]> |
|
16 | */ |
|
17 | class Customer extends HttpApi |
|
18 | { |
|
19 | /** |
|
20 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
21 | * |
|
22 | * @return CustomerCollection|ResponseInterface |
|
23 | */ |
|
24 | public function all(array $params = []) |
|
25 | { |
|
26 | $response = $this->httpGet('/3/customers', $params); |
|
27 | ||
28 | if (!$this->hydrator) { |
|
29 | return $response; |
|
30 | } |
|
31 | ||
32 | // Use any valid status code here |
|
33 | if (200 !== $response->getStatusCode()) { |
|
34 | $this->handleErrors($response); |
|
35 | } |
|
36 | ||
37 | return $this->hydrator->hydrate($response, CustomerCollection::class); |
|
38 | } |
|
39 | ||
40 | /** |
|
41 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
42 | * |
|
43 | * @return Model|ResponseInterface |
|
44 | */ |
|
45 | public function get(string $customer) |
|
46 | { |
|
47 | $response = $this->httpGet('/3/customers/'.$customer); |
|
48 | ||
49 | if (!$this->hydrator) { |
|
50 | return $response; |
|
51 | } |
|
52 | ||
53 | // Use any valid status code here |
|
54 | if (200 !== $response->getStatusCode()) { |
|
55 | $this->handleErrors($response); |
|
56 | } |
|
57 | ||
58 | return $this->hydrator->hydrate($response, Model::class); |
|
59 | } |
|
60 | ||
61 | /** |
|
62 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
63 | * |
|
64 | * @return Model|ResponseInterface |
|
65 | */ |
|
66 | public function create(array $data) |
|
67 | { |
|
68 | $response = $this->httpPost('/3/customers', ['Customer' => $data]); |
|
69 | ||
70 | if (!$this->hydrator) { |
|
71 | return $response; |
|
72 | } |
|
73 | ||
74 | // Use any valid status code here |
|
75 | if (201 !== $response->getStatusCode()) { |
|
76 | $this->handleErrors($response); |
|
77 | } |
|
78 | ||
79 | return $this->hydrator->hydrate($response, Model::class); |
|
80 | } |
|
81 | ||
82 | /** |
|
83 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
84 | * |
|
85 | * @return Model|ResponseInterface |
|
86 | */ |
|
87 | public function update(string $customer, array $data) |
|
88 | { |
|
89 | $response = $this->httpPut('/3/customers/'.$customer, ['Customer' => $data]); |
|
90 | ||
91 | if (!$this->hydrator) { |
|
92 | return $response; |
|
93 | } |
|
94 | ||
95 | // Use any valid status code here |
|
96 | if (200 !== $response->getStatusCode()) { |
|
97 | $this->handleErrors($response); |
|
98 | } |
|
99 | ||
100 | return $this->hydrator->hydrate($response, Model::class); |
|
101 | } |
|
102 | ||
103 | /** |
|
104 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
105 | * |
|
106 | * @return ApiResponse|ResponseInterface |
|
107 | */ |
|
108 | public function delete(string $customer) |
|
109 | { |
|
110 | $response = $this->httpDelete('/3/customers/'.$customer); |
|
111 | ||
112 | if (!$this->hydrator) { |
|
113 | return $response; |
|
114 | } |
|
115 | ||
116 | // Use any valid status code here |
|
117 | if (204 !== $response->getStatusCode()) { |
|
118 | $this->handleErrors($response); |
|
119 | } |
|
120 | ||
121 | return $this->hydrator->hydrate($response, ApiResponse::class); |
|
122 | } |
|
123 | } |
|
124 |
@@ 18-124 (lines=107) @@ | ||
15 | * |
|
16 | * @author Tobias Nyholm <[email protected]> |
|
17 | */ |
|
18 | class Invoice extends HttpApi |
|
19 | { |
|
20 | /** |
|
21 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
22 | * |
|
23 | * @return CustomerCollection|ResponseInterface |
|
24 | */ |
|
25 | public function all(array $params = []) |
|
26 | { |
|
27 | $response = $this->httpGet('/3/invoices', $params); |
|
28 | ||
29 | if (!$this->hydrator) { |
|
30 | return $response; |
|
31 | } |
|
32 | ||
33 | // Use any valid status code here |
|
34 | if (200 !== $response->getStatusCode()) { |
|
35 | $this->handleErrors($response); |
|
36 | } |
|
37 | ||
38 | return $this->hydrator->hydrate($response, InvoiceCollection::class); |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
43 | * |
|
44 | * @return Model|ResponseInterface |
|
45 | */ |
|
46 | public function get(int $invoice) |
|
47 | { |
|
48 | $response = $this->httpGet('/3/invoices/'.$invoice); |
|
49 | ||
50 | if (!$this->hydrator) { |
|
51 | return $response; |
|
52 | } |
|
53 | ||
54 | // Use any valid status code here |
|
55 | if (200 !== $response->getStatusCode()) { |
|
56 | $this->handleErrors($response); |
|
57 | } |
|
58 | ||
59 | return $this->hydrator->hydrate($response, Model::class); |
|
60 | } |
|
61 | ||
62 | /** |
|
63 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
64 | * |
|
65 | * @return Model|ResponseInterface |
|
66 | */ |
|
67 | public function create(array $data) |
|
68 | { |
|
69 | $response = $this->httpPost('/3/invoices', ['Invoice' => $data]); |
|
70 | ||
71 | if (!$this->hydrator) { |
|
72 | return $response; |
|
73 | } |
|
74 | ||
75 | // Use any valid status code here |
|
76 | if (201 !== $response->getStatusCode()) { |
|
77 | $this->handleErrors($response); |
|
78 | } |
|
79 | ||
80 | return $this->hydrator->hydrate($response, Model::class); |
|
81 | } |
|
82 | ||
83 | /** |
|
84 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
85 | * |
|
86 | * @return Model|ResponseInterface |
|
87 | */ |
|
88 | public function update(int $invoice, array $data) |
|
89 | { |
|
90 | $response = $this->httpPut('/3/invoices/'.$invoice, ['Invoice' => $data]); |
|
91 | ||
92 | if (!$this->hydrator) { |
|
93 | return $response; |
|
94 | } |
|
95 | ||
96 | // Use any valid status code here |
|
97 | if (200 !== $response->getStatusCode()) { |
|
98 | $this->handleErrors($response); |
|
99 | } |
|
100 | ||
101 | return $this->hydrator->hydrate($response, Model::class); |
|
102 | } |
|
103 | ||
104 | /** |
|
105 | * @throws \FAPI\Fortnox\Exception\DomainException |
|
106 | * |
|
107 | * @return ApiResponse|ResponseInterface |
|
108 | */ |
|
109 | public function email(int $invoice) |
|
110 | { |
|
111 | $response = $this->httpGet(sprintf('/3/invoices/%d/email', $invoice)); |
|
112 | ||
113 | if (!$this->hydrator) { |
|
114 | return $response; |
|
115 | } |
|
116 | ||
117 | // Use any valid status code here |
|
118 | if (200 !== $response->getStatusCode()) { |
|
119 | $this->handleErrors($response); |
|
120 | } |
|
121 | ||
122 | return $this->hydrator->hydrate($response, ApiResponse::class); |
|
123 | } |
|
124 | } |
|
125 |