diff options
Diffstat (limited to 'lib/payments.js')
| -rw-r--r-- | lib/payments.js | 12 |
1 files changed, 8 insertions, 4 deletions
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); |
