aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-02-23 15:47:16 -0800
committerAdam Soltys <[email protected]>2023-02-23 15:47:16 -0800
commit797d10c9322b2de3ec14fa85689ae70435e98c8f (patch)
treebc8ade7f56b236b9690bc003d88de7e953928695 /lib
parente5b3b8454bd3c72ec1f6e2c214a2ccb717c54486 (diff)
downloadcoinos-server-797d10c9322b2de3ec14fa85689ae70435e98c8f.tar.gz
coinos-server-797d10c9322b2de3ec14fa85689ae70435e98c8f.zip
fix fee subtraction
Diffstat (limited to 'lib')
-rw-r--r--lib/payments.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/payments.js b/lib/payments.js
index 89652ff4..aaf39210 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -25,9 +25,11 @@ export let debit = async (
type = types.internal,
id = v4()
) => {
- let ref;
+ let ref, tip;
let invoice = await g(`invoice:${hash}`);
- if (invoice) ref = invoice.uid;
+ if (invoice) {
+ ref = invoice.uid;
+ }
let { id: uid, currency, username } = user;
@@ -44,16 +46,21 @@ export let debit = async (
let covered = Math.min(credit, ourfee) || 0;
ourfee -= covered;
- l("debiting", user.username, balance, amount, ourfee, amount + ourfee);
- if (balance < amount + ourfee) fail("Insufficient funds");
+ l("debiting", user.username, balance, amount, fee, ourfee, amount + fee + ourfee);
+ if (balance < amount + fee + ourfee) fail("Insufficient funds");
await db
.multi()
.decrBy(`credit:${type}:${uid}`, covered)
- .decrBy(`balance:${uid}`, amount + ourfee)
+ .decrBy(`balance:${uid}`, amount + fee + ourfee)
.exec();
});
});
+ if (invoice?.tip) {
+ tip = invoice.tip;
+ amount -= tip;
+ }
+
let p = {
id,
amount: -amount,
@@ -66,6 +73,7 @@ export let debit = async (
currency,
type,
ref,
+ tip,
created: Date.now()
};