itsoft/revolut 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

itsoft/revolut

Composer 安装命令:

composer require itsoft/revolut

包简介

Revolut API in one php-class in one file without any dependencies.

README 文档

README

simple PHP library for the Revolut Business API

Build

🚀 Features

  • One file
  • No external dependencies
  • Support for older versions of PHP

💡 Motivation

Revolut API has the following bugs:

  • Scope is not supported. E.g. you cannot give read-only access to your Revolut application. It's a shame.
  • No possibility to revoke the token. Again it's a shame. You can ask for a new token (refresh token) and not save it, but it's a kludge.
  • No possibility to add a second account (IBAN) to a counterparty. Delete and create is a bad solution due to old payments are linked to the counterparty uuid. We can add several counterparties with different IBANs, and get into a mess while distinguishing between 2 different companies with the same name.
  • It's very bad there's no MFA when sending payments via the API. We need a second independent channel to confirm (sign) payments. It can be SMS or TOTP.

Revolut API is very unsafe.

Revolut Business API Documentation.

🍭 Demo

You can find a demo app using this library here: https://github.com/maslick/revolutor

✅ Installation

composer require itsoft/revolut

🎱 Usage

cd your_secret_keys_dir/revolut
openssl genrsa -out privatekey.pem 1024
openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 1825
more publickey.cer

Add the contents of publickey.cer to Revolut Business API settings page and point your OAuth redirect URI. Save ClientId and Enable API access to your account.

Create insecure revolut.cfg.php

This config saves tokens in files. You can save them to a database or other places, but for security reasons better not to save them, see the next section Secured revolut.cfg.php.

<?php
$ROOT_PATH = '/www/your-crm...';

require_once $ROOT_PATH . 'vendor/autoload.php';
$path2token = $ROOT_PATH . 'token/revolut.txt';
$path2refresh_token = $ROOT_PATH . 'token/revolut_refresh_token.txt';


$a_token = json_decode(file_get_contents($path2token));
$r_token = json_decode(file_get_contents($path2refresh_token));

$params = [
	'apiUrl' => 'https://b2b.revolut.com/api/1.0',
	'authUrl' => 'https://business.revolut.com/app-confirm', 
	'clientId' => 'YOUR-CLIENT-ID',
	'privateKey' => file_get_contents('your_secret_keys_dir/revolut/privatekey.pem'),
	'redirectUri' => 'https://your_site.com/redirect_uri/', //OAuth redirect URI
	'accessToken' => $a_token->access_token,
	'accessTokenExpires' => $a_token->expires,
	'refreshToken' => $r_token->refresh_token,
	'refreshTokenExpires' => $r_token->expires,
	'saveAccessTokenCallback' => function ($access_token, $expires) use ($path2token) {file_put_contents($path2token, json_encode(['access_token' => $access_token, 'expires' => $expires]));},
	'saveRefreshTokenCallback' => function ($refresh_token, $expires) use ($path2refresh_token) {file_put_contents($path2refresh_token, json_encode(['refresh_token' => $refresh_token, 'expires' => $expires]));},
	'logErrorCallback' => function ($error){mail('your_email@domin.com', 'Revolut API Error', $error);}
];


// for debug you can use
// $params['apiUrl'] =  'https://sandbox-b2b.revolut.com/api/1.0';
// $params['authUrl'] = 'https://sandbox-business.revolut.com/app-confirm';

$revolut = new \ITSOFT\Revolut\Revolut($params);

Secured revolut.cfg.php

<?php
$ROOT_PATH = '/www/your-crm...';

require_once $ROOT_PATH . 'vendor/autoload.php';
$params = [
	'apiUrl' => 'https://b2b.revolut.com/api/1.0',
	'authUrl' => 'https://business.revolut.com/app-confirm',
	'clientId' => 'YOUR-CLIENT-ID',
	'privateKey' => file_get_contents('your_secret_keys_dir/revolut/privatekey.pem'),
	'redirectUri' => 'https://your_site.com/redirect_uri/', //OAuth redirect URI
	'accessToken' => '',
	'accessTokenExpires' => '',
	'refreshToken' => '',
	'refreshTokenExpires' => '',
	'saveAccessTokenCallback' => function ($access_token, $expires){},
	'saveRefreshTokenCallback' => function ($refresh_token, $expires){},
	'logErrorCallback' => function ($error){mail('your_email@domin.com', 'Revolut API Error', $error);}
];


// for debug you can use
// $params['apiUrl'] =  'https://sandbox-b2b.revolut.com/api/1.0';
// $params['authUrl'] = 'https://sandbox-business.revolut.com/app-confirm';


$revolut = new \ITSOFT\Revolut\Revolut($params);

Code for OAuth redirect URI (https://your_site.com/redirect_uri/)

require_once 'revolut.cfg.php';

if(isset($_GET['code'])) $revolut->exchangeCodeForAccessToken();
elseif(!$revolut->accessToken) $revolut->goToConfirmationURL();
  
print "<pre><h2>accounts</h2>\n";
print_r($revolut->accounts());

print "<h2>counterparties</h2>\n";
print_r($revolut->counterparties());

print "<h2>getExchangeRate</h2>\n";
print_r($revolut->getExchangeRate(['from'=>'USD', 'to'=>'EUR']));
print_r($revolut->getExchangeRate(['from'=>'EUR', 'to'=>'USD']));

print "<h2>transactions</h2>\n";
print_r($revolut->transactions());

Create payment and other methods

$revolut->createPayment($params); 

For $params see tutorials-make-a-payment-create-payment and api-reference createPayment.

For other methods see https://github.com/itsoft7/revolut-php/blob/master/src/Revolut.php

itsoft/revolut 适用场景与选型建议

itsoft/revolut 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 971 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 01 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「single」 「revolut」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 itsoft/revolut 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 itsoft/revolut 我们能提供哪些服务?
定制开发 / 二次开发

基于 itsoft/revolut 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 971
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 23
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-06