diff options
| -rw-r--r-- | lib/payments.js | 33 | ||||
| -rw-r--r-- | lib/utils.js | 1 | ||||
| -rw-r--r-- | templates/payments/received.html | 16 |
3 files changed, 43 insertions, 7 deletions
diff --git a/lib/payments.js b/lib/payments.js index f1b2ff46..d9ee58b6 100644 --- a/lib/payments.js +++ b/lib/payments.js @@ -10,6 +10,7 @@ import { f, btc, fail, + fiat, getInvoice, sleep, wait, @@ -132,7 +133,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { tip = parseInt(tip) || 0; if (!memo) ({ memo } = inv); - if (memo && memo.length > 200) fail("memo too long"); + if (memo && memo.length > 200) fail("memo too long"); if (amount < 0 || tip < 0) fail("Invalid amount"); if (type === types.internal) amount += tip; @@ -210,7 +211,10 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { // console.log(items); let items; - if (inv.items && inv.items.length) formatReceipt(inv.items, inv.currency); + if (inv.items && inv.items.length) { + formatReceipt(inv.items, inv.currency); + p.items = inv.items; + } if (config.mqtt1) { mqtt1.publish( @@ -226,7 +230,12 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => { ); } - await completePayment(p, user); + try { + await completePayment(p, user); + } catch (e) { + console.log(e); + } + return p; }; @@ -263,7 +272,23 @@ export let completePayment = async (p, user) => { mail(user, t.paymentReceived, templates.paymentReceived, { ...t, username, - payment: { amount: fmt(p.amount), link: link(p.id) }, + payment: { + amount: fmt(p.amount), + link: link(p.id), + tip: p.tip ? fmt(p.tip) : undefined, + fiat: f(fiat(p.amount, p.rate), p.currency), + fiatTip: p.tip ? f(fiat(p.tip, p.rate), p.currency) : undefined, + items: + p.items && + p.items.map((i) => { + return { + quantity: i.quantity, + name: i.name, + total: i.quantity * i.price, + totalFiat: f(i.quantity * i.price, p.currency), + }; + }), + }, withdrawal, }); } diff --git a/lib/utils.js b/lib/utils.js index b5492f72..89217dfa 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -24,6 +24,7 @@ export let bail = (res, msg) => res.code(500).send(msg); export let SATS = 100000000; export let sats = (n) => Math.round(n * SATS); export let btc = (n) => parseFloat((n / SATS).toFixed(8)); +export let fiat = (n, r) => (n * r) / SATS; export let uniq = (a, k) => [...new Map(a.map((x) => [k(x), x])).values()]; export let pick = (O, K) => diff --git a/templates/payments/received.html b/templates/payments/received.html index dc98006d..61888742 100644 --- a/templates/payments/received.html +++ b/templates/payments/received.html @@ -8,10 +8,20 @@ <html> <body> - <div style="margin-bottom: 10px">{{hello}} {{username}},</div> + {{#if payment.items}} + <div style="margin-bottom: 10px"> + {{#each payment.items}} + <div>{{this.quantity}} {{this.name}} {{this.totalFiat}}</div> + {{/each}} + </div> + {{/if}} + + <div style="margin-bottom: 10px"> + {{payment.fiat}} {{#if payment.tip}} + {{payment.fiatTip}}{{/if}} + </div> <div style="margin-bottom: 10px"> - {{youReceived}} {{payment.amount}} + {{payment.amount}} + {{payment.tip}} </div> <div style="margin-bottom: 10px"> @@ -33,7 +43,7 @@ {{/if}} <a href="{{payment.link}}"> - <img src="https://coinos.io/images/logo.webp" style="width: 200px; margin: 50px;"/> + <img src="https://coinos.io/images/logo.webp" style="width: 200px; margin-top: 20px;"/> </a> </body> </html> |
