Skip to content

Commit 7c061d5

Browse files
authored
Merge pull request #2 from sverraest/feature/webhooks
Added Webhooks Resource
2 parents 51ecda6 + a01b609 commit 7c061d5

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Using this PHP API Client you can interact with your:
1111
- 💸 __Payments__
1212
- 🔀 __Transfers__
1313
- 📊 __Transactions__
14+
- 🔗 __Webhooks__
15+
1416

1517
## Installation
1618

@@ -100,6 +102,10 @@ Get all transactions or a subset (with queryFilters), cancel a scheduled transac
100102

101103
A Transaction is either created as a Payment or a Transfer.
102104

105+
🔗 __Webhooks__
106+
107+
Create new webhooks.
108+
103109
## Usage details
104110

105111
### 💰 Accounts
@@ -304,6 +310,22 @@ $searchFilters = [
304310
$transactions = $client->transactions->all($searchFilters);
305311
```
306312

313+
### 🔗 Webhooks
314+
#### Create a webhook
315+
See more at [https://revolutdev.github.io/business-api/#web-hooks](https://revolutdev.github.io/business-api/#web-hooks)
316+
317+
```php
318+
use RevolutPHP\Client;
319+
320+
$client = new Client('apikey');
321+
322+
$webhook = [
323+
'url' => 'https://foo.bar',
324+
];
325+
326+
$payment = $client->webhooks->create($webhook);
327+
```
328+
307329
## About
308330

309331
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.

src/Client.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class Client
6363
*/
6464
public $transactions;
6565

66+
/**
67+
* @var Webhooks
68+
*/
69+
public $webhooks;
70+
6671
/**
6772
* Client constructor.
6873
* @param string $apiKey
@@ -83,6 +88,7 @@ public function __construct(string $apiKey, $mode = 'production', array $clientO
8388
$this->payments = new Payments($this);
8489
$this->transfers = new Transfers($this);
8590
$this->transactions = new Transactions($this);
91+
$this->webhooks = new Webhooks($this);
8692
}
8793

8894
/**

src/Webhooks.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace RevolutPHP;
4+
5+
class Webhooks
6+
{
7+
const ENDPOINT = 'webhook';
8+
9+
/**
10+
* @var Client
11+
*/
12+
private $client;
13+
14+
/**
15+
* Webhook constructor.
16+
* @param Client $client
17+
*/
18+
public function __construct(Client $client)
19+
{
20+
$this->client = $client;
21+
}
22+
23+
/**
24+
* @see https://revolutdev.github.io/business-api/#web-hooks
25+
*
26+
* @param array $json
27+
* @return mixed
28+
* @throws \GuzzleHttp\Exception\GuzzleException
29+
*/
30+
public function create(array $json)
31+
{
32+
return $this->client->post(self::ENDPOINT, $json);
33+
}
34+
}

test/WebhooksTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
class WebhooksTest extends PHPUnit_Framework_TestCase
4+
{
5+
public function testCreate()
6+
{
7+
$stub = $this->getMockBuilder('RevolutPHP\Client')->disableOriginalConstructor()->getMock();
8+
$stub->method('post')->willReturn('https://example.org');
9+
10+
$webhooks = new \RevolutPHP\Webhooks($stub);
11+
$this->assertEquals('https://example.org', $webhooks->create(['url' => 'https://example.org']));
12+
13+
}
14+
}

0 commit comments

Comments
 (0)