diff options
| author | Adam Soltys <[email protected]> | 2026-02-05 16:44:47 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-02-06 09:00:10 -0800 |
| commit | 4e9c0c5198c7884cfd97cb4495f6156632e3124a (patch) | |
| tree | ce8144806d7f88a7c3084eca3fd9669f13df54af /lib | |
| parent | 635ca5ad96c791bdd229f50c138b4f3292ae29ad (diff) | |
| download | coinos-server-4e9c0c5198c7884cfd97cb4495f6156632e3124a.tar.gz coinos-server-4e9c0c5198c7884cfd97cb4495f6156632e3124a.zip | |
payment forwarding
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/invoices.ts | 2 | ||||
| -rw-r--r-- | lib/payments.ts | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/invoices.ts b/lib/invoices.ts index 4a9d5c89..2d9d82ad 100644 --- a/lib/invoices.ts +++ b/lib/invoices.ts @@ -36,6 +36,7 @@ export const generate = async ({ invoice, user }) => { type = PaymentType.lightning, webhook, secret, + forward, } = invoice; amount = Number.parseInt(amount || 0); @@ -168,6 +169,7 @@ export const generate = async ({ invoice, user }) => { type, uid: user.id, webhook, + forward, }; if (type === "liquid") { diff --git a/lib/payments.ts b/lib/payments.ts index 011807d5..526ae5a2 100644 --- a/lib/payments.ts +++ b/lib/payments.ts @@ -315,7 +315,28 @@ export const completePayment = async (inv, p, user) => { const { id, autowithdraw, threshold, reserve, destination, username } = user; let withdrawal; if (p.confirmed) { - if (autowithdraw) { + if (inv.forward && !inv.forwarded) { + try { + // Skip forward if destination is the same user's own invoice + try { + const destInv = await getInvoice(inv.forward); + if (destInv?.uid === id) { + inv.forwarded = true; + await s(`invoice:${inv.id}`, inv); + callWebhook(inv, p); + return; + } + } catch {} + + inv.forwarded = true; + await s(`invoice:${inv.id}`, inv); + const w = await pay({ amount: p.amount, to: inv.forward, user }); + callWebhook(inv, p); + return w; + } catch (e) { + warn(username, "forward failed", inv.forward, e.message); + } + } else if (autowithdraw && p.type !== "ark") { try { const to = destination.trim(); const balance = await getBalance(id); |
