aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-04-04 15:11:17 -0700
committerAdam Soltys <[email protected]>2023-04-04 15:11:21 -0700
commita650cf9a37e4536d3ce5c2bfb346b1056b596f09 (patch)
treefb470022e56262a147003ff125c99df2efb8b53a
parenteba6aac189e3524891509ece001bb945c44bb06c (diff)
downloadcoinos-server-a650cf9a37e4536d3ce5c2bfb346b1056b596f09.tar.gz
coinos-server-a650cf9a37e4536d3ce5c2bfb346b1056b596f09.zip
deduct tip from credited amount
-rw-r--r--lib/invoices.js1
-rw-r--r--lib/payments.js12
2 files changed, 9 insertions, 4 deletions
diff --git a/lib/invoices.js b/lib/invoices.js
index 9aade609..ff372bf4 100644
--- a/lib/invoices.js
+++ b/lib/invoices.js
@@ -57,6 +57,7 @@ export let generate = async ({ invoice, user, sender, memo }) => {
currency,
hash,
rate,
+ pending: 0,
received: 0,
request_id,
prompt,
diff --git a/lib/payments.js b/lib/payments.js
index 7eab01b0..fe6a718c 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -102,13 +102,16 @@ export let debit = async (
};
export let credit = async (hash, amount, memo, ref, type = types.internal) => {
- amount = parseInt(amount);
+ amount = parseInt(amount) || 0;
let invoice = await g(`invoice:${hash}`);
if (!invoice) return warn("failed to credit", hash, ", invoice not found");
let { tip } = invoice;
+ tip = parseInt(tip) || 0;
+
if (!memo) ({ memo } = invoice);
+ if (type === types.internal) amount += tip;
let user = await g(`user:${invoice.uid}`);
@@ -127,7 +130,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
let p = {
hash,
- amount,
+ amount: parseInt(amount - tip),
uid,
rate,
currency,
@@ -139,7 +142,8 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
created: Date.now(),
};
- invoice.received += amount;
+ if (type === types.bitcoin) invoice.pending += amount;
+ else invoice.received += amount;
let balance = "balance";
if (type === types.bitcoin) {
@@ -162,7 +166,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
.incrBy(`${balance}:${uid}`, amount)
.exec();
- l("received", type, username, amount);
+ l("received", type, username, amount, tip);
emit(uid, "payment", p);
notify(user, `Received ${amount} sats`);
callWebhook(invoice, p);