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

Commit

Permalink
fix(Account): Fix account create without company set (#157)
Browse files Browse the repository at this point in the history
* fix(Account): Fix account create without company set
Preventing account from create with company node when it was not set

* style(Account): Fix formatting to StyleCI

Fix formatting to StyleCI

* style(Account): Fix formatting to StyleCI

Fix formatting to StyleCI
  • Loading branch information
caiogaspar authored and joaolucasl committed Aug 11, 2017
1 parent f74e51d commit 4d7f4bc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Resource/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function initialize()
$this->data->email = new stdClass();
$this->data->person = new stdClass();
$this->data->person->alternativePhones = [];
$this->data->company = new stdClass();
$this->data->type = self::ACCOUNT_TYPE;
}

Expand Down Expand Up @@ -521,12 +520,23 @@ public function setBusinessSegment($segmentId)
*/
public function setCompanyName($name, $businessName)
{
$this->initializeCompany();
$this->data->company->name = $name;
$this->data->company->businessName = $businessName;

return $this;
}

/**
* Initialize company node.
*/
private function initializeCompany()
{
if (!isset($this->data->company)) {
$this->data->company = new stdClass();
}
}

/**
* Set company opening date.
*
Expand All @@ -539,6 +549,7 @@ public function setCompanyOpeningDate($openingDate)
if ($openingDate instanceof \DateTime) {
$openingDate = $openingDate->format('Y-m-d');
}
$this->initializeCompany();
$this->data->company->openingDate = $openingDate;

return $this;
Expand All @@ -553,6 +564,7 @@ public function setCompanyOpeningDate($openingDate)
*/
public function setCompanyTaxDocument($documentNumber)
{
$this->initializeCompany();
$this->data->company->taxDocument = new stdClass();
$this->data->company->taxDocument->type = self::COMPANY_TAX_DOCUMENT;
$this->data->company->taxDocument->number = $documentNumber;
Expand All @@ -569,6 +581,7 @@ public function setCompanyTaxDocument($documentNumber)
*/
public function setCompanyMainActivity($cnae, $description)
{
$this->initializeCompany();
$this->data->company->mainActivity = new stdClass();
$this->data->company->mainActivity->cnae = $cnae;
$this->data->company->mainActivity->description = $description;
Expand Down Expand Up @@ -602,6 +615,7 @@ public function setCompanyAddress($street, $number, $district, $city, $state, $z
$address->country = $country;
$address->zipCode = $zip;

$this->initializeCompany();
$this->data->company->address = $address;

return $this;
Expand All @@ -618,6 +632,7 @@ public function setCompanyAddress($street, $number, $district, $city, $state, $z
*/
public function setCompanyPhone($areaCode, $number, $countryCode = 55)
{
$this->initializeCompany();
$this->data->company->phone = new stdClass();
$this->data->company->phone->countryCode = $countryCode;
$this->data->company->phone->areaCode = $areaCode;
Expand Down
22 changes: 22 additions & 0 deletions tests/Resource/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,28 @@ public function testShouldCreateAccount()
{
$this->mockHttpSession($this->body_moip_account);

$account = $this->moip->accounts()
->setName('Fulano')
->setLastName('De Tal')
->setEmail('[email protected]')
->setIdentityDocument('4737283560', 'SSP', '2015-06-23')
->setBirthDate('1988-12-30')
->setTaxDocument('16262131000')
->setType('MERCHANT')
->setPhone(11, 66778899, 55)
->addAlternativePhone(11, 66448899, 55)
->addAlternativePhone(11, 66338899, 55)
->setTransparentAccount(true)
->addAddress('Rua de teste', 123, 'Bairro', 'Sao Paulo', 'SP', '01234567', 'Apt. 23', 'BRA')
->create();

$this->assertNotEmpty($account->getId());
}

public function testShouldCreateAccountWithCompany()
{
$this->mockHttpSession($this->body_moip_account);

$account = $this->moip->accounts()
->setName('Fulano')
->setLastName('De Tal')
Expand Down

0 comments on commit 4d7f4bc

Please sign in to comment.