Skip to content

Commit

Permalink
Fix encoding of nested parameters in multipart requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Apr 5, 2019
1 parent d14f02d commit eeebf90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 2 additions & 0 deletions tests/Stripe/FileCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Stripe/FileUploadCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit eeebf90

Please sign in to comment.