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

Method createInvoice

src/services/payments-service.ts:50–105  ·  view source on GitHub ↗
(pubkey: Pubkey, amount: bigint, description: string)

Source from the content-addressed store, hash-verified

48 }
49
50 public async createInvoice(pubkey: Pubkey, amount: bigint, description: string): Promise<Invoice> {
51 logger('create invoice for %s for %s: %s', pubkey, amount.toString(), description)
52 const transaction = new Transaction(this.dbClient)
53
54 try {
55 await transaction.begin()
56
57 await this.userRepository.upsert({ pubkey }, transaction.transaction)
58
59 const invoiceResponse = await this.paymentsProcessor.createInvoice({
60 amount,
61 description,
62 requestId: pubkey,
63 })
64
65 const date = new Date()
66
67 await this.invoiceRepository.upsert(
68 {
69 id: invoiceResponse.id,
70 pubkey,
71 bolt11: invoiceResponse.bolt11,
72 amountRequested: invoiceResponse.amountRequested,
73 description: invoiceResponse.description,
74 unit: invoiceResponse.unit,
75 status: invoiceResponse.status,
76 expiresAt: invoiceResponse.expiresAt,
77 updatedAt: date,
78 createdAt: date,
79 verifyURL: invoiceResponse.verifyURL,
80 },
81 transaction.transaction,
82 )
83
84 await transaction.commit()
85
86 return {
87 id: invoiceResponse.id,
88 pubkey,
89 bolt11: invoiceResponse.bolt11,
90 amountRequested: invoiceResponse.amountRequested,
91 unit: invoiceResponse.unit,
92 status: invoiceResponse.status,
93 description,
94 expiresAt: invoiceResponse.expiresAt,
95 updatedAt: date,
96 createdAt: invoiceResponse.createdAt,
97 verifyURL: invoiceResponse.verifyURL,
98 }
99 } catch (error) {
100 await transaction.rollback()
101 logger.error('Unable to create invoice:', error)
102
103 throw error
104 }
105 }
106
107 public async updateInvoice(invoice: Partial<Invoice>): Promise<void> {

Callers

nothing calls this directly

Calls 6

beginMethod · 0.95
commitMethod · 0.95
rollbackMethod · 0.95
toStringMethod · 0.80
upsertMethod · 0.65
createInvoiceMethod · 0.65

Tested by

no test coverage detected