Skip to content

Commit

Permalink
Remove legal_entity which is no longer part of the Account API (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-stripe authored Mar 18, 2024
1 parent d569265 commit 4504b0f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 169 deletions.
38 changes: 0 additions & 38 deletions lib/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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
Expand Down
131 changes: 0 additions & 131 deletions tests/Stripe/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down

0 comments on commit 4504b0f

Please sign in to comment.