2026-03-18 15:09:48 +00:00
|
|
|
import { randomBytes } from "crypto";
|
2026-03-18 14:59:02 +00:00
|
|
|
|
|
|
|
|
export interface LNbitsInvoice {
|
|
|
|
|
paymentHash: string;
|
|
|
|
|
paymentRequest: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface LNbitsInvoiceStatus {
|
|
|
|
|
paid: boolean;
|
|
|
|
|
paidAt?: Date;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-18 15:09:48 +00:00
|
|
|
const paidInvoices = new Set<string>();
|
|
|
|
|
|
2026-03-18 14:59:02 +00:00
|
|
|
export async function createInvoice(
|
|
|
|
|
amountSats: number,
|
|
|
|
|
memo: string,
|
|
|
|
|
): Promise<LNbitsInvoice> {
|
2026-03-18 15:09:48 +00:00
|
|
|
const paymentHash = randomBytes(32).toString("hex");
|
|
|
|
|
const paymentRequest = `lnbcrt${amountSats}u1stub_${paymentHash.slice(0, 16)}`;
|
|
|
|
|
console.log(`[stub] Created invoice: ${amountSats} sats — "${memo}" — hash=${paymentHash}`);
|
|
|
|
|
return { paymentHash, paymentRequest };
|
2026-03-18 14:59:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function checkInvoicePaid(
|
|
|
|
|
paymentHash: string,
|
|
|
|
|
): Promise<LNbitsInvoiceStatus> {
|
2026-03-18 15:09:48 +00:00
|
|
|
if (paidInvoices.has(paymentHash)) {
|
|
|
|
|
return { paid: true, paidAt: new Date() };
|
2026-03-18 14:59:02 +00:00
|
|
|
}
|
2026-03-18 15:09:48 +00:00
|
|
|
return { paid: false };
|
|
|
|
|
}
|
2026-03-18 14:59:02 +00:00
|
|
|
|
2026-03-18 15:09:48 +00:00
|
|
|
export function markInvoicePaid(paymentHash: string): void {
|
|
|
|
|
paidInvoices.add(paymentHash);
|
|
|
|
|
console.log(`[stub] Marked invoice paid: hash=${paymentHash}`);
|
2026-03-18 14:59:02 +00:00
|
|
|
}
|