aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js17
1 files changed, 17 insertions, 0 deletions
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')