generate invoice for order

This commit is contained in:
Daniel Lugo 2020-01-13 21:28:32 -04:00
parent 3e2cea2b86
commit 6dcc0d2d04

View file

@ -1,6 +1,9 @@
/** /**
* @format * @format
*/ */
const LightningServices = require('../../../../utils/lightningServices')
const ErrorCode = require('../errorCode') const ErrorCode = require('../errorCode')
const Key = require('../key') const Key = require('../key')
const Schema = require('../schema') const Schema = require('../schema')
@ -36,9 +39,32 @@ const listenerForAddr = (addr, user, SEA) => async (order, orderID) => {
const amount = Number(await SEA.decrypt(order.amount, secret)) const amount = Number(await SEA.decrypt(order.amount, secret))
const memo = await SEA.decrypt(order.memo, secret) const memo = await SEA.decrypt(order.memo, secret)
// create invoice here.. /**
* @type {[any , string]}
*/
const [err, invoice] = await new Promise(resolve => {
const {
services: { lightning }
} = LightningServices
const invoice = `INVOICE_${amount}_${memo}` lightning.addInvoice(
{
expiry: 36000,
memo,
value: amount
},
(
/** @type {any} */ error,
/** @type {{ payment_request: string }} */ response
) => {
resolve([error, response.payment_request])
}
)
})
if (err) {
console.log(new Error(err))
}
const encInvoice = await SEA.encrypt(invoice, secret) const encInvoice = await SEA.encrypt(invoice, secret)