From 0734cb6cb924748cdde834aa955b400217277f7d Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Mon, 13 Jan 2020 21:28:50 -0400 Subject: [PATCH] send payment when order invoice is received --- services/gunDB/contact-api/actions.js | 30 ++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index eb052000..b9f4da32 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -2,6 +2,9 @@ * @format */ const uuidv1 = require('uuid/v1') + +const LightningServices = require('../../../utils/lightningServices') + const ErrorCode = require('./errorCode') const Getters = require('./getters') 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) - return Promise.reject( - new Error('Lightning could not find a route to pay invoice: ' + decInvoice) - ) + const { + 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() + } + } + ) + }) } /**