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 = 'BANK_ACCOUNT'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @const string |
27
|
|
|
*/ |
28
|
|
|
const TYPE = 'CHECKING'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @const string |
32
|
|
|
*/ |
33
|
|
|
const TYPE_HOLD = 'CPF'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Initializes new instances. |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
protected function initialize() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$this->data = new stdClass(); |
41
|
|
|
$this->data->transferInstrument = new stdClass(); |
42
|
|
|
$this->data->transferInstrument->bankAccount = new stdClass(); |
43
|
|
|
$this->data->transferInstrument->bankAccount->holder = new stdClass(); |
44
|
|
|
$this->data->transferInstrument->bankAccount->holder->taxDocument = new stdClass(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param stdClass $response |
49
|
|
|
* |
50
|
|
|
* @return Transfers |
51
|
|
|
*/ |
52
|
|
|
protected function populate(stdClass $response) |
53
|
|
|
{ |
54
|
|
|
$transfers = clone $this; |
55
|
|
|
$transfers->data->id = $this->getIfSet('id', $response); |
56
|
|
|
$transfers->data->amount = $this->getIfSet('amount', $response); |
57
|
|
|
|
58
|
|
|
$transfer_instrument = $this->getIfSet('transferInstrument', $response); |
59
|
|
|
$transfers->data->transferInstrument = new stdClass(); |
60
|
|
|
$transfers->data->transferInstrument->method = $this->getIfSet('method', $transfer_instrument); |
61
|
|
|
|
62
|
|
|
$bank_account = $this->getIfSet('bankAccount', $transfer_instrument); |
63
|
|
|
$transfers->data->transferInstrument->bankAccount = new stdClass(); |
64
|
|
|
$transfers->data->transferInstrument->bankAccount->type = $this->getIfSet('type', $bank_account); |
65
|
|
|
$transfers->data->transferInstrument->bankAccount->bankNumber = $this->getIfSet('bankNumber', $bank_account); |
66
|
|
|
$transfers->data->transferInstrument->bankAccount->agencyNumber = $this->getIfSet('agencyNumber', $bank_account); |
67
|
|
|
$transfers->data->transferInstrument->bankAccount->agencyCheckNumber = $this->getIfSet('agencyCheckNumber', $bank_account); |
68
|
|
|
$transfers->data->transferInstrument->bankAccount->accountNumber = $this->getIfSet('accountNumber', $bank_account); |
69
|
|
|
$transfers->data->transferInstrument->bankAccount->accountCheckNumber = $this->getIfSet('accountCheckNumber', $bank_account); |
70
|
|
|
|
71
|
|
|
$holder = $this->getIfSet('holder', $bank_account); |
72
|
|
|
$transfers->data->transferInstrument->bankAccount->holder = new stdClass(); |
73
|
|
|
$transfers->data->transferInstrument->bankAccount->holder->fullname = $this->getIfSet('fullname', $holder); |
74
|
|
|
|
75
|
|
|
$tax_document = $this->getIfSet('taxDocument', $holder); |
76
|
|
|
$this->data->transferInstrument->bankAccount->holder->taxDocument = new stdClass(); |
77
|
|
|
$this->data->transferInstrument->bankAccount->holder->taxDocument->type = $this->getIfSet('type', $tax_document); |
78
|
|
|
$this->data->transferInstrument->bankAccount->holder->taxDocument->number = $this->getIfSet('number', $tax_document); |
79
|
|
|
|
80
|
|
|
return $transfers; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Set info of transfers. |
85
|
|
|
* |
86
|
|
|
* @param int $amount |
87
|
|
|
* @param string $bankNumber Bank number. possible values: 001, 237, 341, 041. |
88
|
|
|
* @param int $agencyNumber |
89
|
|
|
* @param int $agencyCheckNumber |
90
|
|
|
* @param int $accountNumber |
91
|
|
|
* @param int $accountCheckNumber |
92
|
|
|
* |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function setTransfers( |
96
|
|
|
$amount, |
97
|
|
|
$bankNumber, |
98
|
|
|
$agencyNumber, |
99
|
|
|
$agencyCheckNumber, |
100
|
|
|
$accountNumber, |
101
|
|
|
$accountCheckNumber |
102
|
|
|
) { |
103
|
|
|
$this->data->amount = $amount; |
104
|
|
|
$this->data->transferInstrument->method = self::METHOD; |
105
|
|
|
$this->data->transferInstrument->bankAccount->type = self::TYPE; |
106
|
|
|
$this->data->transferInstrument->bankAccount->bankNumber = $bankNumber; |
107
|
|
|
$this->data->transferInstrument->bankAccount->agencyNumber = $agencyNumber; |
108
|
|
|
$this->data->transferInstrument->bankAccount->agencyCheckNumber = $agencyCheckNumber; |
109
|
|
|
$this->data->transferInstrument->bankAccount->accountNumber = $accountNumber; |
110
|
|
|
$this->data->transferInstrument->bankAccount->accountCheckNumber = $accountCheckNumber; |
111
|
|
|
|
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Returns transfer. |
117
|
|
|
* |
118
|
|
|
* @return stdClass |
119
|
|
|
*/ |
120
|
|
|
public function getTransfers() |
121
|
|
|
{ |
122
|
|
|
return $this->data; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Set info of holder. |
127
|
|
|
* |
128
|
|
|
* @param string $fullname |
129
|
|
|
* @param int $taxDocument |
130
|
|
|
* |
131
|
|
|
* @return $this |
132
|
|
|
*/ |
133
|
|
|
public function setHolder($fullname, $taxDocument) |
134
|
|
|
{ |
135
|
|
|
$this->data->transferInstrument->bankAccount->holder->fullname = $fullname; |
136
|
|
|
$this->data->transferInstrument->bankAccount->holder->taxDocument->type = self::TYPE_HOLD; |
137
|
|
|
$this->data->transferInstrument->bankAccount->holder->taxDocument->number = $taxDocument; |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Returns transfer holder. |
144
|
|
|
* |
145
|
|
|
* @return stdClass |
146
|
|
|
*/ |
147
|
|
|
public function getHolder() |
148
|
|
|
{ |
149
|
|
|
return $this->data->transferInstrument->bankAccount->holder; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Execute Tranfers. |
154
|
|
|
* |
155
|
|
|
* @return Transfers |
156
|
|
|
*/ |
157
|
|
View Code Duplication |
public function execute() |
|
|
|
|
158
|
|
|
{ |
159
|
|
|
$path = sprintf('/%s/%s', MoipResource::VERSION, self::PATH); |
160
|
|
|
|
161
|
|
|
$response = $this->httpRequest($path, Requests::POST, $this); |
162
|
|
|
|
163
|
|
|
return $this->populate($response); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Revert Tranfers. |
168
|
|
|
* |
169
|
|
|
* @param string $id Transfer id. |
170
|
|
|
* |
171
|
|
|
* @return Transfers |
172
|
|
|
*/ |
173
|
|
View Code Duplication |
public function revert($id) |
|
|
|
|
174
|
|
|
{ |
175
|
|
|
$path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $id, 'reverse'); |
176
|
|
|
|
177
|
|
|
$response = $this->httpRequest($path, Requests::POST, $this); |
178
|
|
|
|
179
|
|
|
return $this->populate($response); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* Get a Transfer. |
184
|
|
|
* |
185
|
|
|
* @param string $id Transfer id. |
186
|
|
|
* |
187
|
|
|
* @return stdClass |
188
|
|
|
*/ |
189
|
|
|
public function get($id) |
190
|
|
|
{ |
191
|
|
|
return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $id)); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Create a new Transfers list instance. |
196
|
|
|
* |
197
|
|
|
* @return \Moip\Resource\TransfersList |
198
|
|
|
*/ |
199
|
|
|
public function getList(Pagination $pagination = null, Filters $filters = null, $qParam = '') |
200
|
|
|
{ |
201
|
|
|
$transfersList = new TransfersList($this->moip); |
202
|
|
|
|
203
|
|
|
return $transfersList->get($pagination, $filters, $qParam); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Get MoIP Transfers id. |
208
|
|
|
* |
209
|
|
|
* @return string |
210
|
|
|
*/ |
211
|
|
|
public function getId() |
212
|
|
|
{ |
213
|
|
|
return $this->getIfSet('id'); |
214
|
|
|
} |
215
|
|
|
} |
216
|
|
|
|
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.