aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-03-11 10:20:46 -0800
committerAdam Soltys <[email protected]>2023-03-11 10:20:46 -0800
commit5955ff6969a5301c4413631b76cf2300d193f8ed (patch)
tree92d1269a098cb7c764ca92f7a40af9ee236ae5b1 /lib/payments.js
parent7fec7cc3e7c51a9892869732b5bfe65922ee7818 (diff)
downloadcoinos-server-5955ff6969a5301c4413631b76cf2300d193f8ed.tar.gz
coinos-server-5955ff6969a5301c4413631b76cf2300d193f8ed.zip
separate tips from amounts
Diffstat (limited to 'lib/payments.js')
-rw-r--r--lib/payments.js22
1 files changed, 9 insertions, 13 deletions
diff --git a/lib/payments.js b/lib/payments.js
index ff6e9ba5..0a59a868 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -13,7 +13,7 @@ export const types = {
bitcoin: "bitcoin",
lightning: "lightning",
pot: "pot",
- classic: "classic"
+ classic: "classic",
};
export let debit = async (
@@ -25,7 +25,7 @@ export let debit = async (
type = types.internal,
id = v4()
) => {
- let ref, tip;
+ let ref;
let { id: uid, currency, username } = user;
let rate = store.rates[currency];
@@ -36,7 +36,7 @@ export let debit = async (
if (Math.abs(invoice.rate / rate - 1) < 0.01) rate = invoice.rate;
}
- amount = parseInt(amount);
+ let tip = parseInt(invoice?.tip) || null;
if (!amount || amount < 0) fail("Amount must be greater than zero");
@@ -54,24 +54,20 @@ export let debit = async (
user.username,
balance,
amount,
+ tip,
fee,
ourfee,
- amount + fee + ourfee
+ amount + fee + ourfee + tip
);
- if (balance < amount + fee + ourfee) fail("Insufficient funds");
+ if (balance < amount + tip + fee + ourfee) fail("Insufficient funds");
await db
.multi()
.decrBy(`credit:${type}:${uid}`, covered)
- .decrBy(`balance:${uid}`, amount + fee + ourfee)
+ .decrBy(`balance:${uid}`, amount + tip + fee + ourfee)
.exec();
});
});
- if (invoice?.tip) {
- tip = invoice.tip;
- amount -= tip;
- }
-
let p = {
id,
amount: -amount,
@@ -85,7 +81,7 @@ export let debit = async (
type,
ref,
tip,
- created: Date.now()
+ created: Date.now(),
};
await s(`payment:${id}`, p);
@@ -120,7 +116,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
ref,
type,
confirmed: true,
- created: Date.now()
+ created: Date.now(),
};
let { tip } = invoice;