Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 14256c0

Browse files
committed
feat(account): added missing properties to account
1 parent dbf0fcd commit 14256c0

File tree

5 files changed

+178
-38
lines changed

5 files changed

+178
-38
lines changed

src/Resource/Account.php

+112-4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,36 @@ public function getId()
163163
return $this->getIfSet('id');
164164
}
165165

166+
/**
167+
* Get account access token.
168+
*
169+
* @return string
170+
*/
171+
public function getAccessToken()
172+
{
173+
return $this->getIfSet('accessToken');
174+
}
175+
176+
/**
177+
* Get account channel ID.
178+
*
179+
* @return string
180+
*/
181+
public function getChannelId()
182+
{
183+
return $this->getIfSet('channelId');
184+
}
185+
186+
/**
187+
* Get account login.
188+
*
189+
* @return string The buyer login.
190+
*/
191+
public function getLogin()
192+
{
193+
return $this->getIfSet('login');
194+
}
195+
166196
/**
167197
* Get account address.
168198
*
@@ -233,6 +263,56 @@ public function getTaxDocumentType()
233263
return $this->getIfSet('type', $this->data->person->taxDocument);
234264
}
235265

266+
/**
267+
* Get tax document number from account.
268+
*
269+
* @return string Document Number.
270+
*/
271+
public function getTaxDocumentNumber()
272+
{
273+
return $this->getIfSet('number', $this->data->person->taxDocument);
274+
}
275+
276+
/**
277+
* Get identity document number from account.
278+
*
279+
* @return string
280+
*/
281+
public function getIdentityDocumentNumber()
282+
{
283+
return $this->getIfSet('number', $this->data->person->identityDocument);
284+
}
285+
286+
/**
287+
* Get identity document issuer from account.
288+
*
289+
* @return string
290+
*/
291+
public function getIdentityDocumentIssuer()
292+
{
293+
return $this->getIfSet('issuer', $this->data->person->identityDocument);
294+
}
295+
296+
/**
297+
* Get identity document issue date from account.
298+
*
299+
* @return \DateTime
300+
*/
301+
public function getIdentityDocumentIssueDate()
302+
{
303+
return $this->getIfSet('issueDate', $this->data->person->identityDocument);
304+
}
305+
306+
/**
307+
* Get identity document type from account.
308+
*
309+
* @return string Type of value: RG
310+
*/
311+
public function getIdentityDocumentType()
312+
{
313+
return $this->getIfSet('type', $this->data->person->identityDocument);
314+
}
315+
236316
/**
237317
* Get alternative phones.
238318
*
@@ -254,13 +334,23 @@ public function getCompany()
254334
}
255335

256336
/**
257-
* Get tax document number from account.
337+
* Get email address.
258338
*
259-
* @return string Document Number.
339+
* @return string
260340
*/
261-
public function getTaxDocumentNumber()
341+
public function getEmailAddress()
262342
{
263-
return $this->getIfSet('number', $this->data->person->taxDocument);
343+
return $this->getIfSet('address', $this->data->email);
344+
}
345+
346+
/**
347+
* Get email confirmed.
348+
*
349+
* @return boolean
350+
*/
351+
public function getEmailConfirmed()
352+
{
353+
return $this->getIfSet('confirmed', $this->data->email);
264354
}
265355

