aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-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);