diff options
Diffstat (limited to 'src/routes/invoice/+server.js')
| -rw-r--r-- | src/routes/invoice/+server.js | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/routes/invoice/+server.js b/src/routes/invoice/+server.js index 225f6bb1..d4c4c303 100644 --- a/src/routes/invoice/+server.js +++ b/src/routes/invoice/+server.js @@ -1,11 +1,17 @@ import { auth, get, post } from '$lib/utils'; -export async function POST({ request }) { - let network = 'lightning'; - let { amount, currency, rate, tip, text, username } = await request.json(); - ({ text } = await post('/lightning/invoice', { amount }, auth(request))); - let invoice = { amount, currency, network, rate, tip, text }; - let { uuid } = await post('/invoice', { invoice, user: { username } }, auth(request)); +export async function POST({ request, parent }) { + let { amount, currency, network = 'lightning', rate, tip, username } = await request.json(); + let invoice = { amount, currency, network, rate, tip }; - return new Response(JSON.stringify(uuid), { headers: { 'content-type': 'application/json' } }); + if (network === 'lightning') { + invoice.text = await post('/lightning/invoice', { amount }, auth(request)); + } else { + invoice.address = (await parent()).user.address; + } + + return new Response( + JSON.stringify(await post('/invoice', { invoice, user: { username } }, auth(request))), + { headers: { 'content-type': 'application/json' } } + ); } |
