aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/invoice
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/(app)/invoice')
-rw-r--r--src/routes/(app)/invoice/[id]/+layout.server.ts28
-rw-r--r--src/routes/(app)/invoice/[id]/tip/+page.server.ts13
2 files changed, 18 insertions, 23 deletions
diff --git a/src/routes/(app)/invoice/[id]/+layout.server.ts b/src/routes/(app)/invoice/[id]/+layout.server.ts
index 590e5d4d..d6ab979e 100644
--- a/src/routes/(app)/invoice/[id]/+layout.server.ts
+++ b/src/routes/(app)/invoice/[id]/+layout.server.ts
@@ -12,25 +12,29 @@ export async function load({ cookies, depends, params, url, parent }) {
if (id) {
invoice = await get(`/invoice/${id}`);
const options = !!url.searchParams.get("options");
-
- if (
- user &&
- invoice.uid !== user.id &&
- !(url.pathname.includes("tip") || url.pathname.includes("memo")) &&
- !options
- ) {
- redirect(307, `/send/invoice/${id}`);
- }
-
let { amount, pending, received } = invoice;
amount = parseInt(amount);
- subject = invoice.user;
const paid =
(!amount && (pending || received)) ||
(amount > 0 && (pending >= amount || received >= amount));
if (paid && !url.pathname.endsWith("paid")) {
- redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : ""));
+ if (invoice.uid === user.id)
+ redirect(307, `/invoice/${id}/paid` + (options ? "?options=true" : ""));
+ else redirect(307, `/pay/${subject.username}/${invoice.amount}`);
+ }
+
+ subject = invoice.user;
+
+ if (
+ user &&
+ invoice.uid !== user.id &&
+ !(url.pathname.includes("tip") || url.pathname.includes("memo")) &&
+ !options
+ ) {
+ if (invoice.prompt && invoice.tip === null)
+ redirect(307, `/invoice/${id}/tip`);
+ else redirect(307, `/send/invoice/${id}`);
}
}
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
index 988b6da5..12582b28 100644
--- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts
+++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts
@@ -5,23 +5,14 @@ import { fail, redirect } from "@sveltejs/kit";
export async function load({ cookies, parent }) {
const rates = await getRates();
- let { invoice, subject, user } = await parent();
+ const { invoice, subject, user } = await parent();
if (!invoice.amount) redirect(307, `/invoice/${invoice.id}`);
const pin = cookies.get("pin");
if (user) {
const trust = await get("/trust", auth(cookies));
const trusted = trust.includes(invoice.uid);
- if (trusted && (pin || !user.haspin)) {
- if (!invoice.prompt && invoice.user.prompt && user.tip > 0) {
- invoice.tip = Math.round(invoice.amount * (user.tip / 100));
- invoice = await post(
- "/invoice",
- { invoice, user: subject },
- auth(cookies),
- );
- }
-
+ if (trusted && (pin || !user.haspin) && user.tip > 0) {
let p;
try {
p = await post("/payments", { ...invoice, pin }, auth(cookies));