mapmyplan/basiq-sdk-php

PHP SDK for Basiq.io API.

2.2.4 2023-08-02 02:34 UTC

This package is auto-updated.

Last update: 2024-03-31 04:03:06 UTC


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.2.0 Added support for waitForAccounts, Refactored jobs search

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 mapmyplan/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 MMPBasiq\Session;

// Used to manipulate jobs and connections
use MMPBasiq\Services\ConnectionService;

// Used to manipulate users
use MMPBasiq\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 MMPBasiq\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 MMPBasiq\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 MMPBasiq\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 MMPBasiq\Session;
use MMPBasiq\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 MMPBasiq\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 an 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();