aboutsummaryrefslogtreecommitdiffstats
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
parentae79b2a52f4527de0e24a6fe2e9b161c804de02a (diff)
downloadcoinos-server-3bb1a1600a9788d6571d3fa736331d8b104a16b9.tar.gz
coinos-server-3bb1a1600a9788d6571d3fa736331d8b104a16b9.zip
stripe integration
-rw-r--r--index.js17
-rw-r--r--package.json1
-rw-r--r--yarn.lock9
3 files changed, 27 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')
diff --git a/package.json b/package.json
index 5389b455..a74d0ee0 100644
--- a/package.json
+++ b/package.json
@@ -65,6 +65,7 @@
"socket.io-client": "^2.0.4",
"socketio-jwt-auth": "https://github.com/adcentury/socketio-jwt-auth",
"sql-template-strings": "^2.2.2",
+ "stripe": "^6.20.0",
"twilio": "^2.11.1",
"zeromq": "^4.6.0"
},
diff --git a/yarn.lock b/yarn.lock
index 248106d3..ac32430b 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -7157,6 +7157,15 @@ strip-outer@^1.0.0:
dependencies:
escape-string-regexp "^1.0.2"
+stripe@^6.20.0:
+ version "6.20.0"
+ resolved "https://registry.yarnpkg.com/stripe/-/stripe-6.20.0.tgz#b862165da39507194962e8b91131fbf537fd81c1"
+ integrity sha512-a/F/hyuQpUKuiY1zyK1PcLiWBsEUR8WbsAJ7UP1xHTPyWrRZV0zWGAjhL1p0SKXPfuC5EMYNKUplmod7pBBsyg==
+ dependencies:
+ lodash.isplainobject "^4.0.6"
+ qs "~6.5.1"
+ safe-buffer "^5.1.1"
+
supports-color@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"