diff options
| author | Adam Soltys <[email protected]> | 2023-09-20 15:35:12 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2023-09-20 15:38:06 -0700 |
| commit | 27fa1e5479f285da62b761e36b7e7fb2b1319158 (patch) | |
| tree | 6e786344c793695b1fdddefd9650f9e16b5ecca2 | |
| parent | fb45ea1f665c5fc750e1bd09e3cc23be9c695133 (diff) | |
| download | coinos-server-27fa1e5479f285da62b761e36b7e7fb2b1319158.tar.gz coinos-server-27fa1e5479f285da62b761e36b7e7fb2b1319158.zip | |
shopify attributes
| -rw-r--r-- | index.js | 2 | ||||
| -rw-r--r-- | lib/invoices.js | 6 | ||||
| -rw-r--r-- | lib/whitelist.js | 5 | ||||
| -rw-r--r-- | routes/shopify.js | 29 |
4 files changed, 38 insertions, 4 deletions
@@ -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); +}; |
