From 3bb1a1600a9788d6571d3fa736331d8b104a16b9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 25 Dec 2018 21:13:37 -0800 Subject: stripe integration --- index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'index.js') diff --git a/index.js b/index.js index e4e4d2c6..7d7cca61 100644 --- a/index.js +++ b/index.js @@ -476,6 +476,23 @@ const l = console.log } }) + app.post('/buy', auth, async (req, res) => { + const stripe = require('stripe')(config.stripe); + const { token, amount, sats } = req.body + + const charge = stripe.charges.create({ + amount, + currency: 'cad', + description: 'Bitcoin', + source: token, + }) + + req.user.balance += parseInt(sats) + await req.user.save() + + res.send(`Bought ${amount}`) + }) + app.use(function (err, req, res, next) { res.status(500) res.send('An error occurred') -- cgit v1.2.3