25 lines
834 B
TypeScript
25 lines
834 B
TypeScript
import type { Article } from '@/types/nostr'
|
|
import type { AlbyInvoice } from '@/types/alby'
|
|
|
|
/**
|
|
* Resolve invoice for article payment
|
|
* Uses invoice from event tags only
|
|
*/
|
|
export async function resolveArticleInvoice(article: Article): Promise<AlbyInvoice> {
|
|
if (!article.invoice || !article.paymentHash) {
|
|
throw new Error('Article does not have an invoice. The author must create an invoice when publishing the article.')
|
|
}
|
|
|
|
// Parse invoice from event tags
|
|
// Note: We don't have expiresAt from tags, so we'll assume it's valid
|
|
// In production, you'd decode BOLT11 to get expiry
|
|
const invoice: AlbyInvoice = {
|
|
invoice: article.invoice,
|
|
paymentHash: article.paymentHash,
|
|
amount: article.zapAmount,
|
|
expiresAt: Math.floor(Date.now() / 1000) + 86400, // Assume 24h validity
|
|
}
|
|
|
|
return invoice
|
|
}
|