All Projects โ†’ sverraest โ†’ revolut-php

sverraest / revolut-php

Licence: other
๐Ÿ’ณ PHP Bindings for the Revolut Business API

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to revolut-php

cv4pve-api-dotnet
Proxmox VE Client API .Net C#
Stars: โœญ 25 (-32.43%)
Mutual labels:  api-client
pushover
Go wrapper for the Pushover API
Stars: โœญ 112 (+202.7%)
Mutual labels:  api-client
keen-analysis.js
A light JavaScript client for Keen
Stars: โœญ 40 (+8.11%)
Mutual labels:  api-client
nodejs-searchitunes
Lightweight node.js module to quickly search Apple's iTunes Store for music, movies, apps, etc.
Stars: โœญ 25 (-32.43%)
Mutual labels:  api-client
mite-cli
command line interface for time tracking service mite.yo.lk
Stars: โœญ 17 (-54.05%)
Mutual labels:  api-client
CompaniesHouse.NET
A simple .NET client wrapper for CompaniesHouse API
Stars: โœญ 28 (-24.32%)
Mutual labels:  api-client
wiesbaden
Client to Access Databases from the Federal Statistical Office of Germany (DESTATIS)
Stars: โœญ 32 (-13.51%)
Mutual labels:  api-client
hcloud-rust
Unofficial Rust crate for accessing the Hetzner Cloud API
Stars: โœญ 22 (-40.54%)
Mutual labels:  api-client
nzb
Get Things Doneยฎ with nzb, a beautiful terminal interface for Nozbe. Inspired by Wunderline
Stars: โœญ 35 (-5.41%)
Mutual labels:  api-client
tweetsOLAPing
implementing an end-to-end tweets ETL/Analysis pipeline.
Stars: โœญ 24 (-35.14%)
Mutual labels:  api-client
Taviloglu.Wrike.ApiClient
.NET Client for Wrike API
Stars: โœญ 24 (-35.14%)
Mutual labels:  api-client
ynab.go
Go client for the YNAB API. Unofficial. It covers 100% of the resources made available by the YNAB API.
Stars: โœญ 49 (+32.43%)
Mutual labels:  api-client
downcloud
Download your own Soundcloud tracks (uncompressed)
Stars: โœญ 22 (-40.54%)
Mutual labels:  api-client
fetch
Isomorphic Wordpress API client and React hooks - super tiny, super fast.
Stars: โœญ 47 (+27.03%)
Mutual labels:  api-client
pychannels
Python library for querying and controlling the Channels app.
Stars: โœญ 15 (-59.46%)
Mutual labels:  api-client
go-amazon-product-advertising-api
Go Client Library for Amazon Product Advertising API
Stars: โœญ 51 (+37.84%)
Mutual labels:  api-client
pocket-api
A python wrapper around GetPocket API V3.
Stars: โœญ 103 (+178.38%)
Mutual labels:  api-client
messaging-apis
Messaging APIs for multi-platform
Stars: โœญ 1,759 (+4654.05%)
Mutual labels:  api-client
js-http-client
[DEPRECATED] Official Textile JS HTTP Wrapper Client
Stars: โœญ 29 (-21.62%)
Mutual labels:  api-client
dns
dns is a simple CLI tool for DNS-LG API
Stars: โœญ 28 (-24.32%)
Mutual labels:  api-client

RevolutPHP

(Unofficial) PHP API Client and bindings for the Revolut Business API.

Build Status codecov Scrutinizer Code Quality Maintainability Latest Stable Version License composer.lock

Using this PHP API Client you can interact with your:

  • ๐Ÿ’ฐ Accounts
  • ๐Ÿข Counterparties
  • ๐Ÿ’ธ Payments
  • ๐Ÿ•ฐ๏ธ Payment Drafts
  • ๐Ÿ”€ Transfers
  • ๐Ÿ“Š Transactions
  • ๐Ÿ’น Rates
  • ๐Ÿ’ฑ Exchanges
  • ๐Ÿ”— Webhooks

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 and composer 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 privatekey.pem 1024
openssl req -new -x509 -key privatekey.pem -out publickey.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://revolut-engineering.github.io/api-docs/#business-api-business-api-accounts-get-accounts

use RevolutPHP\Client;

