diff --git a/lib/Account.php b/lib/Account.php index 155ef4795..14d1b5130 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -103,15 +103,6 @@ public static function retrieve($id = null, $opts = null) public function serializeParameters($force = false) { $update = parent::serializeParameters($force); - if (isset($this->_values['legal_entity'])) { - $entity = $this['legal_entity']; - if (isset($entity->_values['additional_owners'])) { - $owners = $entity['additional_owners']; - $entityUpdate = isset($update['legal_entity']) ? $update['legal_entity'] : []; - $entityUpdate['additional_owners'] = $this->serializeAdditionalOwners($entity, $owners); - $update['legal_entity'] = $entityUpdate; - } - } if (isset($this->_values['individual'])) { $individual = $this['individual']; if (($individual instanceof Person) && !isset($update['individual'])) { @@ -122,35 +113,6 @@ public function serializeParameters($force = false) return $update; } - private function serializeAdditionalOwners($legalEntity, $additionalOwners) - { - if (isset($legalEntity->_originalValues['additional_owners'])) { - $originalValue = $legalEntity->_originalValues['additional_owners']; - } else { - $originalValue = []; - } - if (($originalValue) && (\count($originalValue) > \count($additionalOwners))) { - throw new Exception\InvalidArgumentException( - 'You cannot delete an item from an array, you must instead set a new array' - ); - } - - $updateArr = []; - foreach ($additionalOwners as $i => $v) { - $update = ($v instanceof StripeObject) ? $v->serializeParameters() : $v; - - if ([] !== $update) { - if (!$originalValue - || !\array_key_exists($i, $originalValue) - || ($update !== $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) { - $updateArr[$i] = $update; - } - } - } - - return $updateArr; - } - /** * @param null|array $clientId * @param null|array|string $opts diff --git a/tests/Stripe/AccountTest.php b/tests/Stripe/AccountTest.php index 61ae41317..3f094546f 100644 --- a/tests/Stripe/AccountTest.php +++ b/tests/Stripe/AccountTest.php @@ -289,137 +289,6 @@ public function testCanListPersons() static::compatAssertIsArray($resources->data); } - // TODO (MAJOR): Remove legal_entity/additional_owners logic. - public function testSerializeNewAdditionalOwners() - { - /** @var Account $obj */ - $obj = Util\Util::convertToStripeObject([ - 'object' => 'account', - 'legal_entity' => StripeObject::constructFrom([]), - ], null); - $obj['legal_entity']->additional_owners = [ - ['first_name' => 'Joe'], - ['first_name' => 'Jane'], - ]; - - $expected = [ - 'legal_entity' => [ - 'additional_owners' => [ - 0 => ['first_name' => 'Joe'], - 1 => ['first_name' => 'Jane'], - ], - ], - ]; - static::assertSame($expected, $obj->serializeParameters()); - } - - public function testSerializeAddAdditionalOwners() - { - $obj = Util\Util::convertToStripeObject([ - 'object' => 'account', - 'legal_entity' => [ - 'additional_owners' => [ - StripeObject::constructFrom(['first_name' => 'Joe']), - StripeObject::constructFrom(['first_name' => 'Jane']), - ], - ], - ], null); - $obj['legal_entity']->additional_owners[2] = ['first_name' => 'Andrew']; - - $expected = [ - 'legal_entity' => [ - 'additional_owners' => [ - 2 => ['first_name' => 'Andrew'], - ], - ], - ]; - static::assertSame($expected, $obj->serializeParameters()); - } - - public function testSerializePartiallyChangedAdditionalOwners() - { - $obj = Util\Util::convertToStripeObject([ - 'object' => 'account', - 'legal_entity' => [ - 'additional_owners' => [ - StripeObject::constructFrom(['first_name' => 'Joe']), - StripeObject::constructFrom(['first_name' => 'Jane']), - ], - ], - ], null); - $obj['legal_entity']->additional_owners[1]->first_name = 'Stripe'; - - $expected = [ - 'legal_entity' => [ - 'additional_owners' => [ - 1 => ['first_name' => 'Stripe'], - ], - ], - ]; - static::assertSame($expected, $obj->serializeParameters()); - } - - public function testSerializeUnchangedAdditionalOwners() - { - $obj = Util\Util::convertToStripeObject([ - 'object' => 'account', - 'legal_entity' => [ - 'additional_owners' => [ - StripeObject::constructFrom(['first_name' => 'Joe']), - StripeObject::constructFrom(['first_name' => 'Jane']), - ], - ], - ], null); - - $expected = [ - 'legal_entity' => [ - 'additional_owners' => [], - ], - ]; - static::assertSame($expected, $obj->serializeParameters()); - } - - public function testSerializeUnsetAdditionalOwners() - { - $obj = Util\Util::convertToStripeObject([ - 'object' => 'account', - 'legal_entity' => [ - 'additional_owners' => [ - StripeObject::constructFrom(['first_name' => 'Joe']), - StripeObject::constructFrom(['first_name' => 'Jane']), - ], - ], - ], null); - $obj['legal_entity']->additional_owners = null; - - // Note that the empty string that we send for this one has a special - // meaning for the server, which interprets it as an array unset. - $expected = [ - 'legal_entity' => [ - 'additional_owners' => '', - ], - ]; - static::assertSame($expected, $obj->serializeParameters()); - } - - public function testSerializeAdditionalOwnersDeletedItem() - { - $this->expectException(\InvalidArgumentException::class); - - $obj = Util\Util::convertToStripeObject([ - 'object' => 'account', - 'legal_entity' => [ - 'additional_owners' => [ - StripeObject::constructFrom(['first_name' => 'Joe']), - StripeObject::constructFrom(['first_name' => 'Jane']), - ], - ], - ], null); - unset($obj['legal_entity']->additional_owners[0]); - - $obj->serializeParameters(); - } - public function testSerializeExternalAccountString() { $obj = Util\Util::convertToStripeObject([