aboutsummaryrefslogtreecommitdiffstats
path: root/addInvoice.js
blob: fa1833215a7d965788dba8b67718180464120cb9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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")[req.user.currency],
    tip,
    confirmed: 1,
    asset: 'LNBTC',
  });

  res.send(invoice);
};