Skip to content

Commit

Permalink
Merge pull request #624 from stripe/ob-fix-multipart-nested-params-en…
Browse files Browse the repository at this point in the history
…coding

Fix encoding of nested parameters in multipart requests
  • Loading branch information
ob-stripe authored Apr 5, 2019
2 parents d14f02d + eeebf90 commit f513348
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 f513348

Please sign in to comment.