diff --git a/src/Resource/Account.php b/src/Resource/Account.php index 587d665..1db9f29 100644 --- a/src/Resource/Account.php +++ b/src/Resource/Account.php @@ -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; } @@ -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. * @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/tests/Resource/AccountTest.php b/tests/Resource/AccountTest.php index 6b70725..eef6bfa 100644 --- a/tests/Resource/AccountTest.php +++ b/tests/Resource/AccountTest.php @@ -13,6 +13,28 @@ public function testShouldCreateAccount() { $this->mockHttpSession($this->body_moip_account); + $account = $this->moip->accounts() + ->setName('Fulano') + ->setLastName('De Tal') + ->setEmail('fulano@email2.com') + ->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')