aboutsummaryrefslogtreecommitdiffstats
path: root/addInvoice.js
diff options
context:
space:
mode:
Diffstat (limited to 'addInvoice.js')
-rw-r--r--addInvoice.js25
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);
+};