diff options
| author | Adam Soltys <[email protected]> | 2025-07-08 10:16:22 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2025-07-08 10:16:22 -0700 |
| commit | 2d9d01d6e8d63ee223078874aa3b101b016367ac (patch) | |
| tree | 0a5a7d90c15aadcd22a75e65aafa2c69287442c0 /src/routes/(app)/invoice | |
| parent | 3c63c47f51f0b86f530ce2381a44a05cb1e4abf1 (diff) | |
| download | coinos-ui-2d9d01d6e8d63ee223078874aa3b101b016367ac.tar.gz coinos-ui-2d9d01d6e8d63ee223078874aa3b101b016367ac.zip | |
auto pay
Diffstat (limited to 'src/routes/(app)/invoice')
| -rw-r--r-- | src/routes/(app)/invoice/[id]/tip/+page.server.ts | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index c3be68f0..de24c639 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -1,12 +1,29 @@ import invoice from "$lib/invoice"; import getRates from "$lib/rates"; +import { auth, get, post } from "$lib/utils"; import { redirect } from "@sveltejs/kit"; -export async function load({ parent }) { +export async function load({ cookies, parent }) { const rates = await getRates(); - const { invoice, subject } = await parent(); + let { invoice, subject, user } = await parent(); if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`); + const trust = await get("/trust", auth(cookies)); + const trusted = trust.includes(invoice.uid); + if (trusted) { + if (invoice.prompt && invoice.tip === null && user.tip > 0) { + invoice.tip = Math.round(invoice.amount * (user.tip / 100)); + invoice = await post( + "/invoice", + { invoice, user: subject }, + auth(cookies), + ); + } + + const p = await post("/payments", invoice, auth(cookies)); + redirect(307, `/sent/${p.id}`); + } + const rate = rates[subject?.currency]; const invoiceRate = rates[invoice.currency]; return { rate, invoiceRate }; |
