npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bankly

v1.2.7

Published

Javascript bindings for Acesso Bankly API

Downloads

16

Readme

Bankly (Acesso)

Unnofficial Javascript class to access Bankly (by Acesso) API.

API Docs here.

PHP port here.

Installing

This class is available at NPM.

npm i bankly

Usage

Authentication and token refreshing is handled by the class itself.

Start by importing the class and creating an instance supplying your client_id and client_secret provided by Acesso.

import Bankly from 'bankly';
// or
const Bankly = require('bankly')
let bankly = new Bankly('client_id', 'client_secret')

If you are using the sandbox environment, just do:

let bankly = new Bankly('client_id', 'client_secret', 'sandbox')

Getting account balance

Provide the branch and account number (without hyphen) to get the balance.

bankly.getBalance('0001', '1234')

This method returns a promise that resolves to a JSON object.

Getting account statement

Provide:

  • Branch (string)
  • Account number (string)
  • Offset (number, starts at 0)
  • Limit (number, > 0)
  • Details (optional, boolean, default true)
  • DetailsLevelBasic (optional, boolean, default true)
bankly.getStatement('0001', '1234', 0, 10)

This method returns a promise that resolves to a JSON object.

Getting account events

Provide:

  • Branch (string)
  • Account number (string)
  • Page (number, starts at 1)
  • Pagesize (number, > 0)
  • IncludeDetails (optional, boolean, default true)
bankly.getEvents('0001', '1234', 1, 10)

This method returns a promise that resolves to a JSON object.

Performing transfers

Note: this method causes subtraction of real money.

In order to specify an origin and destination bank account, you must create two BankAccount objects. You'll need to import it from the library first:

import Bankly, { BankAccount } from 'bankly'
// or
const { BankAccount } = require('bankly')
// or
const BankAccount = require('bankly').BankAccount

A bank account instance must be created receiving an object with the following properties:

  • branch (string): account branch
  • account (string): account number (no hyphen)
  • document (string): account holder's CPF or CNPJ (numbers only)
  • name (string): account holder name
  • bankCode (string, optional): bank code (see below, defaults to Acesso's 332)

Then you will use the transfer() method to perform the actual transfer, providing:

  • The amount in centavos (1 BRL = 100 centavos)
  • Reference or description (human-readable string)
  • Sender (a BankAccount object)
  • Recipient (a BankAccount Object)

Example:

let from = new BankAccount({
	branch: '0001',
	account: '1234',
	document: '00000000000000',
	name: 'Company LTDA'
})

let to = new BankAccount({
	bankCode: '123',
	branch: '1234',
	account: '12345',
	document: '00000000000',
	name: 'John Doe'
})

// transfer BRL 5 (R$ 5)
bankly.transfer(500, 'test', from, to)

This method returns a promise that resolves to an object. This object contains an "authenticationCode" property with a string, with a reference code for the transaction that you will use to check its status later.

Getting transfer status

Use the following method to retrieve a transaction's status. You will need to provide:

  • The origin branch
  • The origin account number
  • The AuthenticationId (that you receive as authenticationCode from the transfer method)
bankly.getTransferStatus('0001', '1234', 'AuthenticationId')

This method returns a promise that resolves to a JSON object.

Getting banks list

You can get a list of banks and payment institutions with respective codes from the Central Bank (Bacen). No authentication is needed. You can either call this getter from your instance:

let banks = await bankly.bankList

Or use the static getter directly (no class instancing needed):

let banks = await Bankly.bankList

This getter returns a JSON array. You can also perform this request using your browser by clicking here.

Debugging

You can define a function that receives debug logs (as strings) from your instance of the class.

bankly.debug = console.log

Directly calling the API

You can use these functions to direct call the API without having to care about the authorization step:

bankly._get()
bankly._post()
bankly._postJSON()

All these functions receive three arguments:

  • path (string): the path to call (starting with slash)
  • variables (object, default is false): a key-value object containing variables you want to send. They will be sent as query parameters for _get(), as URLEncoded body for _post() or as JSON-encoded body for _postJSON().
  • headers: a key-value object containing additional headers

These functions return a promise that resolve to a JSON object, decoded from the API response.