MCPcopy Create free account
hub / github.com/cameri/nostream / LnurlPaymentsProcessor

Class LnurlPaymentsProcessor

src/payments-processors/lnurl-payments-processor.ts:12–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10const logger = createLogger('lnurl-payments-processor')
11
12export class LnurlPaymentsProcessor implements IPaymentsProcessor {
13 public constructor(
14 private httpClient: AxiosInstance,
15 private settings: Factory<Settings>,
16 ) {}
17
18 public async getInvoice(invoice: LnurlInvoice): Promise<GetInvoiceResponse> {
19 logger('get invoice: %s', invoice.id)
20
21 try {
22 const response = await this.httpClient.get(invoice.verifyURL)
23
24 return {
25 id: invoice.id,
26 confirmedAt: response.data.settled ? new Date() : undefined,
27 status: response.data.settled ? InvoiceStatus.COMPLETED : InvoiceStatus.PENDING,
28 }
29 } catch (error) {
30 logger.error(`Unable to get invoice ${invoice.id}. Reason:`, error)
31
32 throw error
33 }
34 }
35
36 public async createInvoice(request: CreateInvoiceRequest): Promise<any> {
37 logger('create invoice: %o', request)
38 const { amount: amountMsats, description, requestId } = request
39
40 try {
41 const response = await this.httpClient.get(
42 `${this.settings().paymentsProcessors?.lnurl?.invoiceURL}/callback?amount=${amountMsats}&comment=${description}`,
43 )
44
45 const result = {
46 id: randomUUID(),
47 pubkey: requestId,
48 bolt11: response.data.pr,
49 amountRequested: amountMsats,
50 description,
51 unit: InvoiceUnit.MSATS,
52 status: InvoiceStatus.PENDING,
53 expiresAt: null,
54 confirmedAt: null,
55 createdAt: new Date(),
56 verifyURL: response.data.verify,
57 }
58
59 logger('result: %o', result)
60
61 return result
62 } catch (error) {
63 logger.error('Unable to request invoice. Reason:', error.message)
64
65 throw error
66 }
67 }
68}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected