Skip to content

Commit

Permalink
Merge pull request #541 from stripe/remi-add-webhook-endpoint
Browse files Browse the repository at this point in the history
Add support for the Webhook Endpoint resource
  • Loading branch information
remi-stripe authored Oct 30, 2018
2 parents e1d2fb8 + f376b19 commit 852709d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,5 @@

// Webhooks
require(dirname(__FILE__) . '/lib/Webhook.php');
require(dirname(__FILE__) . '/lib/WebhookEndpoint.php');
require(dirname(__FILE__) . '/lib/WebhookSignature.php');
1 change: 1 addition & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
29 changes: 29 additions & 0 deletions lib/WebhookEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Stripe;

/**
* Class WebhookEndpoint
*
* @property string $id
* @property string $object
* @property int $created
* @property string[] $enabled_events
* @property bool $livemode
* @property string $secret
* @property string $status
* @property string $url
*
* @package Stripe
*/
class WebhookEndpoint extends ApiResource
{

const OBJECT_NAME = "webhook_endpoint";

use ApiOperations\All;
use ApiOperations\Create;
use ApiOperations\Delete;
use ApiOperations\Retrieve;
use ApiOperations\Update;
}
77 changes: 77 additions & 0 deletions tests/Stripe/WebhookEndpointTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace Stripe;

class WebhookEndpointTest extends TestCase
{
const TEST_RESOURCE_ID = 'we_123';

public function testIsListable()
{
$this->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);
}
}

0 comments on commit 852709d

Please sign in to comment.