Install
npm install blockchain-payments
About
Blockchain.info payment api (v2) module
Example
Creation of an address
const BlockchainPayments = require("blockchain-payments");
const express = require("express");
const app = express();
const xpub = "xpub";
const key = "key";
const notifySecret = "secret";
const blockchain = new BlockchainPayments(xpub, key, notifySecret);
app.post('/payments/bitcoin/address/', (req, res, next) => {
blockchain.createAddress({
callback: 'http://example.com'
}, {
someCallbackField1: '1',
someCallbackFieldw2: '2',
}).then((data) => {
console.log(data)
})
});
Conversation of currencies
BlockchainPayments.toBTC(500, 'USD').then((amountInBTC) => {
});
Handling of a notification
const successHandler = (data, callback) => {
};
const errorHandler = (err, meta) => {
};
let confirmationsCount = 8;
app.get('payments/notification/', blockchain.notify(successHandler, errorHandler, confirmationsCount));
Description
You can write custom notification handler, but library version includes data/authentication validation and automatically sends all headers in the necessary format
API
.constructor(xpub, key, notifySecret, [notifyCallback])
you can find xpub and key in your blockchain account, notifySecret you have to come up yourself
.createAddress(query, [callbackQuery])
returns promise, creates bitcoin address for client payment
you can set callback url query params with callbackQuery as js object
.notify(fn, onError, [confirmationsCount])
notification handler, it is "connect" middleware
Class methods
.toBTC(amount, currency)
converts an amount from a given currency to BTC, returns promise