266356
/**
@@ -273,6 +363,16 @@ public function getType()
273363
return $this->getIfSet('type', $this->data);
274364
}
275365

366+
/**
367+
* Get transparent account (true/false).
368+
*
369+
* @return boolean
370+
*/
371+
public function getTransparentAccount()
372+
{
373+
return $this->getIfSet('transparentAccount', $this->data);
374+
}
375+
276376
/**
277377
* Mount the seller structure from account.
278378
*
@@ -288,6 +388,11 @@ protected function populate(stdClass $response)
288388
$email = $this->getIfSet('email', $response);
289389

290390
$account->data->email->address = $this->getIfSet('address', $email);
391+
392+
$account->data->email->confirmed = $this->getIfSet('confirmed', $email);
393+
394+
$account->data->login = $this->getIfSet('login', $response);
395+
291396
$account->data->person = new stdClass();
292397

293398
$person = $this->getIfSet('person', $response);
@@ -325,6 +430,9 @@ protected function populate(stdClass $response)
325430
$account->data->_links = $this->getIfSet('_links', $response);
326431
$account->data->type = $this->getIfSet('type', $response);
327432
$account->data->id = $this->getIfSet('id', $response);
433+
$account->data->accessToken = $this->getIfSet('accessToken', $response);
434+
$account->data->channelId = $this->getIfSet('channelId', $response);
435+
$account->data->transparentAccount = $this->getIfSet('transparentAccount', $response);
328436

329437
return $account;
330438
}

tests/Resource/AccountTest.php

+55-31
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,64 @@ class AccountTest extends TestCase
1111
{
1212
public function testShouldCreateAccount()
1313
{
14-
$this->mockHttpSession($this->body_moip_account);
14+
$this->mockHttpSession($this->body_moip_account_create);
1515

1616
$account = $this->moip->accounts()
17-
->setName('Fulano')
18-
->setLastName('De Tal')
19-
->setEmail('fulano@email2.com')
20-
->setIdentityDocument('4737283560', 'SSP', '2015-06-23')
21-
->setBirthDate('1988-12-30')
22-
->setTaxDocument('16262131000')
17+
->setName('For tests')
18+
->setLastName('Mine Customer Company')
19+
->setEmail('fortestsminecustomercompany@mailinator.com')
20+
->setIdentityDocument('144563480', 'SSP', '2017-10-25')
21+
->setBirthDate('1990-01-01')
22+
->setTaxDocument('02822921873')
2323
->setType('MERCHANT')
24-
->setPhone(11, 66778899, 55)
25-
->addAlternativePhone(11, 66448899, 55)
26-
->addAlternativePhone(11, 66338899, 55)
27-
->setTransparentAccount(true)
28-
->addAddress('Rua de teste', 123, 'Bairro', 'Sao Paulo', 'SP', '01234567', 'Apt. 23', 'BRA')
24+
->setPhone(11, 965213244, 55)
25+
->addAlternativePhone(11, 912345678, 55)
26+
->setTransparentAccount(false)
27+
->addAddress('Av. Brigadeiro Faria Lima', 2927, 'Itaim', 'São Paulo', 'SP', '01234000', 'Apt. X', 'BRA')
2928
->create();
3029

3130
$this->assertNotEmpty($account->getId());
31+
$this->assertNotEmpty($account->getAccessToken());
32+
//$this->assertNotEmpty($account->getchannelId());
33+
$this->assertEquals('144563480', $account->getIdentityDocumentNumber());
34+
$this->assertEquals('SSP', $account->getIdentityDocumentIssuer());
35+
$this->assertEquals('2017-10-25', $account->getIdentityDocumentIssueDate());
36+
$this->assertEquals('RG', $account->getIdentityDocumentType());
3237
}
3338

3439
public function testShouldCreateAccountWithCompany()
3540
{
36-
$this->mockHttpSession($this->body_moip_account);
41+
$this->mockHttpSession($this->body_moip_account_create);
3742

3843
$account = $this->moip->accounts()
39-
->setName('Fulano')
40-
->setLastName('De Tal')
41-
->setEmail('fulano@email2.com')
42-
->setIdentityDocument('4737283560', 'SSP', '2015-06-23')
43-
->setBirthDate('1988-12-30')
44-
->setTaxDocument('16262131000')
44+
->setName('For tests')
45+
->setLastName('Mine Customer Company')
46+
->setEmail('fortestsminecustomercompany@mailinator.com')
47+
->setIdentityDocument('144563480', 'SSP', '2017-10-25')
48+
->setBirthDate('1990-01-01')
49+
->setTaxDocument('02822921873')
4550
->setType('MERCHANT')
46-
->setPhone(11, 66778899, 55)
47-
->addAlternativePhone(11, 66448899, 55)
48-
->addAlternativePhone(11, 66338899, 55)
49-
->setTransparentAccount(true)
50-
->addAddress('Rua de teste', 123, 'Bairro', 'Sao Paulo', 'SP', '01234567', 'Apt. 23', 'BRA')
51-
->setCompanyName('Empresa Teste', 'Teste Empresa ME')
51+
->setPhone(11, 965213244, 55)
52+
->addAlternativePhone(11, 912345678, 55)
53+
->setTransparentAccount(false)
54+
->addAddress('Av. Brigadeiro Faria Lima', 2927, 'Itaim', 'São Paulo', 'SP', '01234000', 'Apt. X', 'BRA')
55+
->setCompanyName('Mine Customer Company', 'Company Business')
5256
->setCompanyOpeningDate('2011-01-01')
53-
->setCompanyPhone(11, 66558899, 55)
54-
->setCompanyTaxDocument('69086878000198')
55-
->setCompanyAddress('Rua de teste 2', 123, 'Bairro Teste', 'Sao Paulo', 'SP', '01234567', 'Apt. 23', 'BRA')
56-
->setCompanyMainActivity('82.91-1/00', 'Atividades de cobranças e informações cadastrais')
57+
->setCompanyPhone(11, 987654321, 55)
58+
->setCompanyTaxDocument('64893609000110')
59+
->setCompanyAddress('R. Company', 321, 'Bairro Company', 'São Paulo', 'SP', '12345678', 'Ap. Y', 'BRA')
60+
->setCompanyMainActivity('82.91-1/00', 'Test')
5761
->create();
5862

5963
$this->assertNotEmpty($account->getId());
60-
$this->assertEquals('66448899', $account->getAlternativePhones()[0]->number);
61-
$this->assertEquals('Teste Empresa ME', $account->getCompany()->businessName);
64+
$this->assertNotEmpty($account->getAccessToken());
65+
$this->assertNotEmpty($account->getchannelId());
66+
$this->assertEquals('144563480', $account->getIdentityDocumentNumber());
67+
$this->assertEquals('SSP', $account->getIdentityDocumentIssuer());
68+
$this->assertEquals('2017-10-25', $account->getIdentityDocumentIssueDate());
69+
$this->assertEquals('RG', $account->getIdentityDocumentType());
70+
$this->assertEquals('912345678', $account->getAlternativePhones()[0]->number);
71+
$this->assertEquals('Company Business', $account->getCompany()->businessName);
6272
}
6373

6474
public function testCheckExistingAccount()
@@ -72,4 +82,18 @@ public function testCheckNonExistingAccount()
7282
$this->mockHttpSession('', 404);
7383
$this->assertFalse($this->moip->accounts()->checkExistence('412.309.725-10'));
7484
}
85+
86+
public function testShouldGetAccount()
87+
{
88+
$this->mockHttpSession($this->body_moip_account_get);
89+
$account_id = 'MPA-7E9B1F907512';
90+
$account = $this->moip->accounts()->get($account_id);
91+
92+
$this->assertNotEmpty($account->getId());
93+
$this->assertEquals(false, $account->getTransparentAccount());
94+
$this->assertEquals('fortestsminecustomer@mailinator.com', $account->getLogin());
95+
$this->assertEquals(true, $account->getEmailConfirmed());
96+
$this->assertEquals('fortestsminecustomer@mailinator.com', $account->getEmailAddress());
97+
$this->assertEquals('794.663.228-26', $account->getTaxDocumentNumber());
98+
}
7599
}

tests/TestCase.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,12 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
9393
/**
9494
* @var string response from moip API.
9595
*/
96-
protected $body_moip_account;
96+
protected $body_moip_account_create;
97+
98+
/**
99+
* @var string response from moip API.
100+
*/
101+
protected $body_moip_account_get;
97102

98103
/**
99104
* @var string response from moip API.
@@ -157,7 +162,9 @@ public function __construct()
157162

158163
$this->body_notification_preference = $this->readJsonFile('jsons/notification/create');
159164

160-
$this->body_moip_account = $this->readJsonFile('jsons/account/create');
165+
$this->body_moip_account_create = $this->readJsonFile('jsons/account/create');
166+
167+
$this->body_moip_account_get = $this->readJsonFile('jsons/account/get');
161168

162169
$this->body_order_list = $this->readJsonFile('jsons/order/get_list');
163170

tests/jsons/account/create.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"id":"MPA-CB428374873D","login":"fulano@email2.com","accessToken":"f16fee8779d84e8ba91588b443b665c6_v2","channelId":"APP-18JTHC3LEMT9","type":"MERCHANT","transparentAccount":true,"email":{"address":"fulano@email2.com","confirmed":false},"person":{"name":"Fulano","lastName":"De Tal","birthDate":"1988-12-30","taxDocument":{"type":"CPF","number":"162.621.310-00"},"address":{"street":"Rua de teste","streetNumber":"123","district":"Bairro","zipcode":"01234567","zipCode":"01234567","city":"Sao Paulo","state":"SP","country":"BRA","complement":"Apt. 23"},"phone":{"countryCode":"55","areaCode":"11","number":"66778899"},"identityDocument":{"number":"4737283560","issuer":"SSP","issueDate":"2015-06-23","type":"RG"},"alternativePhones":[{"countryCode":"55","areaCode":"11","number":"66448899"},{"countryCode":"55","areaCode":"11","number":"66338899"}]},"company":{"name":"Empresa Teste","businessName":"Teste Empresa ME","taxDocument":{"type":"CNPJ","number":"69.086.878/0001-98"},"address":{"street":"Rua de teste 2","streetNumber":"123","district":"Bairro Teste","zipcode":"01234567","zipCode":"01234567","city":"Sao Paulo","state":"SP","country":"BRA","complement":"Apt. 23"},"phone":{"countryCode":"55","areaCode":"11","number":"66558899"},"openingDate":"2011-01-01"},"createdAt":"2017-07-10T13:42:19.967Z","_links":{"self":{"href":"https://sandbox.moip.com.br/moipaccounts/MPA-CB428374873D","title":null}}}
1+
{"id":"MPA-61B1FE0940A2","login":"fortestsminecustomercompany@mailinator.com","accessToken":"dbb1cee101444f7a9f74c576854b9103_v2","channelId":"APP-QGAGZRIX1CUF","type":"MERCHANT","transparentAccount":true,"email":{"address":"fortestsminecustomercompany@mailinator.com","confirmed":false},"person":{"name":"For tests","lastName":"Mine Customer Company","birthDate":"1990-01-01","taxDocument":{"type":"CPF","number":"028.229.218-73"},"address":{"street":"Av. Brigadeiro Faria Lima","streetNumber":"2927","district":"Itaim","zipcode":"01234000","zipCode":"01234000","city":"São Paulo","state":"SP","country":"BRA","complement":"Ap. X"},"phone":{"countryCode":"55","areaCode":"11","number":"965213244","verified":false,"phoneType":"not_informed"},"nationality":"BRA","identityDocument":{"number":"144563480","issuer":"SSP","issueDate":"2017-10-25","type":"RG"},"alternativePhones":[{"countryCode":"55","areaCode":"11","number":"912345678","verified":false,"phoneType":"not_informed"}],"birthPlace":"São Paulo","parentsName":{"father":"Father of Mine Customer","mother":"Mother of Mine Customer"}},"company":{"name":"Mine Customer Company","businessName":"Company Business","taxDocument":{"type":"CNPJ","number":"64.893.609/0001-10"},"address":{"street":"R. Company","streetNumber":"321","district":"Bairro Company","zipcode":"12345678","zipCode":"12345678","city":"São Paulo","state":"SP","country":"BRA","complement":"Ap. Y"},"phone":{"countryCode":"55","areaCode":"11","number":"987654321","verified":false,"phoneType":"not_informed"},"openingDate":"2017-10-20"},"businessSegment":{"id":33,"name":"Jogos online","mcc":null},"site":"https://www.meusite.com","createdAt":"2017-10-25T14:05:46.050Z","_links":{"self":{"href":"https://sandbox.moip.com.br/moipaccounts/MPA-61B1FE0940A2","title":null}}}

tests/jsons/account/get.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"id":"MPA-7E9B1F907512","person":{"lastName":"For Tests","phone":{"areaCode":"11","countryCode":"55","number":"965213244"},"parentsName":{"mother":"","father":""},"address":{"zipcode":"01234-000","zipCode":"01234-000","street":"Av. Brigadeiro Faria Lima","state":"SP","streetNumber":"2927","district":"Itaim","country":"BRA","city":"São Paulo"},"taxDocument":{"number":"794.663.228-26","type":"CPF"},"name":"Mine","birthDate":"1990-01-01"},"transparentAccount":false,"email":{"confirmed":true,"address":"fortestsminecustomer@mailinator.com"},"createdAt":"2017-10-25T10:57:15.000-02:00","businessSegment":{"id":0},"_links":{"self":{"href":"https://sandbox.moip.com.br/accounts/MPA-7E9B1F907512"}},"monthlyRevenueId":0,"softDescriptor":"fortestsmine","login":"fortestsminecustomer@mailinator.com","type":"MERCHANT"}

0 commit comments

Comments
 (0)