From cf2acc62dbdb356eb53a3d30b604ec519a171876 Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Mon, 17 Sep 2018 19:53:06 +0200 Subject: [PATCH] Handle case when adding a new additional owner to the array --- lib/Account.php | 4 +++- tests/Stripe/AccountTest.php | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Account.php b/lib/Account.php index 0fd55cb93..f5c450aef 100644 --- a/lib/Account.php +++ b/lib/Account.php @@ -230,7 +230,9 @@ private function serializeAdditionalOwners($legalEntity, $additionalOwners) $update = ($v instanceof StripeObject) ? $v->serializeParameters() : $v; if ($update !== []) { - if (!$originalValue || ($update != $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) { + if (!$originalValue || + !array_key_exists($i, $originalValue) || + ($update != $legalEntity->serializeParamsValue($originalValue[$i], null, false, true))) { $updateArr[$i] = $update; } } diff --git a/tests/Stripe/AccountTest.php b/tests/Stripe/AccountTest.php index 92035f8b7..0e7b2fe17 100644 --- a/tests/Stripe/AccountTest.php +++ b/tests/Stripe/AccountTest.php @@ -202,6 +202,29 @@ public function testSerializeNewAdditionalOwners() $this->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'], + ], + ], + ]; + $this->assertSame($expected, $obj->serializeParameters()); + } + public function testSerializePartiallyChangedAdditionalOwners() { $obj = Util\Util::convertToStripeObject([