aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/payments.ts')
-rw-r--r--lib/payments.ts7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 01de2eff..df2c8857 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -293,10 +293,13 @@ export const credit = async ({
// preimage:${paymentHash} (see generate()). Prefer it as the settlement
// ref: external settlements already carry the same value, but internal
// ones pass ref=sender.id, which would otherwise be surfaced as the
- // payment preimage and lose the secret the buyer paid for.
+ // payment preimage and lose the secret the buyer paid for. Only once the
+ // invoice is fully paid, though — internal sends can settle partial
+ // amounts, and an underpayment must not reveal the secret.
if (
inv.paymentHash &&
- ![PaymentType.bitcoin, PaymentType.liquid].includes(type)
+ ![PaymentType.bitcoin, PaymentType.liquid].includes(type) &&
+ inv.received + amount >= inv.amount
) {
const stored = await db.get(`preimage:${inv.paymentHash}`);
if (stored) ref = stored;