47 lines
1.8 KiB
TypeScript
47 lines
1.8 KiB
TypeScript
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 = `<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Payment Receipt</title>
|
|
<link rel="stylesheet" href="/assets/styles.css" />
|
|
</head>
|
|
<body class="receipt">
|
|
<div class="receipt-card">
|
|
<h1>Payment Receipt</h1>
|
|
<div class="receipt-row"><div class="receipt-label">Stripe/Payment ID</div><div class="receipt-value">${stripeId}</div></div>
|
|
<div class="receipt-row"><div class="receipt-label">Lease ID</div><div class="receipt-value">${leaseId}</div></div>
|
|
<div class="receipt-row"><div class="receipt-label">Amount</div><div class="receipt-value">$${amount.toLocaleString()}</div></div>
|
|
<div class="receipt-row"><div class="receipt-label">Method</div><div class="receipt-value">${method}</div></div>
|
|
<div class="receipt-row"><div class="receipt-label">Date</div><div class="receipt-value">${
|
|
new Date(date).toLocaleString()
|
|
}</div></div>
|
|
</div>
|
|
</body>
|
|
</html>`;
|
|
|
|
return new Response(html, {
|
|
status: 200,
|
|
headers: { "content-type": "text/html; charset=utf-8" },
|
|
});
|
|
},
|
|
});
|