-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add new lnurl processor * fix: lnbits issues * fix: add default settings for lnurl processor * fix: small changes * fix: more changes * fix: add verify url in upsert omit * fix: change comment * chore: add updateInvoiceStatus * chore: revert lnbits change * fix: changes
- Loading branch information
1 parent
d803428
commit f237400
Showing
18 changed files
with
159 additions
and
36 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
migrations/20230213103904_add_verify_url_to_invoices_table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
exports.up = function (knex) { | ||
return knex.raw('ALTER TABLE invoices ADD verify_url TEXT;') | ||
} | ||
|
||
exports.down = function (knex) { | ||
return knex.schema.alterTable('invoices', function (table) { | ||
table.dropColumn('verify_url') | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { AxiosInstance } from 'axios' | ||
import { Factory } from '../@types/base' | ||
|
||
import { CreateInvoiceRequest, GetInvoiceResponse, IPaymentsProcessor } from '../@types/clients' | ||
import { Invoice, InvoiceStatus, InvoiceUnit } from '../@types/invoice' | ||
import { createLogger } from '../factories/logger-factory' | ||
import { randomUUID } from 'crypto' | ||
import { Settings } from '../@types/settings' | ||
|
||
const debug = createLogger('lnurl-payments-processor') | ||
|
||
export class LnurlPaymentsProcesor implements IPaymentsProcessor { | ||
public constructor( | ||
private httpClient: AxiosInstance, | ||
private settings: Factory<Settings> | ||
) {} | ||
|
||
public async getInvoice(invoice: Invoice): Promise<GetInvoiceResponse> { | ||
debug('get invoice: %s', invoice.id) | ||
|
||
try { | ||
const response = await this.httpClient.get(invoice.verifyURL) | ||
|
||
return { | ||
id: invoice.id, | ||
status: response.data.settled ? InvoiceStatus['COMPLETED'] : InvoiceStatus['PENDING'], | ||
} | ||
} catch (error) { | ||
console.error(`Unable to get invoice ${invoice.id}. Reason:`, error) | ||
|
||
throw error | ||
} | ||
} | ||
|
||
public async createInvoice(request: CreateInvoiceRequest): Promise<any> { | ||
debug('create invoice: %o', request) | ||
const { | ||
amount: amountMsats, | ||
description, | ||
requestId, | ||
} = request | ||
|
||
try { | ||
const response = await this.httpClient.get(`${this.settings().paymentsProcessors?.lnurl?.invoiceURL}/callback?amount=${amountMsats}&comment=${description}`) | ||
|
||
const result = { | ||
id: randomUUID(), | ||
pubkey: requestId, | ||
bolt11: response.data.pr, | ||
amountRequested: amountMsats, | ||
description, | ||
unit: InvoiceUnit.MSATS, | ||
status: InvoiceStatus.PENDING, | ||
expiresAt: null, | ||
confirmedAt: null, | ||
createdAt: new Date(), | ||
verifyURL: response.data.verify, | ||
} | ||
|
||
debug('result: %o', result) | ||
|
||
return result | ||
} catch (error) { | ||
console.error('Unable to request invoice. Reason:', error.message) | ||
|
||
throw error | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.