diff --git a/pages/api/lnurlp/[username]/pay.js b/pages/api/lnurlp/[username]/pay.js index c4b3c411..30896194 100644 --- a/pages/api/lnurlp/[username]/pay.js +++ b/pages/api/lnurlp/[username]/pay.js @@ -90,7 +90,8 @@ export default async ({ query: { username, amount, nostr, comment, payerdata: pa return res.status(200).json({ pr: invoice.request, - routes: [] + routes: [], + verify: `${process.env.NEXT_PUBLIC_URL}/api/lnurlp/${username}/verify/${invoice.id}` }) } catch (error) { console.log(error) diff --git a/pages/api/lnurlp/[username]/verify/[hash].js b/pages/api/lnurlp/[username]/verify/[hash].js new file mode 100644 index 00000000..a8887b41 --- /dev/null +++ b/pages/api/lnurlp/[username]/verify/[hash].js @@ -0,0 +1,15 @@ +import lnd from '@/api/lnd' +import { getInvoice } from 'ln-service' + +export default async ({ query: { hash } }, res) => { + try { + const inv = await getInvoice({ id: hash, lnd }) + const settled = inv.is_confirmed + return res.status(200).json({ status: 'OK', settled, preimage: settled ? inv.secret : null, pr: inv.request }) + } catch (err) { + if (err[1] === 'UnexpectedLookupInvoiceErr') { + return res.status(404).json({ status: 'ERROR', reason: 'not found' }) + } + return res.status(500).json({ status: 'ERROR', reason: 'internal server error' }) + } +}