|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Moip\Resource; |
|
4
|
|
|
|
|
5
|
|
|
use stdClass; |
|
6
|
|
|
use UnexpectedValueException; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class Account. |
|
10
|
|
|
* |
|
11
|
|
|
* @todo Devo acrescentar transparentAccount? |
|
12
|
|
|
* |
|
13
|
|
|
*/ |
|
14
|
|
|
class Account extends MoipResource |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Path accounts API. |
|
18
|
|
|
* |
|
19
|
|
|
* @const string |
|
20
|
|
|
*/ |
|
21
|
|
|
const PATH = 'accounts'; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Standard country . |
|
25
|
|
|
* |
|
26
|
|
|
* @const string |
|
27
|
|
|
*/ |
|
28
|
|
|
const ADDRESS_COUNTRY = 'BRA'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Standard document type. |
|
32
|
|
|
* |
|
33
|
|
|
* @const string |
|
34
|
|
|
*/ |
|
35
|
|
|
const TAX_DOCUMENT = 'CPF'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Default Account Type |
|
39
|
|
|
* |
|
40
|
|
|
* @var string |
|
41
|
|
|
*/ |
|
42
|
|
|
const ACCOUNT_TYPE = 'MERCHANT'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Initialize a new instance. |
|
46
|
|
|
*/ |
|
47
|
|
|
public function initialize() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->data = new stdClass(); |
|
50
|
|
|
$this->data->email = new stdClass(); |
|
51
|
|
|
$this->data->person = new stdClass(); |
|
52
|
|
|
$this->data->type = self::ACCOUNT_TYPE; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Add a new address to the account. |
|
57
|
|
|
* |
|
58
|
|
|
* @param string $street Street address. |
|
59
|
|
|
* @param string $number Number address. |
|
60
|
|
|
* @param string $district Neighborhood address. |
|
61
|
|
|
* @param string $city City address. |
|
62
|
|
|
* @param string $state State address. |
|
63
|
|
|
* @param string $zip The zip code billing address. |
|
64
|
|
|
* @param string $complement Address complement. |
|
65
|
|
|
* @param string $country Country ISO-alpha3 format, BRA example. |
|
66
|
|
|
* |
|
67
|
|
|
* @return $this |
|
68
|
|
|
*/ |
|
69
|
|
|
public function addAddress($street, $number, $district, $city, $state, $zip, $complement = null, $country = self::ADDRESS_COUNTRY) |
|
70
|
|
|
{ |
|
71
|
|
|
$address = new stdClass(); |
|
72
|
|
|
$address->street = $street; |
|
73
|
|
|
$address->streetNumber = $number; |
|
74
|
|
|
$address->complement = $complement; |
|
75
|
|
|
$address->district = $district; |
|
76
|
|
|
$address->city = $city; |
|
77
|
|
|
$address->state = $state; |
|
78
|
|
|
$address->country = $country; |
|
79
|
|
|
$address->zipCode = $zip; |
|
80
|
|
|
|
|
81
|
|
|
$this->data->person->address = $address; |
|
82
|
|
|
|
|
83
|
|
|
return $this; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Create a new account. |
|
88
|
|
|
* |
|
89
|
|
|
* @return \stdClass |
|
90
|
|
|
*/ |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return stdClass |
|
94
|
|
|
*/ |
|
95
|
|
|
public function create() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->createResource(sprintf('/%s/%s/', MoipResource::VERSION, self::PATH)); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Find a account. |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $moip_id |
|
104
|
|
|
* |
|
105
|
|
|
* @return \Moip\Resource\Account |
|
106
|
|
|
*/ |
|
107
|
|
|
public function get($moip_id) |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $moip_id)); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get account id. |
|
114
|
|
|
* |
|
115
|
|
|
* @return string The buyer id. |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getId() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->getIfSet('id'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Get account address. |
|
124
|
|
|
* |
|
125
|
|
|
* @return \stdClass Account's address. |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getAddress() |
|
128
|
|
|
{ |
|
129
|
|
|
return $this->getIfSet('address', $this->data->person); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Get account fullname. |
|
134
|
|
|
* |
|
135
|
|
|
* @return string Account's full name. |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getFullname() |
|
138
|
|
|
{ |
|
139
|
|
|
return $this->getIfSet('name', $this->data->person) . ' ' . $this->getIfSet('lastName', $this->data->person); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Get birth date from account. |
|
144
|
|
|
* |
|
145
|
|
|
* @return \DateTime|null Date of birth of the credit card holder. |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getBirthDate() |
|
148
|
|
|
{ |
|
149
|
|
|
return $this->getIfSetDate('birthDate', $this->data->person); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Get phone area code from account. |
|
154
|
|
|
* |
|
155
|
|
|
* @return int DDD telephone. |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getPhoneAreaCode() |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->getIfSet('areaCode', $this->data->person->phone); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Get phone country code from account. |
|
164
|
|
|
* |
|
165
|
|
|
* @return int Country code. |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getPhoneCountryCode() |
|
168
|
|
|
{ |
|
169
|
|
|
return $this->getIfSet('countryCode', $this->data->person->phone); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Get phone number from account. |
|
174
|
|
|
* |
|
175
|
|
|
* @return int Telephone number. |
|
176
|
|
|
*/ |
|
177
|
|
|
public function getPhoneNumber() |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->getIfSet('number', $this->data->person->phone); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Get tax document type from account. |
|
184
|
|
|
* |
|
185
|
|
|
* @return string Type of value: CPF and CNPJ |
|
186
|
|
|
*/ |
|
187
|
|
|
public function getTaxDocumentType() |
|
188
|
|
|
{ |
|
189
|
|
|
return $this->getIfSet('type', $this->data->person->taxDocument); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Get tax document number from account. |
|
194
|
|
|
* |
|
195
|
|
|
* @return string Document Number. |
|
196
|
|
|
*/ |
|
197
|
|
|
public function getTaxDocumentNumber() |
|
198
|
|
|
{ |
|
199
|
|
|
return $this->getIfSet('number', $this->data->person->taxDocument); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Get account type. |
|
204
|
|
|
* |
|
205
|
|
|
* @return string Document Number. |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getType() |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->getIfSet('type', $this->data); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* Mount the seller structure from account. |
|
214
|
|
|
* |
|
215
|
|
|
* @param \stdClass $response |
|
216
|
|
|
* |
|
217
|
|
|
* @return \Moip\Resource\Account Account data |
|
218
|
|
|
*/ |
|
219
|
|
|
protected function populate(stdClass $response) |
|
220
|
|
|
{ |
|
221
|
|
|
$account = clone $this; |
|
222
|
|
|
$account->data->email = new stdClass(); |
|
223
|
|
|
|
|
224
|
|
|
$email = $this->getIfSet('email', $response); |
|
225
|
|
|
|
|
226
|
|
|
$account->data->email->address = $this->getIfSet('address', $email); |
|
227
|
|
|
$account->data->person = new stdClass(); |
|
228
|
|
|
|
|
229
|
|
|
$person = $this->getIfSet('person', $response); |
|
230
|
|
|
|
|
231
|
|
|
$account->data->person->name = $this->getIfSet('name', $person); |
|
232
|
|
|
$account->data->person->lastName = $this->getIfSet('lastName', $person); |
|
233
|
|
|
$account->data->person->taxDocument = new stdClass(); |
|
234
|
|
|
|
|
235
|
|
|
$taxDocument = $this->getIfSet('taxDocument', $person); |
|
236
|
|
|
|
|
237
|
|
|
$account->data->person->taxDocument->type = $this->getIfSet('type', $taxDocument); |
|
238
|
|
|
$account->data->person->taxDocument->number = $this->getIfSet('number', $taxDocument); |
|
239
|
|
|
$account->data->person->phone = new stdClass(); |
|
240
|
|
|
|
|
241
|
|
|
$phone = $this->getIfSet('phone', $person); |
|
242
|
|
|
|
|
243
|
|
|
$account->data->person->phone->countryCode = $this->getIfSet('countryCode', $phone); |
|
244
|
|
|
$account->data->person->phone->areaCode = $this->getIfSet('areaCode', $phone); |
|
245
|
|
|
$account->data->person->phone->number = $this->getIfSet('number', $phone); |
|
246
|
|
|
$account->data->person->identityDocument = new stdClass(); |
|
247
|
|
|
|
|
248
|
|
|
$identityDocument = $this->getIfSet('identityDocument', $person); |
|
249
|
|
|
|
|
250
|
|
|
$account->data->person->identityDocument->type = $this->getIfSet('type', $identityDocument); |
|
251
|
|
|
$account->data->person->identityDocument->number = $this->getIfSet('number', $identityDocument); |
|
252
|
|
|
$account->data->person->identityDocument->issuer = $this->getIfSet('issuer', $identityDocument); |
|
253
|
|
|
$account->data->person->identityDocument->issueDate = $this->getIfSet('issueDate', $identityDocument); |
|
254
|
|
|
|
|
255
|
|
|
$account->data->person->birthDate = $this->getIfSet('birthDate', $person); |
|
256
|
|
|
$account->data->person->address = $this->getIfSet('address', $person); |
|
257
|
|
|
$account->data->_links = $this->getIfSet('_links', $response); |
|
258
|
|
|
$account->data->type = $this->getIfSet('type', $response); |
|
259
|
|
|
|
|
260
|
|
|
return $account; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* Set e-mail from account. |
|
265
|
|
|
* |
|
266
|
|
|
* @param string $email Email account. |
|
267
|
|
|
* |
|
268
|
|
|
* @return \Moip\Resource\Account |
|
269
|
|
|
*/ |
|
270
|
|
|
public function setEmail($email) |
|
271
|
|
|
{ |
|
272
|
|
|
$this->data->email->address = $email; |
|
273
|
|
|
|
|
274
|
|
|
return $this; |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* Set name from account. |
|
279
|
|
|
* |
|
280
|
|
|
* @param string $name Account's person name. |
|
281
|
|
|
* |
|
282
|
|
|
* @return \Moip\Resource\Account |
|
283
|
|
|
*/ |
|
284
|
|
|
public function setName($name) |
|
285
|
|
|
{ |
|
286
|
|
|
$this->data->person->name = $name; |
|
287
|
|
|
|
|
288
|
|
|
return $this; |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* Set name from account. |
|
293
|
|
|
* |
|
294
|
|
|
* @param string $name Account's person name. |
|
|
|
|
|
|
295
|
|
|
* |
|
296
|
|
|
* @return \Moip\Resource\Account |
|
297
|
|
|
*/ |
|
298
|
|
|
public function setLastName($lastname) |
|
299
|
|
|
{ |
|
300
|
|
|
$this->data->person->lastName = $lastname; |
|
301
|
|
|
|
|
302
|
|
|
return $this; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* Set birth date from account. |
|
307
|
|
|
* |
|
308
|
|
|
* @param \DateTime|string $birthDate Date of birth of the credit card holder. |
|
309
|
|
|
* |
|
310
|
|
|
* @return \Moip\Resource\Account |
|
311
|
|
|
*/ |
|
312
|
|
View Code Duplication |
public function setBirthDate($birthDate) |
|
|
|
|
|
|
313
|
|
|
{ |
|
314
|
|
|
if ($birthDate instanceof \DateTime) { |
|
315
|
|
|
$birthDate = $birthDate->format('Y-m-d'); |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
$this->data->person->birthDate = $birthDate; |
|
319
|
|
|
|
|
320
|
|
|
return $this; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* Set tax document from account. |
|
325
|
|
|
* |
|
326
|
|
|
* @param string $number Document number. |
|
327
|
|
|
* @param string $type Document type. |
|
328
|
|
|
* |
|
329
|
|
|
* @return \Moip\Resource\Account |
|
330
|
|
|
*/ |
|
331
|
|
View Code Duplication |
public function setTaxDocument($number, $type = self::TAX_DOCUMENT) |
|
|
|
|
|
|
332
|
|
|
{ |
|
333
|
|
|
$this->data->person->taxDocument = new stdClass(); |
|
334
|
|
|
$this->data->person->taxDocument->type = $type; |
|
335
|
|
|
$this->data->person->taxDocument->number = $number; |
|
336
|
|
|
|
|
337
|
|
|
return $this; |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
/** |
|
341
|
|
|
* Set phone from account. |
|
342
|
|
|
* |
|
343
|
|
|
* @param int $areaCode DDD telephone. |
|
344
|
|
|
* @param int $number Telephone number. |
|
345
|
|
|
* @param int $countryCode Country code. |
|
346
|
|
|
* |
|
347
|
|
|
* @return \Moip\Resource\Account |
|
348
|
|
|
*/ |
|
349
|
|
|
public function setPhone($areaCode, $number, $countryCode = 55) |
|
350
|
|
|
{ |
|
351
|
|
|
$this->data->person->phone = new stdClass(); |
|
352
|
|
|
$this->data->person->phone->countryCode = $countryCode; |
|
353
|
|
|
$this->data->person->phone->areaCode = $areaCode; |
|
354
|
|
|
$this->data->person->phone->number = $number; |
|
355
|
|
|
|
|
356
|
|
|
return $this; |
|
357
|
|
|
} |
|
358
|
|
|
|
|
359
|
|
|
/** |
|
360
|
|
|
* Set identity document from account. |
|
361
|
|
|
* |
|
362
|
|
|
* @param string $number Número do documento. |
|
363
|
|
|
* @param string $issuer Emissor do documento. |
|
364
|
|
|
* @param \DateTime|string $birthDate $issueDate Data de emissão do documento. |
|
|
|
|
|
|
365
|
|
|
* @param string $type Tipo do documento. Valores possíveis: RG. |
|
366
|
|
|
* |
|
367
|
|
|
* @return \Moip\Resource\Account |
|
368
|
|
|
*/ |
|
369
|
|
|
public function setIdentityDocument($number, $issuer, $issueDate, $type = 'RG') |
|
370
|
|
|
{ |
|
371
|
|
|
$this->data->person->identityDocument = new stdClass(); |
|
372
|
|
|
$this->data->person->identityDocument->type = $type; |
|
373
|
|
|
$this->data->person->identityDocument->number = $number; |
|
374
|
|
|
$this->data->person->identityDocument->issuer = $issuer; |
|
375
|
|
|
$this->data->person->identityDocument->issueDate = $issueDate; |
|
376
|
|
|
|
|
377
|
|
|
return $this; |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
/** |
|
381
|
|
|
* Set account type. Possible values: CONSUMER, MERCHANT. |
|
382
|
|
|
* |
|
383
|
|
|
* @param string $type |
|
384
|
|
|
* |
|
385
|
|
|
* @return \Moip\Resource\Account |
|
386
|
|
|
*/ |
|
387
|
|
|
public function setType($type) |
|
388
|
|
|
{ |
|
389
|
|
|
$this->data->type = $type; |
|
390
|
|
|
|
|
391
|
|
|
return $this; |
|
392
|
|
|
} |
|
393
|
|
|
} |
|
394
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.