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 +++++++++++++++++ package.json | 1 + yarn.lock | 9 +++++++++ 3 files changed, 27 insertions(+) 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" -- cgit v1.2.3