$client = new Client($accessToken);
$accounts = $client->accounts->all();

Get one account

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-accounts-get-account

use RevolutPHP\Client;

$client = new Client($accessToken);
$account = $client->accounts->get('foo');

Get account details

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-accounts-get-account-details

use RevolutPHP\Client;

$client = new Client($accessToken);
$account = $client->accounts->getDetails('foo');

๐Ÿข Counterparties

Add a Counterparty

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-counterparties-add-revolut-counterparty

use RevolutPHP\Client;

$client = new Client($accessToken);
$counterparty = $client->counterparties->create(['profile_type' => 'business', 'name' => 'TestCorp' , 'email' => '[email protected]']);

Delete a Counterparty

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-counterparties-delete-counterparty

use RevolutPHP\Client;

$client = new Client($accessToken);
$client->counterparties->delete('foo');

Get all Counterparties

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-counterparties-get-counterparties

use RevolutPHP\Client;

$client = new Client($accessToken);
$counterparties = $client->counterparties->all();

Get a specific Counterparty

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-counterparties-get-counterparty

use RevolutPHP\Client;

$client = new Client($accessToken);
$counterparty = $client->counterparties->get('bar');

๐Ÿ’ธ Payments

Create a payment

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-payments-create-payment

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://revolut-engineering.github.io/api-docs/#business-api-business-api-payments-schedule-payment

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://revolut-engineering.github.io/api-docs/#business-api-get-payment-drafts

use RevolutPHP\Client;

$client = new Client($accessToken);
$paymentDrafts = $client->paymentDrafts->all();

Get a specific Payment Draft

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-get-payment-drafts-get-payment-draft-by-id

use RevolutPHP\Client;

$client = new Client($accessToken);
$counterparty = $client->paymentDrafts->get('bar');

Create a Payment Draft

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-payment-drafts-create-a-payment-draft

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://revolut-engineering.github.io/api-docs/#business-api-business-api-get-payment-drafts-delete-payment-draft

use RevolutPHP\Client;

$client = new Client($accessToken);
$client->paymentDrafts->delete('bar');

๐Ÿ”€ Transfers

Transfer money between your accounts

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-transfers-create-transfer

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://revolut-engineering.github.io/api-docs/#business-api-business-api-payments-get-transaction

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://revolut-engineering.github.io/api-docs/#business-api-business-api-payments-get-transaction

use RevolutPHP\Client;

$client = new Client($accessToken);
$transaction = $client->transactions->getByRequestId('inv-123456789');

Cancel a scheduled transaction

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-payments-cancel-payment

use RevolutPHP\Client;

$client = new Client($accessToken);
$client->transactions->cancel('foo');

Get all transactions

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-payments-get-transactions

use RevolutPHP\Client;

$client = new Client($accessToken);
$transactions = $client->transactions->all();

Get all transactions with filters applied

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-payments-get-transactions

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://revolut-engineering.github.io/api-docs/#business-api-business-api-exchanges-get-exchange-rates

use RevolutPHP\Client;

$client = new Client($accessToken);

$rates = $client->rates->get('USD', 'EUR', 100);

๐Ÿ’ฑ Exchanges

Exchange currency

See more at https://revolut-engineering.github.io/api-docs/#business-api-business-api-exchanges-exchange-currency

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://revolut-engineering.github.io/api-docs/#business-api-web-hooks

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:

Framework Package
Symfony https://github.com/sverraest/revolut-php-bundle
Laravel https://github.com/vdbelt/laravel-revolut

Errors

Currently the following errors are defined in the Revolut Business API.

Error Description
400 Bad request Your request is invalid.
401 Unauthorized Your API key is wrong.
403 Forbidden Access to the requested resource or action is forbidden.
404 Not Found The requested resource could not be found.
405 Method Not Allowed You tried to access an endpoint with an invalid method.
406 Not Acceptable You requested a format that isn't JSON.
429 Too Many Requests You're sending too many requests.
500 Internal Server Error We had a problem with our server. Try again later.
503 Service Unavailable We're temporarily offline for maintenance. Please try again later.

About

You can follow me on ๐Ÿฆ Twitter or โœ‰๏ธ email me at simon[-at-]appfleet.uk.


www.appfleet.uk

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].