Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Webhook Endpoint resource #541

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}