From 7d11696ce6c555d3f0adc4a0da03d2c895d0a596 Mon Sep 17 00:00:00 2001 From: Stas Date: Thu, 18 Sep 2025 11:05:58 +0200 Subject: Add support for updating the webhook of an existing invoice This feature allows updating the webhook for an already created invoice. It will be especially useful for our ongoing integration of your wallet into our system. --- routes/invoices.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/routes/invoices.ts b/routes/invoices.ts index 430c926d..54b1a30b 100644 --- a/routes/invoices.ts +++ b/routes/invoices.ts @@ -58,6 +58,8 @@ export default { let invoice = await g(`invoice:${id}`); const user = await g(`user:${invoice.uid}`); invoice.tip = body.invoice.tip; + invoice.webhook = body.invoice.webhook; + invoice.secret = body.invoice.secret; invoice = await generate({ invoice, user }); await s(`invoice:${id}`, invoice); -- cgit v1.2.3 From 3ec79e2f938423d1442886454204973d804f37d9 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 18 Sep 2025 16:36:25 -0700 Subject: allow invoice owners to modify the webhook --- index.ts | 2 +- routes/invoices.ts | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/index.ts b/index.ts index 0ca35ec5..611c6ea5 100644 --- a/index.ts +++ b/index.ts @@ -47,7 +47,7 @@ app.get("/locations", locations.list); app.get("/invoice/:id", invoices.get); app.get("/invoices", auth, invoices.list); app.post("/invoice", optional, invoices.create); -app.post("/invoice/:id", invoices.update); +app.post("/invoice/:id", optional, invoices.update); app.post("/sign", auth, invoices.sign); app.get("/assetlinks.json", (_, res) => res.sendFile("assetlinks.json")); diff --git a/routes/invoices.ts b/routes/invoices.ts index 54b1a30b..7e98599e 100644 --- a/routes/invoices.ts +++ b/routes/invoices.ts @@ -53,13 +53,18 @@ export default { try { const { id } = req.params; const { body } = req; - if (body.invoice?.tip == null || body.invoice.tip < 0) fail("Invalid tip"); + const { tip, webhook, secret } = body.invoice; + if (tip == null || tip < 0) fail("Invalid tip"); let invoice = await g(`invoice:${id}`); - const user = await g(`user:${invoice.uid}`); - invoice.tip = body.invoice.tip; - invoice.webhook = body.invoice.webhook; - invoice.secret = body.invoice.secret; + const user = req.user || (await g(`user:${invoice.uid}`)); + + if (tip) invoice.tip = tip; + if (invoice.uid === user?.id) { + if (webhook) invoice.webhook = webhook; + if (secret) invoice.secret = secret; + } + invoice = await generate({ invoice, user }); await s(`invoice:${id}`, invoice); -- cgit v1.2.3