Skip to content

Commit e81186f

Browse files
authored
made v2 event class concrete, and changed convertToStripeObject to use it if we cannot find the identified event subclass (#1805)
1 parent 9fe9d51 commit e81186f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/Util/Util.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static function convertToStripeObject($resp, $opts, $apiMode = 'v1')
6464
if (\array_key_exists('type', $resp) && \array_key_exists($resp['type'], $eventTypes)) {
6565
$class = $eventTypes[$resp['type']];
6666
} else {
67-
$class = \Stripe\StripeObject::class;
67+
$class = \Stripe\V2\Event::class;
6868
}
6969
}
7070
} elseif (\array_key_exists('data', $resp) && \array_key_exists('next_page_url', $resp)) {

lib/V2/Event.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
namespace Stripe\V2;
44

55
/**
6+
* Base class for V2 events.
7+
*
8+
* This is concrete for use in our generated tests. Events returned from the \Stripe\V2\Core\EventService
9+
* will be a subtype of \Stripe\V2\Event.
10+
*
611
* @property string $id Unique identifier for the event.
712
* @property string $object String representing the object's type. Objects of the same type share the same value of the object field.
813
* @property int $created Time at which the object was created.
914
* @property \Stripe\StripeObject $reason Reason for the event.
1015
* @property string $type The type of the event.
1116
* @property null|string $context The Stripe account of the event
1217
*/
13-
abstract class Event extends \Stripe\ApiResource
18+
class Event extends \Stripe\ApiResource
1419
{
1520
const OBJECT_NAME = 'v2.core.event';
1621
}

tests/Stripe/GeneratedExamplesTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,20 @@ public function testCheckoutSessionsPost2()
577577
static::assertInstanceOf(\Stripe\Checkout\Session::class, $result);
578578
}
579579

580+
public function testCoreEventsGet()
581+
{
582+
$this->stubRequest(
583+
'get',
584+
'/v2/core/events/ll_123',
585+
[],
586+
[],
587+
false,
588+
['object' => \Stripe\V2\Event::OBJECT_NAME]
589+
);
590+
$result = $this->client->v2->core->events->retrieve('ll_123', []);
591+
static::assertInstanceOf(\Stripe\V2\Event::class, $result);
592+
}
593+
580594
public function testCountrySpecsGet()
581595
{
582596
$this->expectsRequest('get', '/v1/country_specs');

0 commit comments

Comments
 (0)