Created
December 5, 2016 23:10
-
-
Save bitgord/6ab9bcbdd83d0967b203ac12e057cbe5 to your computer and use it in GitHub Desktop.
Bitcoin payments with nodejs and Bitpay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//First sign up for an account with BiyPay and create a new API key | |
//Download bitpay-node | |
sudo npm install bitpay-node | |
//Go to node console and require bitpay-node | |
Bitpay = require('bitpay-node') | |
//Create new Bitpay client | |
var client = new Bitpay.Client({ apiKey: '' }) | |
//Create invoice | |
client.createInvoice({ price: [[input price]], currency: 'BTC' }, function(err, invoice){ console.log(invoice) }) | |
//You now have an invoice on the url that is returned to console | |
//Install Yeoman and create express app | |
npm install yo | |
yo express | |
//In app.js add path for payments api | |
app.post('payments/:id', payments.notification); | |
//Copy user route to make a payments route | |
/* Add code below to payments route */ | |
exports.notification = function(req, res) { | |
console.log(req.body); | |
res.status(200); | |
}); | |
//Git Init and heroku init | |
git init | |
heroku create [[insert name]] | |
git push heroku master | |
//Create SSL certificate, which is required by BitPay servers | |
brew install openssl | |
heroku addons:create ssl:endpoint | |
//Export API key | |
export BITPAY_API_KEY=[[insert key]] | |
//In node console run these commands | |
var Bitpay = require('bitpay-node'); | |
var client = new Bitpay.Client({ apiKey: process.env.BITPAY_API_KEY }); | |
//Check it went through, apiKey should be in the client object | |
client | |
//Create more data | |
var invoiceOptions = { | |
... price: 0.001, | |
... currency: 'BTC' | |
... }; | |
invoiceOptions.transactionSpeed = 'high' | |
invoiceOptions.fullNotifications = true | |
//Create invoice with these options | |
client.createInvoice(invoiceOptions, function(err, invoice) { | |
console.log(invoice); | |
}) | |
//You have now made an invoice | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment