diff --git a/lib/Service/AbstractService.php b/lib/Service/AbstractService.php index abcc13ae2e..a0064ba89e 100644 --- a/lib/Service/AbstractService.php +++ b/lib/Service/AbstractService.php @@ -40,14 +40,17 @@ public function getClient() * * @param null|array $params */ - private static function formatParams($params) + public static function formatParams($params) { if (null === $params) { return $params; } + $formatted = []; foreach ($params as $k => $v) { - if (null === $v) { + if (is_array($v)) { + $formatted[$k] = static::formatParams($v); + } else if (null === $v) { $formatted[$k] = ''; } else { $formatted[$k] = $v; diff --git a/tests/Stripe/Service/AbstractServiceTest.php b/tests/Stripe/Service/AbstractServiceTest.php index deee3e3869..059badb0f6 100644 --- a/tests/Stripe/Service/AbstractServiceTest.php +++ b/tests/Stripe/Service/AbstractServiceTest.php @@ -57,4 +57,16 @@ public function testRetrieveThrowsIfIdNullIsWhitespace() $this->service->retrieve(' '); } + + public function testFormatParams() { + $result = \Stripe\Service\AbstractService::formatParams(["foo" => null]); + static::assertTrue($result["foo"] === ""); + static::assertTrue($result["foo"] !== null); + + + $result = \Stripe\Service\AbstractService::formatParams(["foo" => ["bar" => null, "baz" => 1]]); + static::assertTrue($result["foo"]["bar"] === ""); + static::assertTrue($result["foo"]["bar"] !== null); + static::assertTrue($result["foo"]["baz"] === 1); + } }