Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .hark/changes/2026-11-03_stripe-openapi_9eb9d0d2.change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: Update generated code
pr_url: https://github.com/stripe/stripe-php/pull/2190
semver_level: minor
is_stripe_api_change: true
---

* Release specs are identical.
2 changes: 1 addition & 1 deletion CODEGEN_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
65c49b0893d71e8cfe272b2d38cd3307ee1833f2
fcd36ef9298b7a9e8a2a18bc4f6162b100aa8bbc
6 changes: 3 additions & 3 deletions lib/BaseStripeClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,9 @@ public function requestCollection($method, $path, $params, $opts)
*/
public function requestSearchResult($method, $path, $params, $opts)
{
$obj = $this->request($method, $path, $params, $opts);
$apiMode = Util::getApiMode($path);
if ('v1' === $apiMode) {
$obj = $this->request($method, $path, $params, $opts);
if (!$obj instanceof SearchResult) {
$received_class = \get_class($obj);
$msg = "Expected to receive `Stripe\\SearchResult` object from Stripe API. Instead received `{$received_class}`.";
Expand All @@ -401,9 +401,9 @@ public function requestSearchResult($method, $path, $params, $opts)
} else {
$params = null === $params ? [] : $params;
$filters = $params;
$path = \explode('?', $path, 2)[0];
if (\array_key_exists('limit', $params)) {
$separator = false === \strpos($path, '?') ? '?' : '&';
$path .= $separator . 'limit=' . \rawurlencode((string) $params['limit']);
$path .= '?limit=' . \rawurlencode((string) $params['limit']);
unset($params['limit']);
}
$obj = $this->request($method, $path, $params, $opts);
Expand Down
55 changes: 55 additions & 0 deletions tests/Stripe/BaseStripeClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,61 @@ protected function setUpCurlClientStub()
;
}

/**
* @dataProvider provideSearchDispatchesOnceCases
*
* @param mixed $method
* @param mixed $path
* @param mixed $params
* @param mixed $expectedPath
* @param mixed $body
* @param mixed $v2
*/
public function testSearchDispatchesOnce($method, $path, $params, $expectedPath, $body, $v2)
{
$client = $this->getMockBuilder(BaseStripeClient::class)->setMethods(['request'])->getMock();
$result = $v2 ? new V2\SearchResult() : new SearchResult();
$opts = ['stripe_account' => 'acct_123'];
$original = $params;
$client->expects(self::once())->method('request')
->with($method, $expectedPath, $body, $opts)->willReturn($result)
;
self::assertSame($result, $client->requestSearchResult($method, $path, $params, $opts));
self::assertSame($original, $params);
if ($v2) {
$filters = new \ReflectionProperty(V2\SearchResult::class, 'filters');
$filters->setAccessible(true);
self::assertSame(null === $params ? [] : $params, $filters->getValue($result));
} else {
self::assertSame($params, $result->getFilters());
}
}

public static function provideSearchDispatchesOnceCases(): iterable
{
return [
['get', '/v1/widgets/search', ['limit' => 2], '/v1/widgets/search', ['limit' => 2], false],
['post', '/v2/widgets/search', ['query' => 'widgets', 'limit' => 2], '/v2/widgets/search?limit=2', ['query' => 'widgets'], true],
['post', '/v2/widgets/search', ['query' => 'widgets'], '/v2/widgets/search', ['query' => 'widgets'], true],
['post', '/v2/widgets/search', null, '/v2/widgets/search', [], true],
['post', '/v2/widgets/search?page=2&limit=2', ['query' => 'widgets', 'limit' => 9], '/v2/widgets/search?limit=9', ['query' => 'widgets'], true],
['post', '/v2/widgets/search?page=2', ['query' => 'widgets', 'limit' => 9], '/v2/widgets/search?limit=9', ['query' => 'widgets'], true],
['post', '/v2/widgets/search?limit=2&unused=value', ['query' => 'widgets'], '/v2/widgets/search', ['query' => 'widgets'], true],
['post', '/v2/widgets/search?limit=2', null, '/v2/widgets/search', [], true],
];
}

public function testSearchPropagatesErrorWithoutAnotherDispatch()
{
$client = $this->getMockBuilder(BaseStripeClient::class)->setMethods(['request'])->getMock();
$client->expects(self::once())->method('request')
->with('post', '/v2/widgets/search?limit=2', ['query' => 'widgets'], [])
->willThrowException(new Exception\InvalidRequestException('search failed'))
;
$this->expectException(Exception\InvalidRequestException::class);
$client->requestSearchResult('post', '/v2/widgets/search', ['limit' => 2, 'query' => 'widgets'], []);
}

public function testCtorDoesNotThrowWhenNoParams()
{
$client = new BaseStripeClient();
Expand Down
Loading