2019-01-01 11:26:51 -05:00
|
|
|
var request = require('request-promise');
|
2018-10-09 20:08:05 -04:00
|
|
|
var common = require('../common');
|
2019-01-13 17:55:25 -05:00
|
|
|
var logger = require('./logger');
|
2019-03-02 12:55:19 -05:00
|
|
|
var options = {};
|
2018-10-09 20:08:05 -04:00
|
|
|
|
|
|
|
exports.decodePayment = (req, res, next) => {
|
2019-04-06 20:20:40 -04:00
|
|
|
options = common.getOptions();
|
|
|
|
options.url = common.getSelLNDServerUrl() + '/payreq/' + req.params.payRequest;
|
2019-01-01 11:26:51 -05:00
|
|
|
request(options).then((body) => {
|
2018-10-09 20:08:05 -04:00
|
|
|
const body_str = (undefined === body) ? '' : JSON.stringify(body);
|
|
|
|
const search_idx = (undefined === body) ? -1 : body_str.search('Not Found');
|
2019-01-13 17:55:25 -05:00
|
|
|
logger.info('\r\nPayReq: 10: ' + JSON.stringify(Date.now()) + ': INFO: Payment Decodd Received: ' + body_str);
|
2018-10-09 20:08:05 -04:00
|
|
|
if(undefined === body || search_idx > -1 || body.error) {
|
|
|
|
res.status(500).json({
|
|
|
|
message: "Payment Request Decode Failed!",
|
2018-10-11 20:03:54 -04:00
|
|
|
error: (undefined === body || search_idx > -1) ? 'Error From Server!' : body.error
|
2018-10-09 20:08:05 -04:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
body.btc_num_satoshis = (undefined === body.num_satoshis) ? 0 : common.convertToBTC(body.num_satoshis);
|
|
|
|
body.timestamp_str = (undefined === body.timestamp) ? '' : common.convertTimestampToDate(body.timestamp);
|
|
|
|
res.status(200).json(body);
|
|
|
|
}
|
2019-01-01 11:26:51 -05:00
|
|
|
})
|
|
|
|
.catch(function (err) {
|
|
|
|
return res.status(500).json({
|
|
|
|
message: "Payment Request Decode Failed!",
|
|
|
|
error: err.error
|
|
|
|
});
|
2018-10-09 20:08:05 -04:00
|
|
|
});
|
|
|
|
};
|