aboutsummaryrefslogtreecommitdiffstats
path: root/lib/payments.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-12-03 17:23:46 +0000
committerAdam Soltys <[email protected]>2024-12-03 17:23:46 +0000
commita7a936f55ca7459002c7a8257dce071534dd207e (patch)
tree80a012befcf3fbe49ce6d26f8eebd5575ee84003 /lib/payments.ts
parent5a8c49ad031dcb175ff4a0dec71c818eeab0b491 (diff)
downloadcoinos-server-a7a936f55ca7459002c7a8257dce071534dd207e.tar.gz
coinos-server-a7a936f55ca7459002c7a8257dce071534dd207e.zip
delay before reversing
Diffstat (limited to 'lib/payments.ts')
-rw-r--r--lib/payments.ts16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index 76a7d1fa..d9808f3a 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -758,11 +758,15 @@ export const check = async () => {
const failed = !pays.length || pays.every((p) => p.status === "failed");
const completed = pays.find((p) => p.status === "complete");
- if (completed) await finalize(completed, p);
- else if (failed) await reverse(p);
+ try {
+ if (completed) await finalize(completed, p);
+ else if (failed) await reverse(p);
+ } catch(e) {
+ err("failed to finalize", p.id, e.message);
+ }
}
} catch (e) {
- console.log("payment check failed", e);
+ err("payment check failed", e.message);
}
setTimeout(check, 2000);
@@ -792,10 +796,14 @@ const finalize = async (r, p) => {
};
const reverse = async (p) => {
- const total = Math.abs(p.amount) + p.fee;
+ await sleep(Math.floor(Math.random() * (1500 - 500 + 1)) + 500);
+
+ const total = Math.abs(p.amount) + p.fee + p.ourfee;
const ourfee = p.ourfee || 0;
const credit = Math.round(total * config.fee) - ourfee;
+ l("reversing", p.id, p.amount, p.fee, total, ourfee, credit);
+
await db.reverse(
`payment:${p.id}`,
`balance:${p.uid}`,