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