anditto / node-btcpay

BTCPay NodeJS client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-btcpay

Install

npm install https://github.com/tanjalo/node-btcpay

Pairing

  • Generate and save private key:
let btcpay = require('btcpay')
var keypair = btcpay.crypto.generate_keypair()
  • Create client:
var client = new btcpay.BTCPayClient('https://btcpayserverhostname', keypair)
  • On BTCPay Server > Stores > Settings > Access Tokens > Create a new token, (leave PublicKey blank) > Request pairing
  • Copy pairing code:
  • Pair client to server and save returned token:
client.pair_client(<pairing-code>).then(res => console.log(res))
>>> { merchant: '6gi59fB1LKxHuyY29m8tR6tRysWppk9TnuoM7wT77Las' }
  • Recreate client:
var client = new btcpay.BTCPayClient('https://btcpayserverhostname', keypair, {merchant: '6gi59fB1LKxHuyY29m8tR6tRysWppk9TnuoM7wT77Las'})

Creating a client

var client = new btcpay.BTCPayClient('https://btcpayserverhostname', keypair, {merchant: '6gi59fB1LKxHuyY29m8tR6tRysWppk9TnuoM7wT77Las'})

Get rates

client.get_rates('BTC_USD').then(rates => console.log(rates))

The first argument accept comma-separated list of currency pair.

Create invoice

See BitPay API documentation: https://bitpay.com/api#resource-Invoices

client.create_invoice({"price": 20, "currency": "USD"}).then(invoice => console.log(invoice.url))

Get invoice

client.get_invoice(<invoice-id>).then(invoice => console.log(invoice.status))

Key Management

var privateKey = keypair.getPrivate().toString('hex')
var keypair = btcpay.crypto.load_keypair(new Buffer(privateKey, "hex"))

About

BTCPay NodeJS client

License:MIT License


Languages

Language:JavaScript 100.0%