aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-02-24 21:39:44 -0800
committerAdam Soltys <[email protected]>2024-02-24 21:39:44 -0800
commitfee415dd6c5ee83159990a5e7d59184b0ab1ec96 (patch)
treed6a0fb1d8348c163d15d062f2b3136147dd5b277 /lib
parentf0e144cfe7b4a7a49e9533ffaa6c61000a19bd32 (diff)
downloadcoinos-server-fee415dd6c5ee83159990a5e7d59184b0ab1ec96.tar.gz
coinos-server-fee415dd6c5ee83159990a5e7d59184b0ab1ec96.zip
itemized email
Diffstat (limited to 'lib')
-rw-r--r--lib/payments.js33
-rw-r--r--lib/utils.js1
2 files changed, 30 insertions, 4 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) =>