aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.js2
-rw-r--r--lib/invoices.js6
-rw-r--r--lib/whitelist.js5
-rw-r--r--routes/shopify.js29
4 files changed, 38 insertions, 4 deletions
diff --git a/index.js b/index.js
index f525cd9f..7c3a134f 100644
--- a/index.js
+++ b/index.js
@@ -17,6 +17,7 @@ import invoices from "$routes/invoices";
import users from "$routes/users";
import payments from "$routes/payments";
import requests from "$routes/requests";
+import shopify from "$routes/shopify";
fillPool();
@@ -94,6 +95,7 @@ app.post("/requests", auth, requests.create);
app.post("/requests/delete", auth, requests.destroy);
app.post("/proxy", payments.proxy);
+app.post("/shopify/:id", auth, shopify);
let host = process.env.HOST || "0.0.0.0";
let port = process.env.PORT || 3119;
diff --git a/lib/invoices.js b/lib/invoices.js
index 2e5a8e64..62bbee1c 100644
--- a/lib/invoices.js
+++ b/lib/invoices.js
@@ -2,7 +2,7 @@ import store from "$lib/store";
import { l } from "$lib/logging";
import { emit } from "$lib/sockets";
import { db, g, s } from "$lib/db";
-import { getUser, bip21, fail } from "$lib/utils";
+import { getUser, bip21, fail, SATS } from "$lib/utils";
import { types } from "$lib/payments";
import { v4 } from "uuid";
@@ -13,6 +13,7 @@ export let generate = async ({ invoice, user, sender, memo }) => {
let {
currency,
expiry,
+ fiat,
tip,
amount,
rate,
@@ -26,14 +27,13 @@ export let generate = async ({ invoice, user, sender, memo }) => {
amount = parseInt(amount || 0);
tip = parseInt(tip) || null;
- if (amount < 0) fail("amount out of range");
-
if (user) user = await getUser(user.username);
else if (sender) user = await getUser(sender.username);
else fail("user not provided");
if (!currency) currency = user.currency;
if (!rate) rate = store.rates[currency];
+ if (fiat) amount = Math.round((SATS * fiat) / rate);
if (amount < 0) fail("invalid amount");
let hash, text;
diff --git a/lib/whitelist.js b/lib/whitelist.js
index ed9e8f95..379c3fdc 100644
--- a/lib/whitelist.js
+++ b/lib/whitelist.js
@@ -28,5 +28,8 @@ export default [
"theme",
"twofa",
"username",
- "verified"
+ "verified",
+ "shopifyStore",
+ "shopifyPubkey",
+ "shopifySecret"
];
diff --git a/routes/shopify.js b/routes/shopify.js
new file mode 100644
index 00000000..f15a3468
--- /dev/null
+++ b/routes/shopify.js
@@ -0,0 +1,29 @@
+import got from "got";
+
+let query = `mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
+ orderMarkAsPaid(input: $input) {
+ order { id }
+ userErrors {
+ field
+ message
+ }
+ }
+}`;
+
+export default async ({ body, params: { id }, user }, res) => {
+ let r = await got.post(
+ `https://${user.shopifyStore}.myshopify.com/admin/api/2023-07/graphql.json`,
+ {
+ headers: {
+ "Content-Type": "application/json",
+ "X-Shopify-Access-Token": user.shopifyToken
+ },
+ json: {
+ query,
+ variables: { input: { id: `gid://shopify/Order/${id}` } }
+ }
+ }
+ ).json();
+
+ res.send(r);
+};