diff options
| author | Adam Soltys <[email protected]> | 2023-02-23 15:47:16 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-02-23 15:47:16 -0800 |
| commit | 797d10c9322b2de3ec14fa85689ae70435e98c8f (patch) | |
| tree | bc8ade7f56b236b9690bc003d88de7e953928695 /lib | |
| parent | e5b3b8454bd3c72ec1f6e2c214a2ccb717c54486 (diff) | |
| download | coinos-server-797d10c9322b2de3ec14fa85689ae70435e98c8f.tar.gz coinos-server-797d10c9322b2de3ec14fa85689ae70435e98c8f.zip | |
fix fee subtraction
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/payments.js | 18 |
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() }; |
