diff --git a/routes/api/receipt/[id].ts b/routes/api/receipt/[id].ts new file mode 100644 index 0000000..18b025e --- /dev/null +++ b/routes/api/receipt/[id].ts @@ -0,0 +1,52 @@ +import { define } from "../../../../utils.ts"; +import { getTransactionByStripeId } from "../../../../services/paymentService.ts"; + +export const handler = define.handlers({ + async GET(ctx) { + const stripeId = ctx.params.id; + if (!stripeId) { + return new Response("Not Found", { status: 404 }); + } + const tx = await getTransactionByStripeId(stripeId); + if (!tx) { + return new Response("Receipt not found", { status: 404 }); + } + const amount = tx.amount ?? 0; + const date = tx.payment_date || tx.created_on || Date.now(); + const leaseId = tx.lease_id || ""; + const method = tx.payment_method || "-"; + + const html = ` + + + + + Payment Receipt + + + +
+

Payment Receipt

+
Stripe/Payment ID
${stripeId}
+
Lease ID
${leaseId}
+
Amount
$${amount.toLocaleString()}
+
Method
${method}
+
Date
${new Date(date).toLocaleString()}
+
+ + `; + + return new Response(html, { + status: 200, + headers: { "content-type": "text/html; charset=utf-8" }, + }); + }, +}); +