Completed
Push — master ( 1e2063...77648b )
by Tobias
03:30
created

Invoice::addMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Api;
6
7
use Billogram\Model\Invoice\Invoice as Model;
8
use Billogram\Model\Invoice\InvoiceCollection;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * @author Ibrahim Hizeoui <[email protected]>
13
 */
14
class Invoice extends HttpApi
15
{
16
    /**
17
     * @param array $param
18
     *
19
     * @return InvoiceCollection|ResponseInterface
20
     *
21
     * @see https://billogram.com/api/documentation#billogram_call_list
22
     */
23 1
    public function search(array $param = [])
24
    {
25 1
        $param = array_merge(['page' => 1, 'page_size' => 100], $param);
26 1
        $response = $this->httpGet('/billogram', $param);
27
28 1
        return $this->handleResponse($response, InvoiceCollection::class);
29
    }
30
31
    /**
32
     * @param string $invoiceId
33
     *
34
     * @return Model|ResponseInterface
35
     *
36
     * @see https://billogram.com/api/documentation#billogram_call_fetch
37
     */
38 2
    public function fetch(string $invoiceId)
39
    {
40 2
        $response = $this->httpGet('/billogram/'.$invoiceId);
41
42 2
        return $this->handleResponse($response, Model::class);
43
    }
44
45
    /**
46
     * @param array $invoice
47
     *
48
     * @return Model|ResponseInterface
49
     *
50
     * @see https://billogram.com/api/documentation#billogram_call_create
51
     *
52
     * @throws \Billogram\Exception
53
     */
54 1
    public function create(array $invoice)
55
    {
56 1
        $response = $this->httpPost('/billogram', $invoice);
57
58 1
        return $this->handleResponse($response, Model::class);
59
    }
60
61
    /**
62
     * @param string $invoiceId
63
     * @param array  $invoice
64
     *
65
     * @return Model|ResponseInterface
66
     *
67
     * @see https://billogram.com/api/documentation#billogram_call_update
68
     *
69
     * @throws \Billogram\Exception
70
     */
71 1
    public function update(string $invoiceId, array $invoice)
72
    {
73 1
        $response = $this->httpPut('/billogram/'.$invoiceId, $invoice);
74
75 1
        return $this->handleResponse($response, Model::class);
76
    }
77
78
    /**
79
     * @param string $invoiceId
80
     * @param string $method
81
     *
82
     * @return Model|ResponseInterface
83
     *
84
     * @see https://billogram.com/api/documentation#billogram_call_send
85
     *
86
     * @throws \Billogram\Exception
87
     */
88 View Code Duplication
    public function send(string $invoiceId, $method = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90
        $params = [];
91
        if (null !== $method) {
92
            $params = ['method' => $method];
93
        }
94
        $response = $this->httpPost('/billogram/'.$invoiceId.'/command/send', $params);
95
96
        return $this->handleResponse($response, Model::class);
97
    }
98
99
    /**
100
     * @param string $invoiceId
101
     * @param string $method
102
     *
103
     * @return Model|ResponseInterface
104
     *
105
     * @see https://billogram.com/api/documentation#billogram_call_resend
106
     *
107
     * @throws \Billogram\Exception
108
     */
109 View Code Duplication
    public function resend(string $invoiceId, $method = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $params = [];
112
        if (null !== $method) {
113
            $params = ['method' => $method];
114
        }
115
116
        $response = $this->httpPost('/billogram/'.$invoiceId.'/command/resend', $params);
117
118
        return $this->handleResponse($response, Model::class);
119
    }
120
121
    /**
122
     * @param string $invoiceId
123
     *
124
     * @return Model|ResponseInterface
125
     *
126
     * @see https://billogram.com/api/documentation#billogram_call_collect
127
     *
128
     * @throws \Billogram\Exception
129
     */
130
    public function collect(string $invoiceId)
131
    {
132
        $response = $this->httpPost('/billogram/'.$invoiceId.'/command/collect', []);
133
134
        return $this->handleResponse($response, Model::class);
135
    }
136
137
    /**
138
     * @param string $invoiceId
139
     * @param float  $amount
140
     *
141
     * @return Model|ResponseInterface
142
     *
143
     * @see https://billogram.com/api/documentation#billogram_call_payment
144
     *
145
     * @throws \Billogram\Exception
146
     */
147 View Code Duplication
    public function manualRegister(string $invoiceId, float $amount)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
148
    {
149
        $params = ['amount' => $amount];
150
        $response = $this->httpPost('/billogram/'.$invoiceId.'/command/payment', $params);
151
152
        return $this->handleResponse($response, Model::class);
153
    }
154
155
    /**
156
     * @param string $invoiceId
157
     * @param string $mode
158
     * @param float  $amount
159
     * @param string $method
160
     *
161
     * @return Model|ResponseInterface
162
     *
163
     * @see https://billogram.com/api/documentation#billogram_call_credit
164
     *
165
     * @throws \Billogram\Exception
166
     */
167
    public function credit(string $invoiceId, string $mode, float $amount, string $method)
168
    {
169
        $params = [
170
            'mode' => $mode,
171
            'amount' => $amount,
172
            'method' => $method,
173
        ];
174
        $response = $this->httpPost('/billogram/'.$invoiceId.'/command/credit', $params);
175
176
        return $this->handleResponse($response, Model::class);
177
    }
178
179
    /**
180
     * @param string $invoiceId
181
     *
182
     * @return Model|ResponseInterface
183
     *
184
     * @see https://billogram.com/api/documentation#billogram_call_writeoff
185
     *
186
     * @throws \Billogram\Exception
187
     */
188
    public function writeOff(string $invoiceId)
189
    {
190
        $response = $this->httpPost('/billogram/'.$invoiceId.'/command/writeoff');
191
192
        return $this->handleResponse($response, Model::class);
193
    }
194
195
    /**
196
     * @param string $invoiceId
197
     *
198
     * @return Model|ResponseInterface
199
     *
200
     * @see https://billogram.com/api/documentation#billogram_call_writedown
201
     *
202
     * @throws \Billogram\Exception
203
     */
204
    public function writeDown(string $invoiceId)
205
    {
206
        $response = $this->httpPost('/billogram/'.$invoiceId.'/command/writedown');
207
208
        return $this->handleResponse($response, Model::class);
209
    }
210
211
    /**
212
     * @param string $invoiceId
213
     *
214
     * @return Model|ResponseInterface
215
     *
216
     * @see https://billogram.com/api/documentation#billogram_call_writedown
217
     *
218
     * @throws \Billogram\Exception
219
     */
220
    public function writeDownRevert(string $invoiceId)
221
    {
222
        $response = $this->httpPost('/billogram/'.$invoiceId.'/command/revert-writedown');
223
224
        return $this->handleResponse($response, Model::class);
225
    }
226
227
    /**
228
     * @param string $invoiceId
229
     * @param string $message
230
     *
231
     * @return Model|ResponseInterface
232
     *
233
     * @see https://billogram.com/api/documentation#billogram_call_writedown
234
     *
235
     * @throws \Billogram\Exception
236
     */
237 View Code Duplication
    public function addMessage(string $invoiceId, string $message)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
238
    {
239
        $params = ['message' => $message];
240
        $response = $this->httpPost('/billogram/'.$invoiceId.'/command/message', $params);
241
242
        return $this->handleResponse($response, Model::class);
243
    }
244
}
245