aboutsummaryrefslogtreecommitdiffstats
path: root/routes/shopify.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-08-26 21:17:43 -0700
committerAdam Soltys <[email protected]>2024-08-26 21:17:43 -0700
commitfe62cadd6fb4a7e49f7d59401fc74ae0411e32a7 (patch)
treeaa8f34e1692bd2d638a2c996eeadb58671d07aea /routes/shopify.ts
parent00e43ddc0bf3d6dd719fc9295d156567fa2fecfb (diff)
downloadcoinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.tar.gz
coinos-server-fe62cadd6fb4a7e49f7d59401fc74ae0411e32a7.zip
typescript
Diffstat (limited to 'routes/shopify.ts')
-rw-r--r--routes/shopify.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/routes/shopify.ts b/routes/shopify.ts
new file mode 100644
index 00000000..bcb60ea3
--- /dev/null
+++ b/routes/shopify.ts
@@ -0,0 +1,41 @@
+import got from "got";
+import { g } from "$lib/db";
+import { err } from "$lib/logging";
+
+let query = `mutation orderMarkAsPaid($input: OrderMarkAsPaidInput!) {
+ orderMarkAsPaid(input: $input) {
+ order { id }
+ userErrors {
+ field
+ message
+ }
+ }
+}`;
+
+export default async ({ body: { hash }, params: { id } }, res) => {
+ let p = await g(`payment:${hash}`);
+ if (typeof p === "string") p = await g(`payment:${p}`);
+ let user = await g(`user:${p.uid}`);
+
+ try {
+ 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);
+ } catch (e) {
+ err("problem marking shopify order as paid", e.message);
+ }
+};