From 4e9c0c5198c7884cfd97cb4495f6156632e3124a Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 5 Feb 2026 16:44:47 -0800 Subject: payment forwarding --- lib/payments.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'lib/payments.ts') 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); -- cgit v1.2.3