diff options
| author | Adam Soltys <[email protected]> | 2019-09-15 23:05:26 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2019-09-15 23:05:26 -0700 |
| commit | 765c6a42135b9334b616c26b22c816edd06e382a (patch) | |
| tree | 05da4f343358fb5e9a9083e348783f0fab973dd8 /addInvoice.js | |
| parent | 087fdd27f3683a1deb9376b7a72aa608e6fd8e6a (diff) | |
| download | coinos-server-765c6a42135b9334b616c26b22c816edd06e382a.tar.gz coinos-server-765c6a42135b9334b616c26b22c816edd06e382a.zip | |
refactor
Diffstat (limited to 'addInvoice.js')
| -rw-r--r-- | addInvoice.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/addInvoice.js b/addInvoice.js new file mode 100644 index 00000000..eca884dd --- /dev/null +++ b/addInvoice.js @@ -0,0 +1,25 @@ +module.exports = (app, db, lnb) => async (req, res) => { + let err = m => res.status(500).send(m); + let { amount, address, tip } = req.body; + + let invoice; + try { + invoice = await lnb.addInvoice({ value: amount }); + } catch (e) { + return err(e.message); + } + + let hash = invoice.payment_request; + if (address) hash = address; + + await db.Payment.create({ + user_id: req.user.id, + hash, + amount, + currency: "CAD", + rate: app.get("rates").ask, + tip + }); + + res.send(invoice); +}; |
