Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ebc542be6 | ||
|
|
f9f3624305 | ||
|
|
78e56ee75e | ||
|
|
1017448362 |
82
README.md
82
README.md
@ -5,58 +5,68 @@
|
|||||||
npm install https://github.com/tanjalo/node-btcpay
|
npm install https://github.com/tanjalo/node-btcpay
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Private key generation
|
||||||
## Pairing
|
|
||||||
* Generate and save private key:
|
* Generate and save private key:
|
||||||
```js
|
```js
|
||||||
let btcpay = require('btcpay')
|
const btcpay = require('btcpay')
|
||||||
var keypair = btcpay.crypto.generate_keypair()
|
const privatekey = btcpay.crypto.generate_keypair().getPrivate('hex')
|
||||||
```
|
|
||||||
* Create client:
|
console.log(`PRIVATEKEY: ${privatekey}`)
|
||||||
```js
|
|
||||||
var client = new btcpay.BTCPayClient('https://btcpayserverhostname', keypair)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Store the value of "priv" in a save place, e.g. environment variables
|
||||||
|
|
||||||
|
## Pairing
|
||||||
|
|
||||||
|
After generating your private key, you have to pair your client with your BTCPay store:
|
||||||
|
|
||||||
* On BTCPay Server > Stores > Settings > Access Tokens > Create a new token, (leave PublicKey blank) > Request pairing
|
* On BTCPay Server > Stores > Settings > Access Tokens > Create a new token, (leave PublicKey blank) > Request pairing
|
||||||
* Copy pairing code:
|
* Copy pairing code:
|
||||||
* Pair client to server and save returned token:
|
* Pair client to server and save returned token:
|
||||||
```js
|
```js
|
||||||
client.pair_client(<pairing-code>).then(res => console.log(res))
|
const btcpay = require('btcpay')
|
||||||
>>> { merchant: '6gi59fB1LKxHuyY29m8tR6tRysWppk9TnuoM7wT77Las' }
|
const keypair = btcpay.crypto.load_keypair(new Buffer.from(<PRIVATEKEY>, 'hex'))
|
||||||
|
const client = new btcpay.BTCPayClient(<BTCPAYURL>, btcpay.crypto.load_keypair(Buffer.from(<PRIVATEKEY>, 'hex')))
|
||||||
|
|
||||||
|
// Pair client to server
|
||||||
|
client
|
||||||
|
.pair_client(<PAIRINGCODE>)
|
||||||
|
.then(res => console.log(res))
|
||||||
|
.catch(err => console.log(err))
|
||||||
|
|
||||||
|
>>> { merchant: 'XXXXXX' }
|
||||||
```
|
```
|
||||||
* Recreate client:
|
Store the value of "merchant" in a save place, e.g. environment variables
|
||||||
|
|
||||||
|
## Recreating a client
|
||||||
|
After pairing your client to the store, you can recreate the client as needed and use it in your code
|
||||||
```js
|
```js
|
||||||
var client = new btcpay.BTCPayClient('https://btcpayserverhostname', keypair, {merchant: '6gi59fB1LKxHuyY29m8tR6tRysWppk9TnuoM7wT77Las'})
|
const btcpay = require('btcpay')
|
||||||
|
const keypair = btcpay.crypto.load_keypair(new Buffer.from(<PRIVATEKEY>, 'hex'))
|
||||||
|
|
||||||
|
// Recreate client
|
||||||
|
const client = new btcpay.BTCPayClient(<BCTPAYURL>, keypair, {merchant: <MERCHANT>})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Get rates
|
||||||
## Creating a client
|
Fetches current rates from BitcoinAverage (using your BTCPayServer)
|
||||||
```js
|
```js
|
||||||
var client = new btcpay.BTCPayClient('https://btcpayserverhostname', keypair, {merchant: '6gi59fB1LKxHuyY29m8tR6tRysWppk9TnuoM7wT77Las'})
|
client.get_rates('BTC_USD')
|
||||||
|
.then(rates => console.log(rates))
|
||||||
|
.catch(err => console.log(err))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Create invoice
|
||||||
## Get rates
|
See [BitPay Invoice API documentation](https://bitpay.com/api#resource-Invoices)
|
||||||
```js
|
```js
|
||||||
client.get_rates('BTC_USD').then(rates => console.log(rates))
|
client.create_invoice({price: 20, currency: 'USD'})
|
||||||
|
.then(invoice => console.log(invoice.url))
|
||||||
|
.catch(err => console.log(err))
|
||||||
```
|
```
|
||||||
|
|
||||||
The first argument accept comma-separated list of currency pair.
|
### Get invoice
|
||||||
|
|
||||||
## Create invoice
|
|
||||||
See BitPay API documentation: https://bitpay.com/api#resource-Invoices
|
|
||||||
```js
|
```js
|
||||||
client.create_invoice({"price": 20, "currency": "USD"}).then(invoice => console.log(invoice.url))
|
client.get_invoice(<invoice-id>)
|
||||||
```
|
.then(invoice => console.log(invoice.status))
|
||||||
|
.catch(err => console.log(err))
|
||||||
|
|
||||||
## Get invoice
|
|
||||||
```js
|
|
||||||
client.get_invoice(<invoice-id>).then(invoice => console.log(invoice.status))
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Key Management
|
|
||||||
```js
|
|
||||||
var privateKey = keypair.getPrivate().toString('hex')
|
|
||||||
var keypair = btcpay.crypto.load_keypair(new Buffer(privateKey, "hex"))
|
|
||||||
```
|
```
|
||||||
Loading…
Reference in New Issue
Block a user