fork-basiqio/basiq-sdk-php
Composer 安装命令:
composer require fork-basiqio/basiq-sdk-php
包简介
PHP SDK for Basiq.io API.
README 文档
README
This is the documentation for the PHP SDK for Basiq.io API
Introduction
Basiq.io PHP SDK is a set of tools you can use to easily communicate with Basiq API. If you want to get familiar with the API docs, click here.
The SDK is organized to mirror the HTTP API's functionality and hierarchy. The top level object needed for SDKs functionality is the Session object which requires your API key to be instantiated. You can grab your API key on the dashboard.
Changelog
1.1.0 Added support for secondaryLoginId
0.9.1beta - getTransactions now receives limit parameter. Fixed bug on refresh all connections
0.9.0beta - Initial release
Getting started
Now that you have your API key, you can use the following command to install the SDK:
composer require fork-basiqio/basiq-sdk-php
Next step is to import the used classes into your namespace. A list of classes you will probably use the most:
// Used to handle the token session
use Basiq\Session;
// Used to manipulate jobs and connections
use Basiq\Services\ConnectionService;
// Used to manipulate users
use Basiq\Services\UserService;
Common usage examples
Fetching a list of institutions
You can fetch a list of supported financial institutions. The function returns a list of Institution structs.
use Basiq\Session;
$session = new Session("YOUR_API_KEY");
$institutions = $session->getInstitutions();
You can specify the version of API when instantiating Session object. When the version is not specified, default version is 1.0.
use Basiq\Session;
$session = new Session("YOUR_API_KEY", "2.0");
$institutions = $session->getInstitutions();
Creating a new connection
When a new connection request is made, the server will create a job that will link user's financial institution with your app.
use Basiq\Session;
$session = new Session("YOUR_API_KEY");
$user = $session->forUser($userId);
$job = $user->createConnection($institutionId, $userId, $password[, $securityCode, $secondaryLoginId]);
// Poll our server to wait for the credentials step to be evaluated
$connection = job->waitForCredentials(1000, 60);
Fetching and iterating through transactions
In this example, the function returns a transactions list struct which is filtered by the connection->id property. You can iterate through transactions list by calling Next().
use Basiq\Session;
use Basiq\Utilities\FilterBuilder;
$session = new Session("YOUR_API_KEY");
$user = $session->forUser($userId);
$fb = new FilterBuilder();
$fb->eq("connection->id", "conn-id-213-id");
$transactions = $user->getTransactions($fb);
while ($transactions->next()) {
var_dump("Next transactions len:", len(transactions.Data))
}
API
The API of the SDK is manipulated using Services and Entities. Different services return different entities, but the mapping is not one to one.
Errors
If an action encounters an error, you will receive an HTTPResponseException instance. The class contains all available data which you can use to act accordingly.
HTTPResponseException class fields
public $response;
public $statusCode;
public $message;
Check the docs for more information about relevant fields in the error object.
Filtering
Some of the methods support adding filters to them. The filters are created using the FilterBuilder class. After instantiating the class, you can invoke methods in the form of comparison(field, value).
Example:
use Basiq\Utilities\FilterBuilder;
$fb = new FilterBuilder();
$fb->eq("connection->id", "conn-id-213-id")->gt("transaction.postDate", "2018-01-01")
$transactions = $user->getTransactions(fb);
This example filter for transactions will match all transactions for the connection with the id of "conn-id-213-id" and that are newer than "2018-01-01". All you have to do is pass the filter instance when you want to use it.
SDK API List
Services
Session
Creating a new Session object
$session = new Session("YOUR_API_KEY");
UserService
The following are APIs available for the User service
Creating a new UserService
$userService = new UserService($session);
Referencing a user
Note: The following action will not send an HTTP request, and can be used to perform additional actions for the instantiated user.
$user = $userService->forUser($userId);
Creating a new User
$user = $userService->create(["email" => "", "mobile" => ""]);
Getting a User
$user = $userService->get($userId);
Update a User
$user = $userService->update($userId, ["email" => "", "mobile" => ""]);
Delete a User
null = $userService->delete($userId);
Refresh connections
$jobs = $userService->refreshAllConnections($userId);
List all connections
$conns = $userService->getAllConnections($userId[, $filter]);
Get account
$acc = $userService->getAccount($userId, $accountId);
Get accounts
$accs = $userService->getAccounts($userId[, $filter]);
Get transaction
$transaction = $userService->getTransaction($userId, $transactionId);
Get transactions
$transactions = $userService->getTransactions($userId[, $filter]);
ConnectionService
The following are APIs available for the Connection service
Creating a new ConnectionService
$connService = new ConnectionService($session, $user);
Get connection
$connection = $connService->get($connectionId);
Get connection entity with ID without performing a http request
$connection = $connService->for($connectionId);
Create a new connection
$job = $connService->create(["institutionId" => "", "loginId" => "", "password" => "", "securityCode" => "", "secondaryLoginId" => ""]);
Update connection
$job = $connService->update($connectionId, $password);
Delete connection
null = $connService->delete($connectionId);
Get a job
$job = $connService->getJob($jobId);
Entities
Updating a user instance
$user = $user->update(["email" => "", "mobile" => ""]);
Deleting a user
null = $user->delete();
Get all of the user's accounts
$accounts = $user->getAccounts();
Get a user's single account
$account = $user->getAccount($accountId);
Get all of the user's transactions
$transactions = $user->getTransactions($filterBuilder = null, $limit = null < 500);
Get a user's single transaction
$transaction = $user->getTransaction($transactionId);
Create a new connection
$job = $user->createConnection(["institutionId" => "", "loginId" => "", "password" => "", "securityCode" => "", "secondaryLoginId" => ""]);
Refresh all connections
$jobs = $user->refreshAllConnections();
Connection
Refresh a connection
$job = $connection->refresh();
Update a connection
$job = $connection->update($password);
Delete a connection
null = $connection->delete();
Job
Get the connection id (if available)
$connectionId = $job->getConnectionId();
Get the connection
$connection = $job->getConnection();
Get the connection after waiting for credentials step resolution
(interval is in milliseconds, timeout is in seconds; in case of timeout an exception will be thrown)
$connection = $job->waitForCredentials($interval, $timeout);
Get the connection after waiting for transactions step resolution
(interval is in milliseconds, timeout is in seconds; in case of timeout an exception will be thrown)
$connection = $job->waitForTransactions($interval, $timeout);
Transaction list
Getting the next set of transactions [mut]
$next = $transactions->next();
fork-basiqio/basiq-sdk-php 适用场景与选型建议
fork-basiqio/basiq-sdk-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 63.22k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「sdk」 「finance」 「basiq」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fork-basiqio/basiq-sdk-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fork-basiqio/basiq-sdk-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fork-basiqio/basiq-sdk-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Sila PHP SDK for API Version 0.2
Simple OFX file parser
PHP SDK for Ledga.io - Programmatic double-entry ledgers for finance, gaming and multi-tenant SaaS
A PSR-7 compatible library for making CRUD API endpoints
Fitbank SDK for PHP
PHP wrapper of the dekopay finance API
统计信息
- 总下载量: 63.22k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-08-10