Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display node URI on checkout page #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const apiToken = process.env.API_TOKEN || (console.error('Please configure your
app.get('/info', auth, wrap(async (req, res) => res.send(await ln.getinfo())))

require('./invoicing')(app, payListen, model, auth)
require('./checkout')(app, payListen)
require('./checkout')(app, payListen, ln)

require('./sse')(app, payListen, auth)
require('./webhook')(app, payListen, model, auth)
Expand Down
5 changes: 3 additions & 2 deletions src/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import wrap from './lib/promise-wrap'

const rpath = name => path.join(__dirname, name)

module.exports = (app, payListen) => {
module.exports = (app, payListen, ln) => {
app.set('url', process.env.URL || '/')
app.set('static_url', process.env.STATIC_URL || app.settings.url + 'static/')
app.set('view engine', 'pug')
Expand All @@ -29,8 +29,9 @@ module.exports = (app, payListen) => {

if (req.invoice.status == 'unpaid')
res.locals.qr = await qrcode.toDataURL(`lightning:${req.invoice.payreq}`.toUpperCase(), { margin: 1 })
const node_info = await ln.getinfo()

res.render('checkout', req.invoice)
res.render('checkout', {invoice: req.invoice, node: node_info })
}))

// like /invoice/:invoice/wait, but user-accessible, doesn't reveal the full invoice fields,
Expand Down
38 changes: 22 additions & 16 deletions views/checkout.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ meta(charset='utf-8')
base(href=settings.url)
meta(name='viewport', content='width=device-width, initial-scale=1')

meta(name='invoice-id', content=id)
meta(name='invoice-id', content=invoice.id)

if status == 'unpaid'
meta(name='invoice-poll-url', content=settings.url+'checkout/'+id+'/wait')
meta(name='invoice-expiry', content=expires_at)
if invoice.status == 'unpaid'
meta(name='invoice-poll-url', content=settings.url+'checkout/'+invoice.id+'/wait')
meta(name='invoice-expiry', content=invoice.expires_at)

mixin css(path)
link(rel='stylesheet', href=settings.static_url+path)

+css('bootstrap.min.css')
+css('checkout.css')

- opt = metadata && metadata.checkout || {}
- opt = invoice.metadata && invoice.metadata.checkout || {}

body: .checkout.container
script window.parent != window && (document.body.className += ' iframed')
Expand All @@ -28,33 +28,39 @@ body: .checkout.container
h4= opt.desc || 'Pay with Lightning'
if msatoshi
.amounts.col-sm-6
if quoted_currency
h3 #{ quoted_amount } #{ quoted_currency }
h4 #{ formatMsat(msatoshi) }
if invoice.quoted_currency
h3 #{ invoice.quoted_amount } #{ invoice.quoted_currency }
h4 #{ formatMsat(invoice.msatoshi) }
else
h3 #{ formatMsat(msatoshi) }
h3 #{ formatMsat(invoice.msatoshi) }

if status == 'paid'
if invoice.status == 'paid'
p.thankyou= opt.thank_you || 'Thank you! Your payment has been received.'
script window.parent != window && window.parent.postMessage({ type: 'completed', invoice: '#{ id }' }, '*')
script window.parent != window && window.parent.postMessage({ type: 'completed', invoice: '#{ invoice.id }' }, '*')

else if status == 'expired'
else if invoice.status == 'expired'
p.expired= opt.expired || 'Your invoice has expired. Please try again.'

else if status == 'unpaid'
else if invoice.status == 'unpaid'
.row
.qr.col-sm-4: img(src=qr)
.pay.col-sm-8
pre= payreq
a.btn.btn-lg.btn-primary(href=`lightning:${payreq}`)= opt.button || 'Pay with wallet'
pre= invoice.payreq
a.btn.btn-lg.btn-primary(href=`lightning:${invoice.payreq}`)= opt.button || 'Pay with wallet'

p.expiry.text-muted Invoice expires in #[span]

if node.address.length
.row
.qr.col-sm-12
h4 Our node
pre= node.id + "@" + node.address[0].address + ":" + node.address[0].port

script(src=settings.static_url+'checkout.js')

script.
if (window.parent != window) {
function updateHeight() { window.parent.postMessage({ type: 'height', value: document.body.scrollHeight, invoice: '#{ id }' }, '*') }
function updateHeight() { window.parent.postMessage({ type: 'height', value: document.body.scrollHeight, invoice: '#{ invoice.id }' }, '*') }
updateHeight()
window.addEventListener('resize', updateHeight)
}