aboutsummaryrefslogtreecommitdiffstats
path: root/routes
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-01 15:50:46 -0700
committerAdam Soltys <[email protected]>2024-10-01 15:50:46 -0700
commit80470a2c66c17e4992f176438025b2b021581d11 (patch)
tree0f541e280fcaa86f52bc6578af4ce62901ba2518 /routes
parent426127506daa5f5e4c7ec851361bb54d4f769400 (diff)
downloadcoinos-server-80470a2c66c17e4992f176438025b2b021581d11.tar.gz
coinos-server-80470a2c66c17e4992f176438025b2b021581d11.zip
getpayment helper
Diffstat (limited to 'routes')
-rw-r--r--routes/payments.ts22
-rw-r--r--routes/shopify.ts4
2 files changed, 15 insertions, 11 deletions
diff --git a/routes/payments.ts b/routes/payments.ts
index 5d190c7e..6ee5a23a 100644
--- a/routes/payments.ts
+++ b/routes/payments.ts
@@ -3,7 +3,15 @@ import { emit } from "$lib/sockets";
import { v4 } from "uuid";
import { db, g, s, t } from "$lib/db";
import { l, err, warn } from "$lib/logging";
-import { bail, fail, getInvoice, getUser, sats, SATS } from "$lib/utils";
+import {
+ bail,
+ fail,
+ getInvoice,
+ getPayment,
+ getUser,
+ sats,
+ SATS,
+} from "$lib/utils";
import { requirePin } from "$lib/auth";
import {
completePayment,
@@ -138,8 +146,7 @@ export default {
let {
params: { hash },
} = req;
- let p = await g(`payment:${hash}`);
- if (typeof p === "string") p = await g(`payment:${p}`);
+ let p = await getPayment(hash);
if (p.type === types.internal) p.with = await g(`user:${p.ref}`);
res.send(p);
},
@@ -271,8 +278,7 @@ export default {
if (type === types.liquid && asset !== config.liquid.btc) continue;
if (category === "send") {
- let p = await g(`payment:${txid}`);
- if (typeof p === "string") p = await g(`payment:${p}`);
+ let p = await getPayment(txid);
if (!p) continue;
if (confirmations) {
@@ -287,8 +293,7 @@ export default {
continue;
}
- let p = await g(`payment:${txid}:${vout}`);
- if (typeof p === "string") p = await g(`payment:${p}`);
+ let p = await getPayment(`${txid}:${vout}`);
if (!p) {
let invoice = await getInvoice(address);
@@ -302,8 +307,7 @@ export default {
});
} else if (confirmations >= 1) {
let id = `payment:${txid}:${vout}`;
- let p = await g(id);
- if (typeof p === "string") p = await g(`payment:${p}`);
+ let p = await getPayment(`${txid}:${vout}`);
if (!p) return db.sAdd("missed", id);
if (p.confirmed) return;
diff --git a/routes/shopify.ts b/routes/shopify.ts
index b28f556f..f5c26208 100644
--- a/routes/shopify.ts
+++ b/routes/shopify.ts
@@ -1,6 +1,7 @@
import got from "got";
import { g } from "$lib/db";
import { err } from "$lib/logging";
+import { getPayment } from "$lib/utils";
let query = `mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
orderMarkAsPaid(input: $input) {
@@ -17,8 +18,7 @@ export default async (req, res) => {
body: { hash },
params: { id },
} = req;
- let p = await g(`payment:${hash}`);
- if (typeof p === "string") p = await g(`payment:${p}`);
+ let p = await getPayment(hash);
let user = await g(`user:${p.uid}`);
try {