diff --git a/lib/StripeObject.php b/lib/StripeObject.php index a096dddef..432e95b7f 100644 --- a/lib/StripeObject.php +++ b/lib/StripeObject.php @@ -280,7 +280,7 @@ public function updateAttributes($values, $opts = null, $dirty = true) // This is necessary in case metadata is empty, as PHP arrays do // not differentiate between lists and hashes, and we consider // empty arrays to be lists. - if ($k === "metadata") { + if (($k === "metadata") && (is_array($v))) { $this->_values[$k] = StripeObject::constructFrom($v, $opts); } else { $this->_values[$k] = Util\Util::convertToStripeObject($v, $opts); diff --git a/tests/Stripe/StripeObjectTest.php b/tests/Stripe/StripeObjectTest.php index 2e841fd8d..bbf2d7c5a 100644 --- a/tests/Stripe/StripeObjectTest.php +++ b/tests/Stripe/StripeObjectTest.php @@ -473,4 +473,23 @@ public function testIsDeleted() $obj = StripeObject::constructFrom(['deleted' => true]); $this->assertTrue($obj->isDeleted()); } + + public function testDeserializeEmptyMetadata() + { + $obj = StripeObject::constructFrom([ + 'metadata' => [], + ]); + + $this->assertInstanceOf("Stripe\\StripeObject", $obj->metadata); + } + + public function testDeserializeMetadataWithKeyNamedMetadata() + { + $obj = StripeObject::constructFrom([ + 'metadata' => ['metadata' => 'value'], + ]); + + $this->assertInstanceOf("Stripe\\StripeObject", $obj->metadata); + $this->assertEquals("value", $obj->metadata->metadata); + } }