Skip to content

Commit

Permalink
made v2 event class concrete, and changed convertToStripeObject to us…
Browse files Browse the repository at this point in the history
…e it if we cannot find the identified event subclass (#1805)
  • Loading branch information
jar-stripe authored Jan 17, 2025
1 parent 9fe9d51 commit e81186f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function convertToStripeObject($resp, $opts, $apiMode = 'v1')
if (\array_key_exists('type', $resp) && \array_key_exists($resp['type'], $eventTypes)) {
$class = $eventTypes[$resp['type']];
} else {
$class = \Stripe\StripeObject::class;
$class = \Stripe\V2\Event::class;
}
}
} elseif (\array_key_exists('data', $resp) && \array_key_exists('next_page_url', $resp)) {
Expand Down
7 changes: 6 additions & 1 deletion lib/V2/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
namespace Stripe\V2;

/**
* Base class for V2 events.
*
* This is concrete for use in our generated tests. Events returned from the \Stripe\V2\Core\EventService
* will be a subtype of \Stripe\V2\Event.
*
* @property string $id Unique identifier for the event.
* @property string $object String representing the object's type. Objects of the same type share the same value of the object field.
* @property int $created Time at which the object was created.
* @property \Stripe\StripeObject $reason Reason for the event.
* @property string $type The type of the event.
* @property null|string $context The Stripe account of the event
*/
abstract class Event extends \Stripe\ApiResource
class Event extends \Stripe\ApiResource
{
const OBJECT_NAME = 'v2.core.event';
}
14 changes: 14 additions & 0 deletions tests/Stripe/GeneratedExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,20 @@ public function testCheckoutSessionsPost2()
static::assertInstanceOf(\Stripe\Checkout\Session::class, $result);
}

public function testCoreEventsGet()
{
$this->stubRequest(
'get',
'/v2/core/events/ll_123',
[],
[],
false,
['object' => \Stripe\V2\Event::OBJECT_NAME]
);
$result = $this->client->v2->core->events->retrieve('ll_123', []);
static::assertInstanceOf(\Stripe\V2\Event::class, $result);
}

public function testCountrySpecsGet()
{
$this->expectsRequest('get', '/v1/country_specs');
Expand Down

0 comments on commit e81186f

Please sign in to comment.