aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2025-09-08 09:26:47 -0700
committerAdam Soltys <[email protected]>2025-09-08 09:26:47 -0700
commitb2f88134a3828d2df7271c7d0ae4219e5e6f7d56 (patch)
tree90aae1ccbb81a8dacc92a58c220a21310f9f0bed
parent66ea0286057f43c699f4701cb4e444ff2308a414 (diff)
downloadcoinos-server-b2f88134a3828d2df7271c7d0ae4219e5e6f7d56.tar.gz
coinos-server-b2f88134a3828d2df7271c7d0ae4219e5e6f7d56.zip
square payments
-rw-r--r--lib/payments.ts2
-rw-r--r--lib/square.ts30
2 files changed, 16 insertions, 16 deletions
diff --git a/lib/payments.ts b/lib/payments.ts
index bd045f98..be801622 100644
--- a/lib/payments.ts
+++ b/lib/payments.ts
@@ -322,7 +322,7 @@ export const completePayment = async (inv, p, user) => {
nwcNotify(p);
notify(p, user, withdrawal);
- if (user.square) squarePayment(user);
+ squarePayment(p, user);
l(username, "received", p.type, p.amount);
callWebhook(inv, p);
diff --git a/lib/square.ts b/lib/square.ts
index 3fbc8774..f491effe 100644
--- a/lib/square.ts
+++ b/lib/square.ts
@@ -1,12 +1,14 @@
-import { g, s } from "$lib/db";
import config from "$config";
+import { g, s } from "$lib/db";
+import { fiat } from "$lib/utils";
import { SquareClient } from "square";
import { v4 } from "uuid";
const { appId, environment } = config.square;
-export const squarePayment = async (user) => {
+export const squarePayment = async (p, user) => {
let square = await g(`${user.id}:square`);
+ if (!square) return;
let client = new SquareClient({
environment,
@@ -29,27 +31,25 @@ export const squarePayment = async (user) => {
environment,
});
- // const payments = await authedClient.payments.list({});
- // console.log(payments);
const locs = await client.locations.list({});
- const pay = await client.payments.create({
+ await client.payments.create({
sourceId: "EXTERNAL",
idempotencyKey: v4(),
amountMoney: {
- amount: BigInt(1000),
- currency: "CAD",
+ amount: BigInt(parseFloat(fiat(p.amount, p.rate).toFixed(2)) * 100),
+ currency: p.currency,
},
- // appFeeMoney: {
- // amount: BigInt(10),
- // currency: "CAD",
- // },
+ tipMoney: p.tip
+ ? {
+ amount: BigInt(parseFloat(fiat(p.tip, p.rate).toFixed(2)) * 100),
+ currency: p.currency,
+ }
+ : undefined,
autocomplete: true,
- externalDetails: { type: "OTHER", source: `Coinos ${v4()}` },
+ externalDetails: { type: "OTHER", source: `Coinos payment ${p.id}` },
locationId: locs.locations[0].id,
referenceId: v4(),
- note: `Brief description ${v4()}`,
+ note: `Coinos payment ${p.id}`,
});
-
- console.log(pay);
};