sverraest / revolut-php
PHP Bindings for the Revolut Business API
Installs: 28 396
Dependents: 3
Suggesters: 0
Security: 0
Stars: 45
Watchers: 7
Forks: 17
Open Issues: 12
Requires
- php: >= 7.0
- guzzlehttp/guzzle: ^6.0|^7.0
- vdbelt/oauth2-revolut: ^1.0
Requires (Dev)
- phpstan/phpstan: ^0.9.2
- phpunit/phpunit: ~5.0
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: ^3.1
README
(Unofficial) PHP API Client and bindings for the Revolut Business API.
Using this PHP API Client you can interact with your:
- ๐ฐ Accounts
- ๐ข Counterparties
- ๐ธ Payments
- ๐ฐ๏ธ Payment Drafts
- ๐ Transfers
- ๐ Transactions
- ๐น Rates
- ๐ฑ Exchanges
- ๐ Webhooks
Revolut Business API does not support - ๐งพ Invoices
Installation
Requires PHP 7.0 or higher
The recommended way to install revolut-php is through Composer:
First, install Composer:
$ curl -sS https://getcomposer.org/installer | php
Next, install the latest revolut-php:
$ php composer.phar require sverraest/revolut-php
Finally, you need to require the library in your PHP application:
require "vendor/autoload.php";
Development
- Run
composer test
andcomposer phpcs
before creating a PR to detect any obvious issues. - Please create issues for this specific API Binding under the issues section.
- Contact Revolut directly for official Revolut For Business API support.
Quick Start
RevolutPHP\Auth\Provider
Start by following the authentication instructions in the Revolut API docs:
openssl genrsa -out privatecert.pem 2048
openssl req -new -x509 -key privatecert.pem -out publiccert.cer -days 1825
Paste the generated public key on the Revolut for Business API settings page, and use the private key to instantiate a new RevolutPHP\Auth\Provider
:
$authProvider = new \RevolutPHP\Auth\Provider([
'clientId' => '{clientId}', // As shown when uploading your key
'privateKey' => 'file://{privateKeyPath}',
'redirectUri' => 'https://example.com', // The URL to redirect the user to after the authorisation step
'isSandbox' => true
]);
You can now redirect the user to the authorisation flow in the Revolut for Business app:
$url = $authProvider->getAuthorizationUrl();
Once the user has confirmed authorisation, the user will be redirected back to the redirectUri with an authorisation code attached. You can exchange this authorisation code for an access token:
$accessToken = $authProvider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
You can save this $accessToken
somewhere safe and pass it directly to the RevolutPHP\Client. The token is valid for 40 minutes. To request a new token after expiration, you can use the refresh token to get a new access token:
if( $accessToken->hasExpired() ) {
$newAccessToken = $authProvider->getAccessToken('refresh_token', [
'refresh_token' => $accessToken->getRefreshToken()
]);
}
RevolutPHP\Client
If you want to get a production
client:
use RevolutPHP\Client; $client = new Client($accessToken);
If you want to get a sandbox
client:
use RevolutPHP\Client; $client = new Client($accessToken, 'sandbox');
If you want to pass additional GuzzleHTTP options:
use RevolutPHP\Client; $options = ['headers' => ['foo' => 'bar']]; $client = new Client($accessToken, 'sandbox', $options);
Available API Operations
The following exposed API operations from the Revolut For Business API are available using the API Client.
See below for more details about each resource.
๐ฐ Accounts
Get all accounts, Get a specific account and get details for a specific account.
๐ข Counterparties
Get all counterparties, get a specific counterparty, create a new counterparty and delete a counterparty.
๐ธ Payments
Create and schedule new payments.
๐ฐ๏ธ Payment Drafts
Create, get and delete payment drafts for approval by a business owner/admin.
๐ Transfers
Create a transfer between your accounts.
๐ Transactions
Get all transactions or a subset (with queryFilters), cancel a scheduled transaction, get a specific transaction and get a transaction by the unique specified requestId.
A Transaction is either created as a Payment or a Transfer.
๐น Rates
Get exchange rates.
๐ฑ Exchanges
There are two ways of using this endpoint:
If you know the amount of currency you want to sell (e.g: I want to exchange 135.5 USD to EUR), then you should specify the amount in the "from" object.
If, on the other hand, you want to specify the amount of currency you want to buy (e.g: I want to exchange USD to receive 200 EUR), then you should specify the amount in the "to" object.
โ Please note that the "amount" field can be specified only once, either in the "from" object or in the "to" object.
๐ Webhooks
Create new webhooks.
Usage details
๐ฐ Accounts
Get all accounts
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Accounts
use RevolutPHP\Client; $client = new Client($accessToken); $accounts = $client->accounts->all();
Get one account
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Accounts/operation/getAccount
use RevolutPHP\Client; $client = new Client($accessToken); $account = $client->accounts->get('foo');
Get account details
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Accounts/operation/getAccountDetails
use RevolutPHP\Client; $client = new Client($accessToken); $account = $client->accounts->getDetails('foo');
๐ข Counterparties
Add a Counterparty
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Counterparties/operation/addCounterparty
use RevolutPHP\Client; $client = new Client($accessToken); $counterparty = $client->counterparties->create(['profile_type' => 'business', 'name' => 'TestCorp' , 'email' => 'test@sandboxcorp.com']);
Delete a Counterparty
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Counterparties/operation/deleteCounterparty
use RevolutPHP\Client; $client = new Client($accessToken); $client->counterparties->delete('foo');
Get all Counterparties
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Counterparties/operation/getCounterparties
use RevolutPHP\Client; $client = new Client($accessToken); $counterparties = $client->counterparties->all();
Get a specific Counterparty
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Counterparties/operation/getCounterparty
use RevolutPHP\Client; $client = new Client($accessToken); $counterparty = $client->counterparties->get('bar');
๐ธ Payments
Create a payment
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payments/operation/createPayment
use RevolutPHP\Client; $client = new Client($accessToken); $payment = [ 'request_id' => 'e0cbf84637264ee082a848b', 'account_id' => 'bdab1c20-8d8c-430d-b967-87ac01af060c', 'receiver' => [ 'counterparty_id': '5138z40d1-05bb-49c0-b130-75e8cf2f7693', 'account_id': 'db7c73d3-b0df-4e0e-8a9a-f42aa99f52ab' ], 'amount' => 123.11, 'currency' => 'EUR', 'reference' => 'Invoice payment #123' ]; $payment = $client->payments->create($payment);
Schedule a payment (for up to 30 days in the future)
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payments/operation/createPayment
use RevolutPHP\Client; $client = new Client($accessToken); $payment = [ 'request_id' => 'e0cbf84637264ee082a848b', 'account_id' => 'bdab1c20-8d8c-430d-b967-87ac01af060c', 'receiver' => [ 'counterparty_id': '5138z40d1-05bb-49c0-b130-75e8cf2f7693', 'account_id': 'db7c73d3-b0df-4e0e-8a9a-f42aa99f52ab' ], 'amount' => 123.11, 'currency' => 'EUR', 'reference' => 'Invoice payment #123', 'schedule_for' => '2018-04-20', ]; $payment = $client->payments->create($payment);
๐ฐ๏ธ Payment Drafts
Get all Payment Drafts
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payment-Drafts/operation/getPaymentDrafts
use RevolutPHP\Client; $client = new Client($accessToken); $paymentDrafts = $client->paymentDrafts->all();
Get a specific Payment Draft
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payment-Drafts/operation/getPaymentDraft
use RevolutPHP\Client; $client = new Client($accessToken); $counterparty = $client->paymentDrafts->get('bar');
Create a Payment Draft
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payment-Drafts/operation/createPaymentDraft
use RevolutPHP\Client; $client = new Client($accessToken); $draft = [ 'title' => 'Title of payment', 'schedule_for' => '2017-10-10', 'payments' => [[ 'currency' => 'EUR', 'amount' => 123, 'account_id' => 'db7c73d3-b0df-4e0e-8a9a-f42aa99f52ab', 'receiver' => [ 'counterparty_id' => '5138z40d1-05bb-49c0-b130-75e8cf2f7693', 'account_id' => 'bdab1c20-8d8c-430d-b967-87ac01af060c' ], 'reference' => 'External transfer' ]] ]; $draft = $client->paymentDrafts->create($draft);
Delete a payment draft
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payment-Drafts/operation/deletePaymentDraft
use RevolutPHP\Client; $client = new Client($accessToken); $client->paymentDrafts->delete('bar');
๐ Transfers
Transfer money between your accounts
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Transfers/operation/createTransfer
use RevolutPHP\Client; $client = new Client($accessToken); $transfer = [ 'request_id' => 'e0cbf84637264ee082a848b', 'source_account_id' => 'bdab1c20-8d8c-430d-b967-87ac01af060c', 'target_account_id' => '5138z40d1-05bb-49c0-b130-75e8cf2f7693', 'amount' => 123.11, 'currency' => 'EUR', 'description' => 'Expenses funding' ]; $transfer = $client->transfers->create($transfer);
๐ Transactions
Get a specific transaction (Transfer, Payment)
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payments/operation/getTransaction
use RevolutPHP\Client; $client = new Client($accessToken); $transaction = $client->transactions->get('foo');
Get a specific transaction by requestId (Transfer, Payment)
You can fetch a transaction by the requestId that you specified on creation. See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payments/operation/getTransaction
use RevolutPHP\Client; $client = new Client($accessToken); $transaction = $client->transactions->getByRequestId('inv-123456789');
Cancel a scheduled transaction
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payments/operation/cancelTransaction
use RevolutPHP\Client; $client = new Client($accessToken); $client->transactions->cancel('foo');
Get all transactions
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payments/operation/getTransactions
use RevolutPHP\Client; $client = new Client($accessToken); $transactions = $client->transactions->all();
Get all transactions with filters applied
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Payments/operation/getTransactions
Default 'count' is 100 if you want to retreive more transactions even with dates selected you should specify bigger 'count'. Highiest value of 'count' is 1000.
use RevolutPHP\Client; $client = new Client($accessToken); $searchFilters = [ 'from' => '2018-01-01', 'to' => '2018-04-01', 'count' => 50, 'counterparty' => 'foo', 'type' => 'transfer' ]; $transactions = $client->transactions->all($searchFilters);
๐น Rates
Get exchange rates
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Exchanges
use RevolutPHP\Client; $client = new Client($accessToken); $rates = $client->rates->get('USD', 'EUR', 100);
๐ฑ Exchanges
Exchange currency
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Exchanges/operation/exchangeMoney
use RevolutPHP\Client; $client = new Client($accessToken); $exchange = [ 'from' => [ 'account_id' => '7998c061-115a-4779-b7c5-7175c6502ea0', 'currency' => 'USD', 'amount' => 135.5 ], 'to' => [ 'account_id' => '35ba695a-9153-4f68-ac16-b32f228265c9', 'currency' => 'EUR' ], 'reference' => 'Time to sell', 'request_id' => 'e0cbf84637264ee082a848b' ]; $response = $client->exchanges->exchange($exchange);
๐ Webhooks
Create a webhook
See more at https://developer.revolut.com/docs/api-reference/business/#tag/Webhooks/operation/setupWebhook
use RevolutPHP\Client; $client = new Client($accessToken); $webhook = [ 'url' => 'https://foo.bar', ]; $webhook = $client->webhooks->create($webhook);
Frameworks
If you're looking to use this PHP API Client in a specific PHP framework you currently have the following options:
Errors
Currently the following errors are defined in the Revolut Business API.
About
You can follow me on ๐ฆ Twitter or โ๏ธ email me at simon[-at-]appfleet.uk.