0.0.3 • Published 7 years ago

bitwala v0.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

API Node Client

Node client for the Bitwala.

For a detailed explanation of our API routes, please check out the documentation

Quick Start

  1. Go to https://my.bitwala.io/api-apps
  2. Create an app and store your token ID and secret
  3. yarn add bitwala
import bitwala from 'bitwala';

const token = {
  _id: 'SuBnyc6d564P49Uuls',
  secret: 'LTdFE6hw725yh0aM4m4azACEZSpNrtl4aowFjCZetSAAPBaGN3Ecq7FgMSR5b3Va'
};

const client = bitwala.client({
  token: token,
  env: 'sandbox'
});

client.info('inputs')
  .then(data => console.log(data))
  .catch(err => console.error(err));

/*
[
    {
        "collection": "BitcoinInvoices",
        "currency": "XBT"
    }
]
*/

Environments

The client can be initialised with the sandbox or production env.

For a breakdown of the differences, see our docs.

Methods

EndpointMethodClient
/infoGET.info()
/info/inputsGET.info('inputs')
/info/outputsGET.info('outputs')
/authGET.auth()
/transactions?page=1GET.transactions.get({page: 1})
/transactions?transactionId=transactionIdGET.transactions.get({transactionId: 'YRTvEJxAEm3MB1GI'})
/transactions?ref=refGET.transactions.get({ref: 'YRTvEJxAEm3MB1GI'})
/transactionsPOST.transactions.create(yourTransactionObj})
/transactions/refreshPOST.transactions.refresh({transactionId: transactionId}})
/transactions/refreshPOST.transactions.refresh({transactionId: transactionId}})

Promises / Callbacks

All api calls can be used with promises or callbacks.

With callbacks

client.info((e, data) => {
  if (e) {
    return console.error(e);
  }
  console.log(data);
})

With promises

client.info()
  .then(data => console.log(data));

With await and async (if you're using ES7)

(async function () {
  let data;

  try {
    await data = client.info();
  } catch (err) {
    console.error(err);
  }

  console.log(data);
})();

Examples

Get a transaction by ref

client.transactions.get({ref: 'My custom id'});
  .then(r => console.log(r))
  .catch(err => console.log(err));

Create a transfer to Germany

client.transactions.create({
  ref: 'My custom id',
  webhookUrl: '...', // example: https://test.com/callbacks/bitwala
  inputs: [{
    collection: 'BitcoinInvoices',
    doc: {
      currency: 'XBT',
      convertedCurrency: 'EUR',
      convertedAmount: 100
    }
  }],
  outputs: [{
    collection: 'BankTransfers',
    doc: {
      amount: 100,
      currency: 'EUR',
      reference: 'January Salary',
      bankAccount: {
        recipientType: 'INDIVIDUAL',
        firstName: 'Satoshi',
        lastName: 'Nakamoto',
        iban: 'DE89370400440532013000',
        currency: 'EUR'
      }
    }
  }]
}).then(r => console.log(r))
  .catch(err => console.log(err));

Receive and verify webhooks

import bitwala from 'bitwala';
import express from 'express';
import bodyParser from 'body-parser';

const token = {
  _id: 'SuBnyc6d564P49Uuls',
  secret: 'LTdFE6hw725yh0aM4m4azACEZSpNrtl4aowFjCZetSAAPBaGN3Ecq7FgMSR5b3Va'
};

const router = express.Router();

router.use(bodyParser.json({
  limit: '100kb',
  type: 'application/*+json'
}));

router.post('/callbacks/bitwala', function (req, res, next) {
  // !important: use body-parser
  const signatureOk = bitwala.verifications.verifyCallback(req, token.secret);
  ...
  res.success();
});
...
0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago