1.0.0 • Published 6 years ago

liquidity v1.0.0

Weekly downloads
5
License
-
Repository
-
Last release
6 years ago

Getting started

This is a sample API defined within Payment Canada as proof of concept.

How to Build

The generated SDK relies on Node Package Manager (NPM) being available to resolve dependencies. If you don't already have NPM installed, please go ahead and follow instructions to install NPM from here. The SDK also requires Node to be installed. If Node isn't already installed, please install it from here

NPM is installed by default when Node is installed

To check if node and npm have been successfully installed, write the following commands in command prompt:

  • node --version
  • npm -version

Version Check

Now use npm to resolve all dependencies by running the following command in the root directory (of the SDK folder):

npm install

Resolve Dependencies

Resolve Dependencies

This will install all dependencies in the node_modules folder.

Once dependencies are resolved, you will need to move the folder LiquidityPositionLib in to your node_modules folder.

How to Use

The following section explains how to use the library in a new project.

1. Open Project Folder

Open an IDE/Text Editor for JavaScript like Sublime Text. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.

Click on File and select Open Folder.

Open Folder

Select the folder of your SDK and click on Select Folder to open it up in Sublime Text. The folder will become visible in the bar on the left.

Open Project

2. Creating a Test File

Now right click on the folder name and select the New File option to create a new test file. Save it as index.js Now import the generated NodeJS library using the following lines of code:

var lib = require('lib');

Save changes.

Create new file

Save new file

3. Running The Test File

To run the index.js file, open up the command prompt and navigate to the Path where the SDK folder resides. Type the following command to run the file:

node index.js

Run file

How to Test

These tests use Mocha framework for testing, coupled with Chai for assertions. These dependencies need to be installed for tests to run. Tests can be run in a number of ways:

Method 1 (Run all tests)

  1. Navigate to the root directory of the SDK folder from command prompt.
  2. Type mocha --recursive to run all the tests.

Method 2 (Run all tests)

  1. Navigate to the ../test/Controllers/ directory from command prompt.
  2. Type mocha * to run all the tests.

Method 3 (Run specific controller's tests)

  1. Navigate to the ../test/Controllers/ directory from command prompt.
  2. Type mocha Liquidity positionController to run all the tests in that controller file.

To increase mocha's default timeout, you can change the TEST_TIMEOUT parameter's value in TestBootstrap.js.

Run Tests

Initialization

Authentication

In order to setup authentication in the API client, you need the following information.

ParameterDescription
oAuthClientIdOAuth 2 Client ID
oAuthRedirectUriOAuth 2 Redirection endpoint or Callback Uri

API client can be initialized as following:

const lib = require('lib');

// Configuration parameters and credentials
lib.Configuration.oAuthClientId = "oAuthClientId"; // OAuth 2 Client ID
lib.Configuration.oAuthRedirectUri = "oAuthRedirectUri"; // OAuth 2 Redirection endpoint or Callback Uri

You must now authorize the client.

Authorizing your client

Your application must obtain user authorization before it can execute an endpoint call. The SDK uses OAuth 2.0 Implicit Grant to obtain a user's consent to perform an API request on user's behalf.

This process requires the presence of a client-side JavaScript code on the redirect URI page to receive the access token after the consent step is completed.

1. Obtain consent

To obtain user's consent, you must redirect the user to the authorization page. The buildAuthorizationUrl() method creates the URL to the authorization page. You must pass the scopes for which you need permission to access.

const oAuthManager = lib.OAuthManager;
const authUrl = oAuthManager.buildAuthorizationUrl([lib.OAuthScopeEnum.READLIQUIDITYPOSITION]);
// open up the authUrl in the browser

2. Handle the OAuth server response

Once the user responds to the consent request, the OAuth 2.0 server responds to your application's access request by redirecting the user to the redirect URI specified set in Configuration.

The redirect URI will receive the access token as the token argument in the URL fragment.

https://example.com/oauth/callback#token=XXXXXXXXXXXXXXXXXXXXXXXXX

The access token must be extracted by the client-side JavaScript code. The access token can be used to authorize any further endpoint calls by the JavaScript code.

Scopes

Scopes enable your application to only request access to the resources it needs while enabling users to control the amount of access they grant to your application. Available scopes are defined in the lib/Models/OAuthScopeEnum enumeration.

Scope NameDescription
READLIQUIDITYPOSITIONread liquidity positions

Class Reference

List of Controllers

Class: LiquidityPositionController

Get singleton instance

The singleton instance of the LiquidityPositionController class can be accessed from the API Client.

var controller = lib.LiquidityPositionController;

Method: listFIsLiquidities

This is a listing operation for liquidity positions by bank

function listFIsLiquidities(bankName, bIC, callback)

Parameters

ParameterTagsDescription
bankNameRequiredName of the bank
bICRequiredName of the bank

Example Usage

    var bankName = 'PayCAN';
    var bIC = 'BBBFFF';

    controller.listFIsLiquidities(bankName, bIC, function(error, response, context) {

    
    });

Errors

Error CodeError Description
400Invalid bank

Back to List of Controllers