aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/payments.ts')
-rw-r--r--lib/payments.ts13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index c715af47..baaa6aa7 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -288,6 +288,19 @@ export const credit = async ({
return;
}
+ // usePreimage invoices keep their merchant-supplied preimage at
+ // 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.
+ if (
+ inv.paymentHash &&
+ ![PaymentType.bitcoin, PaymentType.liquid].includes(type)
+ ) {
+ const stored = await db.get(`preimage:${inv.paymentHash}`);
+ if (stored) ref = stored;
+ }
+
let { path, tip } = inv;
tip = Number.parseInt(tip) || 0;