feat: add receipts to the payment service
This commit is contained in:
@@ -305,6 +305,30 @@ export const dashboard = new Elysia()
|
||||
return html("checkout", { nav: "settings", account: acc, payApi, invoiceId: params.id, coins, invoice });
|
||||
})
|
||||
|
||||
// Receipt (proxy to pay service, serves HTML directly)
|
||||
.get("/dashboard/checkout/:id/receipt", async ({ cookie, headers, params, set }) => {
|
||||
const resolved = await getAccountId(cookie, headers);
|
||||
if (!resolved?.accountId) return redirect("/dashboard");
|
||||
|
||||
const payApi = process.env.PAY_API || "https://pay.pingql.com";
|
||||
const key = cookie?.pingql_key?.value;
|
||||
try {
|
||||
const res = await fetch(`${payApi}/checkout/${params.id}/receipt`, {
|
||||
headers: { "Authorization": `Bearer ${key}` },
|
||||
});
|
||||
if (!res.ok) {
|
||||
const data = await res.json().catch(() => ({}));
|
||||
set.status = res.status;
|
||||
return data.error || "Receipt not available";
|
||||
}
|
||||
set.headers["content-type"] = "text/html; charset=utf-8";
|
||||
return await res.text();
|
||||
} catch {
|
||||
set.status = 500;
|
||||
return "Could not load receipt";
|
||||
}
|
||||
})
|
||||
|
||||
// Create checkout via form POST (no-JS)
|
||||
.post("/dashboard/checkout", async ({ cookie, headers, body }) => {
|
||||
const resolved = await getAccountId(cookie, headers);
|
||||
|
||||
Reference in New Issue
Block a user