aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-02-23 12:19:36 -0800
committerAdam Soltys <[email protected]>2024-02-23 12:19:36 -0800
commit63aac564602bb65065fee5fdb8f29abdacd388d4 (patch)
treeb561b8c54e9fd3bca06a8f57e0e017dda5d7afe1 /lib/payments.js
parentaf0a5642af202441dcc8aa49a0876941fa5a5f19 (diff)
downloadcoinos-server-63aac564602bb65065fee5fdb8f29abdacd388d4.tar.gz
coinos-server-63aac564602bb65065fee5fdb8f29abdacd388d4.zip
payment memos
Diffstat (limited to 'lib/payments.js')
-rw-r--r--lib/payments.js36
1 files changed, 30 insertions, 6 deletions
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}`,
);
}