Completed
Push — master ( 4517c4...dc88ca )
by
unknown
05:54
created

BankAccount   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 342
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 342
rs 10
c 1
b 0
f 0
wmc 25
lcom 2
cbo 2

24 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 6 1
A getId() 0 4 1
A setType() 0 6 1
A getType() 0 4 1
A setBankNumber() 0 6 1
A getBankNumber() 0 4 1
A setAgencyNumber() 0 6 1
A getAgencyNumber() 0 4 1
A setAgencyCheckNumber() 0 6 1
A getAgencyCheckNumber() 0 4 1
A setAccountNumber() 0 6 1
A getAccountNumber() 0 4 1
A setAccountCheckNumber() 0 6 1
A getAccountCheckNumber() 0 4 1
A setHolder() 0 9 1
A getFullname() 0 4 1
A getTaxDocumentType() 0 4 1
A getTaxDocumentNumber() 0 4 1
A get() 0 4 1
A getList() 0 6 1
A create() 0 4 1
A update() 0 6 2
A delete() 0 4 1
B populate() 0 27 1
1
<?php
2
3
namespace Moip\Resource;
4
5
use stdClass;
6
7
/**
8
 * Class BankAccount.
9
 */
10
class BankAccount extends MoipResource
11
{
12
    /**
13
     * Path bank accounts API.
14
     *
15
     * @const string
16
     */
17
    const PATH = 'bankaccounts';
18
19
    /**
20
     * Path accounts API.
21
     *
22
     * @const string
23
     */
24
    const PATH_ACCOUNT = 'accounts';
25
26
    /**
27
     * Bank account type.
28
     *
29
     * @const string
30
     */
31
    const CHECKING = 'CHECKING';
32
33
    /**
34
     * Bank account type.
35
     *
36
     * @const string
37
     */
38
    const SAVING = 'SAVING';
39
40
    /**
41
     * Initialize a new instance.
42
     */
43
    public function initialize()
44
    {
45
        $this->data = new stdClass();
46
        $this->data->holder = new stdClass();
47
        $this->data->holder->taxDocument = new stdClass();
48
    }
49
50
    /**
51
     * Returns bank account id.
52
     *
53
     * @return stdClass
54
     */
55
    public function getId()
56
    {
57
        return $this->getIfSet('id');
58
    }
59
60
    /**
61
     * Set bank account type.
62
     *
63
     * @param string $type Bank account type (CHECKING or SAVING).
64
     *
65
     * @return $this
66
     */
67
    public function setType($type)
68
    {
69
        $this->data->type = $type;
70
71
        return $this;
72
    }
73
74
    /**
75
     * Returns bank account type.
76
     *
77
     * @return string
78
     */
79
    public function getType()
80
    {
81
        return $this->getIfSet('type');
82
    }
83
84
    /**
85
     * Set bank number.
86
     *
87
     * @param string $bank_number Bank number.
88
     *
89
     * @return $this
90
     */
91
    public function setBankNumber($bank_number)
92
    {
93
        $this->data->bankNumber = $bank_number;
94
95
        return $this;
96
    }
97
98
    /**
99
     * Returns bank number.
100
     *
101
     * @return string
102
     */
103
    public function getBankNumber()
104
    {
105
        return $this->getIfSet('bankNumber');
106
    }
107
108
    /**
109
     * Set bank account agency number.
110
     *
111
     * @param int $agency_number Bank account agency number.
112
     *
113
     * @return $this
114
     */
115
    public function setAgencyNumber($agency_number)
116
    {
117
        $this->data->agencyNumber = $agency_number;
118
119
        return $this;
120
    }
121
122
    /**
123
     * Returns bank account agency number.
124
     *
125
     * @return int
126
     */
127
    public function getAgencyNumber()
128
    {
129
        return $this->getIfSet('agencyNumber');
130
    }
131
132
    /**
133
     * Set bank account agency check number.
134
     *
135
     * @param int $agency_check_number Bank account agency check number.
136
     *
137
     * @return $this
138
     */
139
    public function setAgencyCheckNumber($agency_check_number)
140
    {
141
        $this->data->agencyCheckNumber = $agency_check_number;
142
143
        return $this;
144
    }
145
146
    /**
147
     * Returns bank account agency check number.
148
     *
149
     * @return int
150
     */
151
    public function getAgencyCheckNumber()
152
    {
153
        return $this->getIfSet('agencyCheckNumber');
154
    }
155
156
    /**
157
     * Set bank account number.
158
     *
159
     * @param int $account_number Bank account number.
160
     *
161
     * @return $this
162
     */
163
    public function setAccountNumber($account_number)
164
    {
165
        $this->data->accountNumber = $account_number;
166
167
        return $this;
168
    }
169
170
    /**
171
     * Returns bank account number.
172
     *
173
     * @return int
174
     */
175
    public function getAccountNumber()
176
    {
177
        return $this->getIfSet('accountNumber');
178
    }
179
180
    /**
181
     * Set bank account check number.
182
     *
183
     * @param int $account_check_number Bank account check number.
184
     *
185
     * @return $this
186
     */
187
    public function setAccountCheckNumber($account_check_number)
188
    {
189
        $this->data->accountCheckNumber = $account_check_number;
190
191
        return $this;
192
    }
193
194
    /**
195
     * Returns bank account check number.
196
     *
197
     * @return int
198
     */
199
    public function getAccountCheckNumber()
200
    {
201
        return $this->getIfSet('accountCheckNumber');
202
    }
203
204
    /**
205
     * Set holder.
206
     *
207
     * @param string $fullname Holder full name.
208
     * @param string $number   Document number.
209
     * @param string $type     Document type (CPF or CNPJ).
210
     *
211
     * @return $this
212
     */
213
    public function setHolder($fullname, $number, $type)
214
    {
215
        $this->data->holder->fullname = $fullname;
216
217
        $this->data->holder->taxDocument->type = $type;
218
        $this->data->holder->taxDocument->number = $number;
219
220
        return $this;
221
    }
222
223
    /**
224
     * Returns holder full name.
225
     *
226
     * @return string
227
     */
228
    public function getFullname()
229
    {
230
        return $this->getIfSet('fullname', $this->data->holder);
231
    }
232
233
    /**
234
     * Get tax document type from customer.
235
     *
236
     * @return string Type of value: CPF and CNPJ
237
     */
238
    public function getTaxDocumentType()
239
    {
240
        return $this->getIfSet('type', $this->data->holder->taxDocument);
241
    }
242
243
    /**
244
     * Get tax document number from customer.
245
     *
246
     * @return string Document Number.
247
     */
248
    public function getTaxDocumentNumber()
249
    {
250
        return $this->getIfSet('number', $this->data->holder->taxDocument);
251
    }
252
253
    /**
254
     * Get a bank account.
255
     *
256
     * @param string $bank_account_id Bank account id.
257
     *
258
     * @return stdClass
259
     */
260
    public function get($bank_account_id)
261
    {
262
        return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $bank_account_id));
