From eeebf90dc9e85beb7635dd068b7c708fa8af948c Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Thu, 4 Apr 2019 23:24:35 -0700 Subject: [PATCH] Fix encoding of nested parameters in multipart requests --- lib/File.php | 9 ++++++++- tests/Stripe/FileCreationTest.php | 2 ++ tests/Stripe/FileUploadCreationTest.php | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/File.php b/lib/File.php index ae4253d53..76109ad38 100644 --- a/lib/File.php +++ b/lib/File.php @@ -50,6 +50,13 @@ public static function create($params = null, $options = null) if (is_null($opts->apiBase)) { $opts->apiBase = Stripe::$apiUploadBase; } - return static::_create($params, $opts); + // Manually flatten params, otherwise curl's multipart encoder will + // choke on nested arrays. + // TODO: use array_column() once we drop support for PHP 5.4 + $flatParams = []; + foreach (\Stripe\Util\Util::flattenParams($params) as $pair) { + $flatParams[$pair[0]] = $pair[1]; + } + return static::_create($flatParams, $opts); } } diff --git a/tests/Stripe/FileCreationTest.php b/tests/Stripe/FileCreationTest.php index 9a65452c6..c32b37687 100644 --- a/tests/Stripe/FileCreationTest.php +++ b/tests/Stripe/FileCreationTest.php @@ -40,6 +40,7 @@ public function testIsCreatableWithFileHandle() $resource = File::create([ "purpose" => "dispute_evidence", "file" => $fp, + "file_link_data" => ["create" => true] ]); $this->assertInstanceOf("Stripe\\File", $resource); } @@ -63,6 +64,7 @@ public function testIsCreatableWithCurlFile() $resource = File::create([ "purpose" => "dispute_evidence", "file" => $curlFile, + "file_link_data" => ["create" => true] ]); $this->assertInstanceOf("Stripe\\File", $resource); } diff --git a/tests/Stripe/FileUploadCreationTest.php b/tests/Stripe/FileUploadCreationTest.php index 8d5bd870e..8b5ec1357 100644 --- a/tests/Stripe/FileUploadCreationTest.php +++ b/tests/Stripe/FileUploadCreationTest.php @@ -40,6 +40,7 @@ public function testIsCreatableWithFileHandle() $resource = FileUpload::create([ "purpose" => "dispute_evidence", "file" => $fp, + "file_link_data" => ["create" => true] ]); $this->assertInstanceOf("Stripe\\FileUpload", $resource); } @@ -63,6 +64,7 @@ public function testIsCreatableWithCurlFile() $resource = FileUpload::create([ "purpose" => "dispute_evidence", "file" => $curlFile, + "file_link_data" => ["create" => true] ]); $this->assertInstanceOf("Stripe\\FileUpload", $resource); }