Skip to content

Commit

Permalink
Merge pull request #2 from sverraest/feature/webhooks
Browse files Browse the repository at this point in the history
Added Webhooks Resource
  • Loading branch information
sverraest authored Apr 7, 2018
2 parents 51ecda6 + a01b609 commit 7c061d5
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Using this PHP API Client you can interact with your:
- 💸 __Payments__
- 🔀 __Transfers__
- 📊 __Transactions__
- 🔗 __Webhooks__


## Installation

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class Client
*/
public $transactions;

/**
* @var Webhooks
*/
public $webhooks;

/**
* Client constructor.
* @param string $apiKey
Expand All @@ -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);
}

/**
Expand Down
34 changes: 34 additions & 0 deletions src/Webhooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace RevolutPHP;

class Webhooks
{
const ENDPOINT = 'webhook';

/**
* @var Client
*/
private $client;

/**
* Webhook constructor.
* @param Client $client
*/
public function __construct(Client $client)
{
$this->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);
}
}
14 changes: 14 additions & 0 deletions test/WebhooksTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class WebhooksTest extends PHPUnit_Framework_TestCase
{
public function testCreate()
{
$stub = $this->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']));

}
}

0 comments on commit 7c061d5

Please sign in to comment.