diff options
| author | Adam Soltys <[email protected]> | 2023-02-15 19:58:29 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-02-15 19:58:48 -0800 |
| commit | 12bf0c93d17d191a7bb58cfa72f9f94ee2c4d2af (patch) | |
| tree | 76c84fe466969bfea014823a2d14edafc5c41d95 /routes/payments.js | |
| parent | 3de8baffdbc1f026936c91f6976b57770c66cd8a (diff) | |
| download | coinos-server-12bf0c93d17d191a7bb58cfa72f9f94ee2c4d2af.tar.gz coinos-server-12bf0c93d17d191a7bb58cfa72f9f94ee2c4d2af.zip | |
messages endpoint
Diffstat (limited to 'routes/payments.js')
| -rw-r--r-- | routes/payments.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/routes/payments.js b/routes/payments.js index 60e3bdd2..6619c031 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -253,4 +253,34 @@ export default { res.send({ txid }); }, + + async buy({ body: { amount, number, month, year, cvc } }, res) { + let stripe = "https://api.stripe.com/v1"; + let { STRIPE: username } = process.env; + + let { id: source } = await got.post(`${stripe}/tokens`, { + form: { + "card[number]": number, + "card[exp_month]": month, + "card[exp_year]": year, + "card[cvc]": cvc + }, + username + }); + + let { status } = await got.post(`${stripe}/charges`, { + form: { + amount, + currency: "cad", + source, + description: "starter coupon" + }, + username + }); + + if (status !== "succeeded") + throw error(500, { message: "Card payment failed" }); + + res.send(status); + } }; |
