Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
testEnvVars()
let { OPEN_NODE_KEY, LND_TLS_CERT, LND_MACAROON, LND_SOCKET } = getEnvVars()
// if the tests pass above and we don't have a
// OPEN_NODE_KEY then we need to setup the lnd service
if (!OPEN_NODE_KEY) {
const { lnd } = lnService.authenticatedLndGrpc({
cert: LND_TLS_CERT,
macaroon: LND_MACAROON,
socket: LND_SOCKET,
})
req.lnd = lnd
} else {
const env = process.env.ENVIRONMENT || 'dev'
const opennode = require('opennode')
opennode.setCredentials(OPEN_NODE_KEY, env)
req.opennode = opennode
}
next()
} catch (e) {
console.error(
'Problem with configs for connecting to lightning node:',
e.message
)
next("Could not connect to the paywall's lightning node.")
}
}
/**
* Setup your API Key and environment
*/
opennode.setCredentials('MY_API_KEY', 'dev');
/**
*
* Fetch charge information
*/
/**
* Using promises
*/
opennode.chargeInfo('47bb5224-bf50-49d0-a317-4adfd345221a')
.then(charge => {
console.log(charge);
})
.catch(error => {
console.error(`${error.status} | ${error.message}`);
})
/**
*
* Using async/await
*/
;(async () => {
try {
const data = await opennode.chargeInfo('47bb5224-bf50-49d0-a317-4adfd345221a');
;(async () => {
try {
const data = await opennode.chargeInfo('47bb5224-bf50-49d0-a317-4adfd345221a');
console.log(data);
}
catch (error) {
console.error(`${error.status} | ${error.message}`);
}
})()
;(async () => {
try {
const response = await opennode.createCharge(charge);
console.log(response);
}
catch(error) {
console.error(`${error.status} | ${error.message}`);
}
})();
/**
* Using promises
*/
const charge = {
amount: 10.5,
currency: "USD",
callback_url: "https://example.com/webhook/opennode",
auto_settle: false
};
/**
* Using promises
*/
opennode.createCharge(charge)
.then(response => {
console.log(response);
})
.catch(error => {
console.error(`${error.status} | ${error.message}`);
});
/**
* Using async/await
*/
;(async () => {
try {
const response = await opennode.createCharge(charge);
console.log(response);
}
const opennode = require('opennode');
/**
* Setup your API Key and environment
*/
opennode.setCredentials('MY_API_KEY', 'dev');
/**
*
* Fetch charge information
*/
/**
* Using promises
*/
opennode.chargeInfo('47bb5224-bf50-49d0-a317-4adfd345221a')
.then(charge => {
console.log(charge);
})
.catch(error => {