Skip to content

Commit

Permalink
Merge branch 'master' into latest-codegen-master
Browse files Browse the repository at this point in the history
  • Loading branch information
pakrym-stripe authored Jan 25, 2024
2 parents 6870e83 + 53d5dd0 commit b0797b8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 29 deletions.
13 changes: 1 addition & 12 deletions lib/ApiOperations/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,8 @@ trait All
*/
public static function all($params = null, $opts = null)
{
self::_validateParams($params);
$url = static::classUrl();

list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
if (!($obj instanceof \Stripe\Collection)) {
throw new \Stripe\Exception\UnexpectedValueException(
'Expected type ' . \Stripe\Collection::class . ', got "' . \get_class($obj) . '" instead.'
);
}
$obj->setLastResponse($response);
$obj->setFilters($params);

return $obj;
return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
}
}
34 changes: 31 additions & 3 deletions lib/ApiOperations/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ protected static function _validateParams($params = null)
{
if ($params && !\is_array($params)) {
$message = 'You must pass an array as the first argument to Stripe API '
. 'method calls. (HINT: an example call to create a charge '
. "would be: \"Stripe\\Charge::create(['amount' => 100, "
. "'currency' => 'usd', 'source' => 'tok_1234'])\")";
. 'method calls. (HINT: an example call to create a charge '
. "would be: \"Stripe\\Charge::create(['amount' => 100, "
. "'currency' => 'usd', 'source' => 'tok_1234'])\")";

throw new \Stripe\Exception\InvalidArgumentException($message);
}
Expand All @@ -46,6 +46,34 @@ protected function _request($method, $url, $params = [], $options = null, $usage
return [$resp->json, $options];
}

/**
* @param string $url URL for the request
* @param class-string< \Stripe\SearchResult|\Stripe\Collection > $resultClass indicating what type of paginated result is returned
* @param null|array $params list of parameters for the request
* @param null|array|string $options
* @param string[] $usage names of tracked behaviors associated with this request
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\Collection|\Stripe\SearchResult
*/
protected static function _requestPage($url, $resultClass, $params = null, $options = null, $usage = [])
{
self::_validateParams($params);

list($response, $opts) = static::_staticRequest('get', $url, $params, $options, $usage);
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
if (!($obj instanceof $resultClass)) {
throw new \Stripe\Exception\UnexpectedValueException(
'Expected type ' . $resultClass . ', got "' . \get_class($obj) . '" instead.'
);
}
$obj->setLastResponse($response);
$obj->setFilters($params);

return $obj;
}

/**
* @param 'delete'|'get'|'post' $method HTTP method ('get', 'post', etc.)
* @param string $url URL for the request
Expand Down
14 changes: 1 addition & 13 deletions lib/ApiOperations/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ trait Search
*/
protected static function _searchResource($searchUrl, $params = null, $opts = null)
{
self::_validateParams($params);

list($response, $opts) = static::_staticRequest('get', $searchUrl, $params, $opts);
$obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
if (!($obj instanceof \Stripe\SearchResult)) {
throw new \Stripe\Exception\UnexpectedValueException(
'Expected type ' . \Stripe\SearchResult::class . ', got "' . \get_class($obj) . '" instead.'
);
}
$obj->setLastResponse($response);
$obj->setFilters($params);

return $obj;
return static::_requestPage($searchUrl, \Stripe\SearchResult::class, $params, $opts);
}
}
4 changes: 3 additions & 1 deletion tests/Stripe/WebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ final class WebhookTest extends \Stripe\TestCase

const EVENT_PAYLOAD = '{
"id": "evt_test_webhook",
"object": "event"
"object": "event",
"data": { "object": { "id": "rdr_123", "object": "terminal.reader" } }
}';
const SECRET = 'whsec_test_secret';

Expand All @@ -37,6 +38,7 @@ public function testValidJsonAndHeader()
$sigHeader = $this->generateHeader();
$event = Webhook::constructEvent(self::EVENT_PAYLOAD, $sigHeader, self::SECRET);
static::assertSame('evt_test_webhook', $event->id);
static::assertInstanceOf(\Stripe\Terminal\Reader::class, $event->data->__get('object'));
}

public function testInvalidJson()
Expand Down

0 comments on commit b0797b8

Please sign in to comment.