aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-12-25 21:13:37 -0800
committerAdam Soltys <[email protected]>2019-02-05 20:53:45 -0800
commit3bb1a1600a9788d6571d3fa736331d8b104a16b9 (patch)
treec352cea4cf55b4f3c3f2ae05d60cf66437c68827 /index.js
parentae79b2a52f4527de0e24a6fe2e9b161c804de02a (diff)
downloadcoinos-server-3bb1a1600a9788d6571d3fa736331d8b104a16b9.tar.gz
coinos-server-3bb1a1600a9788d6571d3fa736331d8b104a16b9.zip
stripe integration
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')