aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-09-21 21:41:13 +0000
committerAdam Soltys <[email protected]>2023-09-21 21:41:32 +0000
commit58e3d5233d345e03f37dcfc745d1ff09e591de6c (patch)
tree24adbdedc8f0e8ee3e1801b7699a4aa976399341
parentccbf0cbaaf414d638fd9034b0c5eb5037beaac30 (diff)
downloadcoinos-server-58e3d5233d345e03f37dcfc745d1ff09e591de6c.tar.gz
coinos-server-58e3d5233d345e03f37dcfc745d1ff09e591de6c.zip
new rate api
-rw-r--r--index.js2
-rw-r--r--lib/payments.js10
-rw-r--r--lib/rates.js5
-rw-r--r--routes/shopify.js6
4 files changed, 14 insertions, 9 deletions
diff --git a/index.js b/index.js
index ca63ee6c..67164b6d 100644
--- a/index.js
+++ b/index.js
@@ -95,7 +95,7 @@ app.post("/requests", auth, requests.create);
app.post("/requests/delete", auth, requests.destroy);
app.post("/proxy", payments.proxy);
-app.post("/shopify//:id", shopify);
+app.post("/shopify/:id", shopify);
let host = process.env.HOST || "0.0.0.0";
let port = process.env.PORT || 3119;
diff --git a/lib/payments.js b/lib/payments.js
index b855e549..b17dfde6 100644
--- a/lib/payments.js
+++ b/lib/payments.js
@@ -181,12 +181,16 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
callWebhook(invoice, p);
if (user.hasprinter) {
- let fiat = parseFloat(((amount * p.rate) / 100000000).toFixed(2));
- let words = dollarsToWords(fiat);
let client = mqtt.connect("mqtt://ln.coinos.io", config.mqtt);
client.subscribe(username);
+ let connected;
+
+ if (user.hasspeaker) {
+ let fiat = parseFloat(((amount * p.rate) / 100000000).toFixed(2));
+ let words = dollarsToWords(fiat);
+
if (fiat === 0.02) {
words = "there is no second best";
client.publish(username, "easter");
@@ -205,7 +209,6 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
let raw = `/app/data/uploads/${p.id}-raw.mp3`;
let out = `/app/data/uploads/${p.id}.mp3`;
- let connected;
let mimic = spawn("/mimic", [
"-t",
words,
@@ -275,6 +278,7 @@ export let credit = async (hash, amount, memo, ref, type = types.internal) => {
client.publish(username, `end:${chunks.length}`);
});
});
+ }
client.on("connect", function() {
client.publish(
diff --git a/lib/rates.js b/lib/rates.js
index 16ce37d5..bbb5418f 100644
--- a/lib/rates.js
+++ b/lib/rates.js
@@ -50,9 +50,10 @@ export let getRates = async () => {
if (Date.now() - date > 24 * 60 * 60 * 1000) {
date = Date.now();
try {
- let { rates: fx } = await got(
- `https://api.exchangerate.host/latest?base=USD&v={(new Date()).toISOString().split('T')[0]}`
+ let r = await got(
+ `https://v6.exchangerate-api.com/v6/${config.exchange}/latest/USD`
).json();
+ let { conversion_rates: fx } = r;
await s("rates", { date, fx });
} catch (e) {
err("error fetching rates", e.message);
diff --git a/routes/shopify.js b/routes/shopify.js
index 9cbbb02b..0eb4dd27 100644
--- a/routes/shopify.js
+++ b/routes/shopify.js
@@ -11,9 +11,9 @@ let query = `mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
}
}`;
-export default async ({ body, params: { id, username } }, res) => {
- let { uid } = body;
- let user = await g(`user:${uid}`);
+export default async ({ body: { hash }, params: { id } }, res) => {
+ let p = await g(`payment:${hash}`);
+ let user = await g(`user:${p.uid}`);
let r = await got
.post(