oaklabs/psd2
Composer 安装命令:
composer require oaklabs/psd2
包简介
API client for banks supporting psd2 APIs.
README 文档
README
Introduction
Psd2 is a API client for Banks supporting PSD2 APIs with Oauth2 authentication.
PHP 7.1+ is required.
Installation
Psd2 can be installed through Composer, just include "oaklabs/psd2": "^1.0" to your composer.json and run composer update or composer install.
Supported Banks
Usage
Examples will be described using the Fidor Bank Gateway, but all Bank Gateways use the same methods.
Once we use fills in his/her own Bank details in the Bank OAuth2 screen, we must handle the callback to with the state and code variables in order to retrieve the Access Token and therefore being able to use the Bank API.
The Connector class is the class that will take care of instantiate the Bank Gateway.
Creating a Connector instance is the first step to use Psd2.
Sandbox
All Bank Gateways can be used in a sandbox mode, which will make the Banks hit the sandbox API endpoints to allow testing.
Retrieving the Access Token
// Let's suppose we saved the state token in a $state variable, // the random code in $code and we have a boolean $useSandbox variable // First of all we need to create an Authorization instance $authorization = new \OakLabs\Psd2\Authorization\Authorization([ 'code' => $code, 'state' => $state, 'redirect_uri' => 'the redirect_uri your set in your Bank API configuration, 'client_id' => 'the client_id of the bank API, 'client_secret' => 'the client secret of the bank API' ]); // Let's now instantiate the Bank Gateway through the Connector $tokens = (new Connector($authorization)) ->getBankGateway( 'fidor', $useSandbox ) ->retrieveTokens() ->getTokens(); // $tokens is now an instance of \League\OAuth2\Client\Token $accessToken = $tokens->getToken(); $refreshToken = $tokens->getRefreshToken(); $expiration = $tokens->getExpires(); $hasExpired = $tokens->hasExpired(); $jsonSerialized = $tokens->jsonSerialize();
Retrieving the Accounts
// After we got the Access Token and we saved it in a $tokens variable // we can interact with the Bank API // In case of a new request, create again the Authorization instance, // but this time we don't need state and code $authorization = new Authorization([ 'redirect_uri' => 'the redirect_uri your set in your Bank API configuration, 'client_id' => 'the client_id of the bank API, 'client_secret' => 'the client secret of the bank API' ]); $accounts = (new Connector($authorization)) ->getBankGateway( 'fidor', $useSandbox ) ->setAccessToken($accessToken) ->getAccountDetails(); // $accounts is an array of \OakLabs\Psd2\Psd\AccountDetail foreach ($accounts as $account) { // $account->getAccountNumber() // $account->getBic() // $account->getBalance() // $account->getBalanceAvailable() // $account->getCreatedAt() // $account->getCurrency() // $account->getCustomers() // $account->getIban() // $account->getId() }
Retrieving SEPA Transactions
// After we got the Access Token and we saved it in a $tokens variable // we can interact with the Bank API // In case of a new request, create again the Authorization instance, // but this time we don't need state and code $authorization = new Authorization([ 'redirect_uri' => 'the redirect_uri your set in your Bank API configuration, 'client_id' => 'the client_id of the bank API, 'client_secret' => 'the client secret of the bank API' ]); // Let's now retrieve the SEPA Transactions using the API Pagination $transactions = (new Connector($authorization)) ->getBankGateway( 'fidor', $useSandbox ) ->setAccessToken($accessToken) ->getSepaTransactions($page, $limit); // $transactions is an array of \OakLabs\Psd2\Transaction foreach ($transactions as $transaction) { // $transaction->getExternalUid() // $transaction->getAccountUid() // $transaction->getTransactionUid() // $transaction->getAmount() // $transaction->getIban() // $transaction->getBic() // $transaction->getDescription() // $transaction->getCreatedAt() }
Creating a SEPA Transaction
// After we got the Access Token and we saved it in a $tokens variable // we can interact with the Bank API // In case of a new request, create again the Authorization instance, // but this time we don't need state and code $authorization = new Authorization([ 'redirect_uri' => 'the redirect_uri your set in your Bank API configuration, 'client_id' => 'the client_id of the bank API, 'client_secret' => 'the client secret of the bank API' ]); // Let's suppose we have a $data array with the transaction we want to create $data = [ 'external_uid' => '1234567890', // Some uid defined by us 'account_id' => '12345', // The account_id comes from the Bank API and must be retrieved through getAccountDetails . It is NOT the account number 'amount' => 10, // Amount of the transfer 'remote_iban' => 'DE0000000000000000', // IBAN to transfer the money to 'bic' => 'ABCDEFGH', // BIC 'subject' => 'My Description' // Description ]; $transaction = (new Connector($authorization)) ->getBankGateway( 'fidor', $useSandbox ) ->setAccessToken($accessToken) ->createSepaTransaction($data); // Transaction is an instance of \OakLabs\Psd2\Transaction // $transaction->getExternalUid() // $transaction->getAccountUid() // $transaction->getTransactionUid() // $transaction->getAmount() // $transaction->getIban() // $transaction->getBic() // $transaction->getDescription() // $transaction->getCreatedAt()
Testing
Just call vendor/bin/phpunit tests to run the tests.
Contribution guidelines
PSD2 follows PSR-1, PSR-2 and PSR-4 PHP coding standards, and semantic versioning.
Pull requests are welcome.
License
PSD2 is free software distributed under the terms of the MIT license.
oaklabs/psd2 适用场景与选型建议
oaklabs/psd2 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2017 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Banking」 「psd2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 oaklabs/psd2 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 oaklabs/psd2 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 oaklabs/psd2 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Nordigen official API client for PHP
Creates an XML file for a Single Euro Payments Area (SEPA) Credit Transfer.
Library REST API Untuk Develop BCA Payment
Nordigen official API client for PHP
Nordigen API client for PHP
Fitbank SDK for PHP
统计信息
- 总下载量: 8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-24