diff --git a/README.md b/README.md index 44ca7e4..cce3559 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ Using this PHP API Client you can interact with your: - 💸 __Payments__ - 🔀 __Transfers__ - 📊 __Transactions__ +- 🔗 __Webhooks__ + ## Installation @@ -100,6 +102,10 @@ Get all transactions or a subset (with queryFilters), cancel a scheduled transac A Transaction is either created as a Payment or a Transfer. +🔗 __Webhooks__ + +Create new webhooks. + ## Usage details ### 💰 Accounts @@ -304,6 +310,22 @@ $searchFilters = [ $transactions = $client->transactions->all($searchFilters); ``` +### 🔗 Webhooks +#### Create a webhook +See more at [https://revolutdev.github.io/business-api/#web-hooks](https://revolutdev.github.io/business-api/#web-hooks) + +```php +use RevolutPHP\Client; + +$client = new Client('apikey'); + +$webhook = [ + 'url' => 'https://foo.bar', +]; + +$payment = $client->webhooks->create($webhook); +``` + ## About I'm a big fan of Revolut and I use them both at [Appfleet](https://appfleet.uk) and personally. If you need to build your PHP application on top of the Revolut For Business API this is the library you should use. diff --git a/src/Client.php b/src/Client.php index 14d33a6..7f14351 100644 --- a/src/Client.php +++ b/src/Client.php @@ -63,6 +63,11 @@ class Client */ public $transactions; + /** + * @var Webhooks + */ + public $webhooks; + /** * Client constructor. * @param string $apiKey @@ -83,6 +88,7 @@ public function __construct(string $apiKey, $mode = 'production', array $clientO $this->payments = new Payments($this); $this->transfers = new Transfers($this); $this->transactions = new Transactions($this); + $this->webhooks = new Webhooks($this); } /** diff --git a/src/Webhooks.php b/src/Webhooks.php new file mode 100644 index 0000000..37a07e5 --- /dev/null +++ b/src/Webhooks.php @@ -0,0 +1,34 @@ +client = $client; + } + + /** + * @see https://revolutdev.github.io/business-api/#web-hooks + * + * @param array $json + * @return mixed + * @throws \GuzzleHttp\Exception\GuzzleException + */ + public function create(array $json) + { + return $this->client->post(self::ENDPOINT, $json); + } +} diff --git a/test/WebhooksTest.php b/test/WebhooksTest.php new file mode 100644 index 0000000..4be78b0 --- /dev/null +++ b/test/WebhooksTest.php @@ -0,0 +1,14 @@ +getMockBuilder('RevolutPHP\Client')->disableOriginalConstructor()->getMock(); + $stub->method('post')->willReturn('https://example.org'); + + $webhooks = new \RevolutPHP\Webhooks($stub); + $this->assertEquals('https://example.org', $webhooks->create(['url' => 'https://example.org'])); + + } +} \ No newline at end of file