From 63aac564602bb65065fee5fdb8f29abdacd388d4 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Fri, 23 Feb 2024 12:19:36 -0800 Subject: payment memos --- lib/payments.js | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'lib/payments.js') diff --git a/lib/payments.js b/lib/payments.js index ff7052ca..54c901e6 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -6,7 +6,17 @@ import { v4 } from "uuid"; import { notify } from "$lib/notifications"; import { db, g, s, t } from "$lib/db"; import { l, err, warn } from "$lib/logging"; -import { btc, fail, getInvoice, sleep, wait, SATS, sats } from "$lib/utils"; +import { + f, + btc, + fail, + getInvoice, + sleep, + wait, + SATS, + sats, + formatReceipt, +} from "$lib/utils"; import { callWebhook } from "$lib/webhooks"; import got from "got"; import { mqtt1, mqtt2 } from "$lib/mqtt"; @@ -36,9 +46,10 @@ export let debit = async ({ type = types.internal, rate, }) => { - if (type !== types.internal && await g("freeze")) fail("Problem sending payment"); - if (!user.unlimited && amount > 1000000) - fail(`⚡️${amount} exceeds max withdrawal of ⚡️1,000,000`); + if (type !== types.internal && (await g("freeze"))) + fail("Problem sending payment"); + // if (!user.unlimited && amount > 1000000) + // fail(`⚡️${amount} exceeds max withdrawal of ⚡️1,000,000`); let ref; let { id: uid, currency, username } = user; if (!rate) rate = store.rates[currency]; @@ -144,6 +155,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { let id = v4(); let p = { id, + iid: inv.id, hash, amount: parseInt(amount - tip), uid, @@ -186,17 +198,29 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { callWebhook(inv, p); l(username, "received", type, amount); + // let items = ""; + // for (let i of inv.items) { + // items += `${i.quantity} ${i.name} ${f( + // i.price * i.quantity, + // inv.currency, + // )}\n`; + // } + // + // console.log(items); + + let items = formatReceipt(inv.items, inv.currency); + if (config.mqtt1) { mqtt1.publish( username, - `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`, + `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}:${p.memo}:${items}`, ); } if (config.mqtt2) { mqtt2.publish( username, - `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}`, + `pay:${p.amount}:${p.tip}:${p.rate}:${p.created}:${p.id}:${p.memo}:${items}`, ); } -- cgit v1.2.3