Completed
Pull Request — master (#288)
by
unknown
05:42
created

Transfers::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Resource;
4
5
use Moip\Helper\Filters;
6
use Moip\Helper\Pagination;
7
use Requests;
8
use stdClass;
9
10
/**
11
 * Class Transfers.
12
 */
13
class Transfers extends MoipResource
14
{
15
    /**
16
     * @const string
17
     */
18
    const PATH = 'transfers';
19
20
    /**
21
     * @const string
22
     */
23
    const METHOD_BKA = 'BANK_ACCOUNT';
24
25
    /**
26
     * @const string
27
     */
28
    const METHOD_MPA = 'MOIP_ACCOUNT';
29
30
    /**
31
     * @const string
32
     */
33
    const TYPE = 'CHECKING';
34
35
    /**
36
     * Initializes new instances.
37
     */
38 View Code Duplication
    protected function initialize()
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...
39
    {
40
        $this->data = new stdClass();
41
        $this->data->transferInstrument = new stdClass();
42
        $this->data->transferInstrument->moipAccount = new stdClass();
43
        $this->data->transferInstrument->bankAccount = new stdClass();
44
        $this->data->transferInstrument->bankAccount->holder = new stdClass();
45
        $this->data->transferInstrument->bankAccount->holder->taxDocument = new stdClass();
46
    }
47
48
    /**
49
     * @param stdClass $response
50
     *
51
     * @return Transfers
52
     */
53
    protected function populate(stdClass $response)
54
    {
55
        $transfers = clone $this;
56
57
        $transfers->data->id = $this->getIfSet('id', $response);
58
        $transfers->data->ownId = $this->getIfSet('ownId', $response);
59
        $transfers->data->amount = $this->getIfSet('amount', $response);
60
61
        $transferInstrument = $this->getIfSet('transferInstrument', $response);
62
        $transfers->data->transferInstrument = new stdClass();
63
        $transfers->data->transferInstrument->method = $this->getIfSet('method', $transferInstrument);
64
65
        $moipAccount = $this->getIfSet('moipAccount', $transferInstrument);
66
        $transfers->data->transferInstrument->moipAccount = new stdClass();
67
        $transfers->data->transferInstrument->moipAccount->id = $this->getIfSet('id', $moipAccount);
68
69
        $bankAccount = $this->getIfSet('bankAccount', $transferInstrument);
70
        $transfers->data->transferInstrument->bankAccount = new stdClass();
71
        $transfers->data->transferInstrument->bankAccount->id = $this->getIfSet('id', $bankAccount);
72
        $transfers->data->transferInstrument->bankAccount->type = $this->getIfSet('type', $bankAccount);
73
        $transfers->data->transferInstrument->bankAccount->bankNumber = $this->getIfSet('bankNumber', $bankAccount);
74
        $transfers->data->transferInstrument->bankAccount->agencyNumber = $this->getIfSet('agencyNumber', $bankAccount);
75
        $transfers->data->transferInstrument->bankAccount->agencyCheckNumber = $this->getIfSet('agencyCheckNumber', $bankAccount);
76
        $transfers->data->transferInstrument->bankAccount->accountNumber = $this->getIfSet('accountNumber', $bankAccount);
77
        $transfers->data->transferInstrument->bankAccount->accountCheckNumber = $this->getIfSet('accountCheckNumber', $bankAccount);
78
79
        $holder = $this->getIfSet('holder', $bankAccount);
80
        $transfers->data->transferInstrument->bankAccount->holder = new stdClass();
81
        $transfers->data->transferInstrument->bankAccount->holder->fullname = $this->getIfSet('fullname', $holder);
82
83
        $tax_document = $this->getIfSet('taxDocument', $holder);
84
        $this->data->transferInstrument->bankAccount->holder->taxDocument = new stdClass();
85
        $this->data->transferInstrument->bankAccount->holder->taxDocument->type = $this->getIfSet('type', $tax_document);
86
        $this->data->transferInstrument->bankAccount->holder->taxDocument->number = $this->getIfSet('number', $tax_document);
87
88
        return $transfers;
89
    }
90
91
    /**
92
     * Set the amount of transfer.
93
     *
94
     * @param int $amount
95
     *
96
     * @return $this
97
     */
98
    public function setAmount($amount)
99
    {
100
        $this->data->amount = $amount;
101
102
        return $this;
103
    }
104
105
    /**
106
     * Returns amount.
107
     *
108
     * @return amount
109
     */
110
    public function getAmount()
111
    {
112
        return $this->data->amount;
113
    }
114
115
    /**
116
     * Set the bank accout transfer.
117
     *
118
     * @param string $bankNumber         Bank number. possible values: 001, 237, 341, 041.
119
     * @param int    $agencyNumber
120
     * @param int    $agencyCheckNumber
121
     * @param int    $accountNumber
122
     * @param int    $accountCheckNumber
123
     *
124
     * @return $this
125
     */
126
    public function transferToBankAccount(
127
        $bankNumber,
128
        $agencyNumber,
129
        $agencyCheckNumber,
130
        $accountNumber,
131
        $accountCheckNumber
132
    ) {
133
        $this->data->transferInstrument->method = self::METHOD_BKA;
134
        $this->data->transferInstrument->bankAccount->type = self::TYPE;
135
        $this->data->transferInstrument->bankAccount->bankNumber = $bankNumber;
136
        $this->data->transferInstrument->bankAccount->agencyNumber = $agencyNumber;
137
        $this->data->transferInstrument->bankAccount->agencyCheckNumber = $agencyCheckNumber;
138
        $this->data->transferInstrument->bankAccount->accountNumber = $accountNumber;
139
        $this->data->transferInstrument->bankAccount->accountCheckNumber = $accountCheckNumber;
140
141
        return $this;
142
    }
143
144
    /**
145
     * Set the ID of a saved bank account.
146
     *
147
     * @param string $bankAccountId Saved bank account ID (BKA-XXXXXXX).
148
     *
149
     * @return $this
150
     */
151
    public function transferWithBankAccountId($bankAccountId)
152
    {
153
        $this->data->transferInstrument->method = self::METHOD_BKA;
154
        $this->data->transferInstrument->bankAccount->id = $bankAccountId;
155
156
        return $this;
157
    }
158
159
    /**
160
     * Set the Moip Account ID to create a transfer to this account.
161
     *
162
     * @param string $moipAccountId The Moip Account ID (MPA-XXXXXXX)
163
     */
164
    public function transferToMoipAccount($moipAccountId)
165
    {
166
        $this->data->transferInstrument->method = self::METHOD_MPA;
167
        $this->data->transferInstrument->moipAccount->id = $moipAccountId;
168
169
        return $this;
170
    }
171
172
    /**
173
     * Returns transfer.
174
     *
175
     * @return stdClass
176
     */
177
    public function getTransfers()
178
    {
179
        return $this->data;
180
    }
181
182
    /**
183
     * Get own request id. external reference.
184
     *
185
     * @param mixed $ownId id
186
     *
187
     * @return $this
188
     */
189
    public function setOwnId($ownId)
190
    {
191
        $this->data->ownId = $ownId;
192
193
        return $this;
194
    }
195
196
    /**
197
     * Set info of holder.
198
     *
199
     * @param string $fullname
200
     * @param int    $taxDocument
0 ignored issues
show
Documentation introduced by
There is no parameter named $taxDocument. Did you maybe mean $taxDocumentNumber?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
201
     *
202
     * @return $this
203
     */
204
    public function setHolder($fullname, $taxDocumentNumber, $taxDocumentType = 'CPF')
205
    {
206
        $this->data->transferInstrument->bankAccount->holder->fullname = $fullname;
207
        $this->data->transferInstrument->bankAccount->holder->taxDocument->type = $taxDocumentType;
208
        $this->data->transferInstrument->bankAccount->holder->taxDocument->number = $taxDocumentNumber;
209
210
        return $this;
211
    }
212
213
    /**
214
     * Returns transfer holder.
215
     *
216
     * @return stdClass
217
     */
218
    public function getHolder()
219
    {
220
        return $this->data->transferInstrument->bankAccount->holder;
221
    }
222
223
    /**
224
     * Execute Tranfers.
225
     *
226
     * @return Transfers
227
     */
228 View Code Duplication
    public function execute()
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...
229
    {
230
        $path = sprintf('/%s/%s', MoipResource::VERSION, self::PATH);
231
232
        $response = $this->httpRequest($path, Requests::POST, $this);
233
234
        return $this->populate($response);
235
    }
236
237
    /**
238
     * Revert Tranfers.
239
     *
240
     * @param string $id Transfer id.
241
     *
242
     * @return Transfers
243
     */
244 View Code Duplication
    public function revert($id)
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...
245
    {
246
        $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $id, 'reverse');
247
248
        $response = $this->httpRequest($path, Requests::POST, $this);
249
250
        return $this->populate($response);
251
    }
252
253
    /**
254
     * Get a Transfer.
255
     *
256
     * @param string $id Transfer id.
257
     *
258
     * @return stdClass
259
     */
260
    public function get($id)
261
    {
262
        return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $id));
263
    }
264
265
    /**
266
     * Create a new Transfers list instance.
267
     *
268
     * @return \Moip\Resource\TransfersList
269
     */
270
    public function getList(Pagination $pagination = null, Filters $filters = null, $qParam = '')
271
    {
272
        $transfersList = new TransfersList($this->moip);
273
274
        return $transfersList->get($pagination, $filters, $qParam);
275
    }
276
277
    /**
278
     * Get MoIP Transfers id.
279
     *
280
     * @return string
281
     */
282
    public function getId()
283
    {
284
        return $this->getIfSet('id');
285
    }
286
287
    /**
288
     * Get own request id. external reference.
289
     *
290
     * @return mixed
291
     */
292
    public function getOwnId()
293
    {
294
        return $this->getIfSet('ownId');
295
    }
296
}
297