-
Notifications
You must be signed in to change notification settings - Fork 853
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #541 from stripe/remi-add-webhook-endpoint
Add support for the Webhook Endpoint resource
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |