From f376b194ca0e5cf62d44d66bc0dcc135234c606d Mon Sep 17 00:00:00 2001 From: Remi Jannel Date: Wed, 17 Oct 2018 13:20:04 -0700 Subject: [PATCH] Add support for the Webhook Endpoint resource --- init.php | 1 + lib/Util/Util.php | 1 + lib/WebhookEndpoint.php | 29 +++++++++++ tests/Stripe/WebhookEndpointTest.php | 77 ++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 lib/WebhookEndpoint.php create mode 100644 tests/Stripe/WebhookEndpointTest.php diff --git a/init.php b/init.php index 66bd360d1..85fc5c548 100644 --- a/init.php +++ b/init.php @@ -125,4 +125,5 @@ // Webhooks require(dirname(__FILE__) . '/lib/Webhook.php'); +require(dirname(__FILE__) . '/lib/WebhookEndpoint.php'); require(dirname(__FILE__) . '/lib/WebhookSignature.php'); diff --git a/lib/Util/Util.php b/lib/Util/Util.php index d1db0858b..7f257b051 100644 --- a/lib/Util/Util.php +++ b/lib/Util/Util.php @@ -133,6 +133,7 @@ public static function convertToStripeObject($resp, $opts) \Stripe\TransferReversal::OBJECT_NAME => 'Stripe\\TransferReversal', \Stripe\UsageRecord::OBJECT_NAME => 'Stripe\\UsageRecord', \Stripe\UsageRecordSummary::OBJECT_NAME => 'Stripe\\UsageRecordSummary', + \Stripe\WebhookEndpoint::OBJECT_NAME => 'Stripe\\WebhookEndpoint', ]; if (self::isList($resp)) { $mapped = []; diff --git a/lib/WebhookEndpoint.php b/lib/WebhookEndpoint.php new file mode 100644 index 000000000..27ecacf69 --- /dev/null +++ b/lib/WebhookEndpoint.php @@ -0,0 +1,29 @@ +expectsRequest( + 'get', + '/v1/webhook_endpoints' + ); + $resources = WebhookEndpoint::all(); + $this->assertTrue(is_array($resources->data)); + $this->assertInstanceOf("Stripe\\WebhookEndpoint", $resources->data[0]); + } + + public function testIsRetrievable() + { + $this->expectsRequest( + 'get', + '/v1/webhook_endpoints/' . self::TEST_RESOURCE_ID + ); + $resource = WebhookEndpoint::retrieve(self::TEST_RESOURCE_ID); + $this->assertInstanceOf("Stripe\\WebhookEndpoint", $resource); + } + + public function testIsCreatable() + { + $this->expectsRequest( + 'post', + '/v1/webhook_endpoints' + ); + $resource = WebhookEndpoint::create([ + 'enabled_events' => ['charge.succeeded'], + 'url' => 'https://stripe.com', + ]); + $this->assertInstanceOf("Stripe\\WebhookEndpoint", $resource); + } + + public function testIsSaveable() + { + $resource = WebhookEndpoint::retrieve(self::TEST_RESOURCE_ID); + $resource->enabled_events = ['charge.succeeded']; + $this->expectsRequest( + 'post', + '/v1/webhook_endpoints/' . self::TEST_RESOURCE_ID + ); + $resource->save(); + $this->assertInstanceOf("Stripe\\WebhookEndpoint", $resource); + } + + public function testIsUpdatable() + { + $this->expectsRequest( + 'post', + '/v1/webhook_endpoints/' . self::TEST_RESOURCE_ID + ); + $resource = WebhookEndpoint::update(self::TEST_RESOURCE_ID, [ + 'enabled_events' => ['charge.succeeded'], + ]); + $this->assertInstanceOf("Stripe\\WebhookEndpoint", $resource); + } + + public function testIsDeletable() + { + $resource = WebhookEndpoint::retrieve(self::TEST_RESOURCE_ID); + $this->expectsRequest( + 'delete', + '/v1/webhook_endpoints/' . self::TEST_RESOURCE_ID + ); + $resource->delete(); + $this->assertInstanceOf("Stripe\\WebhookEndpoint", $resource); + } +}