diff options
| -rw-r--r-- | index.js | 1 | ||||
| -rw-r--r-- | routes/payments.js | 20 |
2 files changed, 20 insertions, 1 deletions
@@ -64,6 +64,7 @@ app.get("/fund/:name/withdraw", payments.withdraw); app.post("/take", auth, payments.take); app.post("/print", auth, payments.print); app.post("/send/:lnaddress/:amount", auth, payments.lnaddress); +app.post("/send", auth, payments.internal); app.post("/gateway", payments.gateway); app.post("/replace", auth, payments.replace); diff --git a/routes/payments.js b/routes/payments.js index e16156b5..1ae87916 100644 --- a/routes/payments.js +++ b/routes/payments.js @@ -1,9 +1,10 @@ import config from "$config"; import { emit } from "$lib/sockets"; +import { generate } from "$lib/invoices"; import { v4 } from "uuid"; import { db, g, s, t } from "$lib/db"; import { l, err, warn } from "$lib/logging"; -import { bail, fail, getInvoice, btc, sats, SATS } from "$lib/utils"; +import { bail, fail, getInvoice, btc, sats, SATS, getUser } from "$lib/utils"; import { requirePin } from "$lib/auth"; import { completePayment, @@ -457,4 +458,21 @@ export default { bail(res, e.message); } }, + + async internal({ body: { username, amount }, user: sender }, res) { + let recipient = await getUser(username); + let inv = await generate({ + invoice: { amount, type: "lightning" }, + user: recipient, + sender, + }); + + let { hash } = inv; + let memo; + + let p = await debit({ hash, amount, memo, user: sender }); + await credit(hash, amount, memo, recipient.id); + + res.send(p); + }, }; |
