Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Accounts
{
const ENDPOINT = 'accounts';
const ENDPOINT = '1.0/accounts';

/**
* @var Client
Expand Down
27 changes: 18 additions & 9 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class Client
{

const REVOLUT_API_VERSION = '1.0';
const REVOLUT_SANDBOX_ENDPOINT = 'https://sandbox-b2b.revolut.com/api/';
const REVOLUT_PRODUCTION_ENDPOINT = 'https://b2b.revolut.com/api/';

Expand Down Expand Up @@ -84,6 +83,11 @@ class Client
*/
public $webhooks;

/**
* @var WebhooksV2
*/
public $webhooksV2;

/**
* Client constructor.
* @param AccessToken $accessToken
Expand All @@ -108,6 +112,7 @@ public function __construct(AccessToken $accessToken, $mode = 'production', arra
$this->rates = new Rates($this);
$this->exchanges = new Exchanges($this);
$this->webhooks = new Webhooks($this);
$this->webhooksV2 = new WebhooksV2($this);
}

/**
Expand All @@ -125,16 +130,16 @@ private function initiateHttpClient()
{
$options = [
'headers' => [
'Authorization' => 'Bearer ' . $this->accessToken->getToken(),
]
'Authorization' => 'Bearer '.$this->accessToken->getToken(),
],
];

$this->httpClient = new GuzzleClient(array_replace_recursive($this->clientOptions, $options));
}

private function buildBaseUrl()
private function getBaseUrl()
{
return $this->baseUrl.self::REVOLUT_API_VERSION.'/';
return $this->baseUrl;
}

/**
Expand All @@ -157,7 +162,8 @@ private function handleResponse(Response $response)
*/
public function post($endpoint, $json)
{
$response = $this->httpClient->request('POST', $this->buildBaseUrl().$endpoint, ['json' => $json]);
$response = $this->httpClient->request('POST', $this->getBaseUrl().$endpoint, ['json' => $json]);

return $this->handleResponse($response);
}

Expand All @@ -169,7 +175,8 @@ public function post($endpoint, $json)
*/
public function patch($endpoint, $json)
{
$response = $this->httpClient->request('PATCH', $this->buildBaseUrl().$endpoint, ['json' => $json]);
$response = $this->httpClient->request('PATCH', $this->getBaseUrl().$endpoint, ['json' => $json]);

return $this->handleResponse($response);
}

Expand All @@ -180,7 +187,8 @@ public function patch($endpoint, $json)
*/
public function get($endpoint)
{
$response = $this->httpClient->request('GET', $this->buildBaseUrl().$endpoint);
$response = $this->httpClient->request('GET', $this->getBaseUrl().$endpoint);

return $this->handleResponse($response);
}

Expand All @@ -191,7 +199,8 @@ public function get($endpoint)
*/
public function delete($endpoint)
{
$response = $this->httpClient->request('DELETE', $this->buildBaseUrl().$endpoint);
$response = $this->httpClient->request('DELETE', $this->getBaseUrl().$endpoint);

return $this->handleResponse($response);
}
}
2 changes: 1 addition & 1 deletion src/Counterparties.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Counterparties
{
const ENDPOINT = 'counterparty';
const ENDPOINT = '1.0/counterparty';

/**
* @var Client
Expand Down
2 changes: 1 addition & 1 deletion src/Exchanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Exchanges
{
const ENDPOINT = 'exchange';
const ENDPOINT = '1.0/exchange';

/**
* @var Client
Expand Down
2 changes: 1 addition & 1 deletion src/PaymentDrafts.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class PaymentDrafts
{
const ENDPOINT = 'payment-drafts';
const ENDPOINT = '1.0/payment-drafts';

/**
* @var Client
Expand Down
2 changes: 1 addition & 1 deletion src/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Payments
{
const ENDPOINT = 'pay';
const ENDPOINT = '1.0/pay';

/**
* @var Client
Expand Down
2 changes: 1 addition & 1 deletion src/Rates.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Rates
{
const ENDPOINT = 'rate';
const ENDPOINT = '1.0/rate';

/**
* @var Client
Expand Down
2 changes: 1 addition & 1 deletion src/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Transactions
{
const ENDPOINT = 'transaction';
const ENDPOINT = '1.0/transaction';

/**
* @var Client
Expand Down
2 changes: 1 addition & 1 deletion src/Transfers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Transfers
{
const ENDPOINT = 'transfer';
const ENDPOINT = '1.0/transfer';

/**
* @var Client
Expand Down
2 changes: 1 addition & 1 deletion src/Webhooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class Webhooks
{
const ENDPOINT = 'webhook';
const ENDPOINT = '1.0/webhook';

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

namespace RevolutPHP;

class WebhooksV2
{
const ENDPOINT = '2.0/webhooks';

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

/**
* Webhook constructor.
* @param Client $client
*/
public function __construct(Client $client)
{
$this->client = $client;
}

/**
* @see https://developer.revolut.com/docs/business/create-webhook
*
* @param array $json
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function create(array $json)
{
return $this->client->post(self::ENDPOINT, $json);
}

/**
* @see https://developer.revolut.com/docs/business/get-webhooks
*
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function all()
{
return $this->client->get(self::ENDPOINT);
}

/**
* @see https://developer.revolut.com/docs/business/get-webhook
*
* @param string $id
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function get(string $id)
{
return $this->client->get(self::ENDPOINT.'/'.$id);
}

/**
* @see https://developer.revolut.com/docs/business/update-webhook
*
* @param string $id
* @param array $json
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function update(string $id, array $json)
{
return $this->client->patch(self::ENDPOINT.'/'.$id, $json);
}

/**
* @see https://developer.revolut.com/docs/business/delete-webhook
*
* @param string $id
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function delete(string $id)
{
return $this->client->delete(self::ENDPOINT.'/'.$id);
}

/**
* @see https://developer.revolut.com/docs/business/rotate-webhook-signing-secret
*
* @param string $id
* @param array $json
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function rotateSigningSecret(string $id, array $json)
{
return $this->client->post(self::ENDPOINT.'/'.$id.'/rotate-signing-secret', $json);
}

/**
* @see https://developer.revolut.com/docs/business/failed-events
*
* @param string $id
* @param int|null $limit
* @param \DateTime|null $createdBefore
* @return mixed
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getFailedEvents(string $id, int $limit = null, \DateTime $createdBefore = null)
{
$args = [];
if (null !== $limit) {
$args['limit'] = $limit;
}
if (null !== $createdBefore) {
$args['created_before'] = $createdBefore->format(\DateTime::ISO8601);
}

$query = http_build_query($args);

$endpoint = self::ENDPOINT.'/'.$id.'/failed-events';
$endpoint = implode('?', array_filter([$endpoint, $query]));

return $this->client->get($endpoint);
}
}