263
    }
264
265
    /**
266
     * Create a new BankAccount List instance.
267
     *
268
     * @param string Account id.
269
     *
270
     * @return \Moip\Resource\BankAccountList
271
     */
272
    public function getList($account_id)
273
    {
274
        $bankAccountList = new BankAccountList($this->moip);
275
276
        return $bankAccountList->get($account_id);
277
    }
278
279
    /**
280
     * Create a new bank account.
281
     *
282
     * @param string Account id.
283
     *
284
     * @return stdClass
285
     */
286
    public function create($account_id)
287
    {
288
        return $this->createResource(sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH_ACCOUNT, $account_id, self::PATH));
289
    }
290
291
    /**
292
     * Update a bank account.
293
     *
294
     * @param string|null $bank_account_id Bank account id.
295
     *
296
     * @return stdClass
297
     */
298
    public function update($bank_account_id = null)
299
    {
300
        $bank_account_id = (!empty($bank_account_id) ? $bank_account_id : $this->getId());
301
302
        return $this->updateByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $bank_account_id));
303
    }
304
305
    /**
306
     * Delete a bank account.
307
     *
308
     * @param string $bank_account_id Bank account id.
309
     *
310
     * @return mixed
311
     */
312
    public function delete($bank_account_id)
313
    {
314
        return $this->deleteByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $bank_account_id));
315
    }
316
317
    /**
318
     * Mount the bank account structure.
319
     *
320
     * @param stdClass $response
321
     *
322
     * @return \Moip\Resource\BankAccount
323
     */
324
    protected function populate(stdClass $response)
325
    {
326
        $bank_account = clone $this;
327
        $bank_account->data->id = $this->getIfSet('id', $response);
328
        $bank_account->data->agencyNumber = $this->getIfSet('agencyNumber', $response);
329
        $bank_account->data->accountNumber = $this->getIfSet('accountNumber', $response);
330
        $bank_account->data->status = $this->getIfSet('status', $response);
331
        $bank_account->data->accountCheckNumber = $this->getIfSet('accountCheckNumber', $response);
332
        $bank_account->data->bankName = $this->getIfSet('bankName', $response);
333
        $bank_account->data->type = $this->getIfSet('type', $response);
334
        $bank_account->data->agencyCheckNumber = $this->getIfSet('agencyCheckNumber', $response);
335
        $bank_account->data->bankNumber = $this->getIfSet('bankNumber', $response);
336
337
        $holder = $this->getIfSet('holder', $response);
338
        $bank_account->data->holder = new stdClass();
339
        $bank_account->data->holder->fullname = $this->getIfSet('fullname', $holder);
340
341
        $tax_document = $this->getIfSet('taxDocument', $holder);
342
        $bank_account->data->holder->taxDocument = new stdClass();
343
        $bank_account->data->holder->taxDocument->number = $this->getIfSet('number', $tax_document);
344
        $bank_account->data->holder->taxDocument->type = $this->getIfSet('type', $tax_document);
345
346
        $bank_account->data->_links = $this->getIfSet('_links', $response);
347
        $bank_account->data->createdAt = $this->getIfSet('createdAt', $response);
348
349
        return $bank_account;
350
    }
351
}
352