send payment when order invoice is received
This commit is contained in:
parent
88abc9a2a9
commit
0734cb6cb9
1 changed files with 23 additions and 7 deletions
|
|
@ -2,6 +2,9 @@
|
||||||
* @format
|
* @format
|
||||||
*/
|
*/
|
||||||
const uuidv1 = require('uuid/v1')
|
const uuidv1 = require('uuid/v1')
|
||||||
|
|
||||||
|
const LightningServices = require('../../../utils/lightningServices')
|
||||||
|
|
||||||
const ErrorCode = require('./errorCode')
|
const ErrorCode = require('./errorCode')
|
||||||
const Getters = require('./getters')
|
const Getters = require('./getters')
|
||||||
const Key = require('./key')
|
const Key = require('./key')
|
||||||
|
|
@ -908,15 +911,28 @@ const sendPayment = async (to, amount, memo, gun, user, SEA) => {
|
||||||
})
|
})
|
||||||
])
|
])
|
||||||
|
|
||||||
if (Math.random() > 0.5) {
|
|
||||||
return Promise.resolve()
|
|
||||||
}
|
|
||||||
|
|
||||||
const decInvoice = await SEA.decrypt(invoice, ourSecret)
|
const decInvoice = await SEA.decrypt(invoice, ourSecret)
|
||||||
|
|
||||||
return Promise.reject(
|
const {
|
||||||
new Error('Lightning could not find a route to pay invoice: ' + decInvoice)
|
services: { lightning }
|
||||||
)
|
} = LightningServices
|
||||||
|
|
||||||
|
await new Promise((rej, resolve) => {
|
||||||
|
lightning.sendPaymentSync(
|
||||||
|
{
|
||||||
|
payment_request: decInvoice
|
||||||
|
},
|
||||||
|
(/** @type {any} */ err, /** @type {any} */ res) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err)
|
||||||
|
rej(err)
|
||||||
|
} else {
|
||||||
|
console.log(res)
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue