payment | webhook

This commit is contained in:
Tria
2026-06-05 17:34:33 +03:00
parent 6786bdd210
commit ebe59f491a
3 changed files with 17 additions and 225 deletions

View File

@@ -65,24 +65,24 @@ export class PaymentController {
}
@Get("test")
handleTest(@Res() res: Response) {
// @Get("test")
// handleTest(@Res() res: Response) {
const filePath = path.join(__dirname, "templates", "payment.hbs");
console.log(filePath)
console.log(__dirname)
if (fs.existsSync(filePath)) {
const source = fs.readFileSync(filePath, "utf8");
const template = Handlebars.compile(source);
// const filePath = path.join(__dirname, "templates", "payment.hbs");
// console.log(filePath)
// console.log(__dirname)
// if (fs.existsSync(filePath)) {
// const source = fs.readFileSync(filePath, "utf8");
// const template = Handlebars.compile(source);
const html = template({
url: "https://example.com"
});
// const html = template({
// url: "https://example.com"
// });
res.send(html)
}
}
// res.send(html)
// }
// }

View File

@@ -95,213 +95,6 @@ export class PaymentService {
return this.paymentRepo.getActivePaymentByRefIdAndMethod(refId, method)
}
getReceiptTemplate(data: {
vendorName: string;
vendorAddress: string;
receiptDate: string;
paymentMethod: string;
subtotal?: string;
total?: string;
currency: string;
reason?: string;
}) {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Receipt - ${data.vendorName}</title>
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f9f9f9;
margin: 0;
padding: 20px;
}
.receipt-box {
max-width: 550px;
margin: auto;
padding: 30px;
border: 1px solid #eee;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
border-radius: 8px;
}
.header {
text-align: center;
border-bottom: 2px dashed #eee;
padding-bottom: 20px;
margin-bottom: 20px;
}
.header h1 {
font-size: 22px;
margin: 0 0 5px;
color: #0056b3;
}
.header p {
font-size: 14px;
color: #777;
margin: 0;
}
.details-table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
.details-table td {
padding: 10px 0;
font-size: 14px;
}
.label {
color: #777;
font-weight: 600;
}
.value {
text-align: right;
}
.totals-section {
border-top: 1px solid #eee;
padding-top: 15px;
}
.total-row {
font-size: 16px;
font-weight: bold;
}
.footer {
text-align: center;
margin-top: 30px;
font-size: 12px;
color: #999;
border-top: 1px solid #eee;
padding-top: 15px;
}
.download-container {
text-align: center;
margin-top: 25px;
}
.download-btn {
background: #0056b3;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 14px;
font-weight: 600;
}
.download-btn:hover {
background: #004494;
}
@media print {
body {
background: white;
padding: 0;
}
.receipt-box {
box-shadow: none;
border: none;
max-width: 100%;
}
.download-container {
display: none;
}
}
</style>
</head>
<body>
<div class="receipt-box">
<div class="header">
<h1>${data.vendorName}</h1>
<p>${data.vendorAddress}</p>
</div>
<table class="details-table">
<tr>
<td class="label">Date</td>
<td class="value">${data.receiptDate}</td>
</tr>
<tr>
<td class="label">Payment Method</td>
<td class="value" style="text-transform: capitalize;">
${data.paymentMethod}
</td>
</tr>
<tr>
<td class="label">Description</td>
<td class="value">${data.reason ?? "-"}</td>
</tr>
</table>
<div class="totals-section">
<table class="details-table">
<tr>
<td class="label">Subtotal</td>
<td class="value">
${data.currency} ${data.subtotal ?? "0.00"}
</td>
</tr>
<tr class="total-row">
<td class="label" style="color:#333">
Total Paid
</td>
<td class="value" style="color:#0056b3">
${data.currency} ${data.total ?? "0.00"}
</td>
</tr>
</table>
</div>
<div class="footer">
<p>Thank you for traveling with us!</p>
<p>Have a safe journey.</p>
</div>
<div class="download-container">
<button class="download-btn" onclick="downloadPdf()">
Download PDF
</button>
</div>
</div>
<script>
function downloadPdf() {
window.print();
}
</script>
</body>
</html>
`;
}
async genReceiptHtml(orderId: string) {
const payment = await this.paymentRepo.findOneBy({
merchantOrderId: orderId,
@@ -321,7 +114,7 @@ export class PaymentService {
const html = template({
vendorName: "Ethio Djibouti Railway Ticket Booking",
vendorAddress: "Addis Ababa",
receiptDate: new Date().toLocaleDateString(),
receiptDate: payment.paidAt,
paymentMethod: payment?.method,
subtotal: payment?.amount.toString(),
total: payment?.amount.toString(),

View File

@@ -54,11 +54,10 @@ export class TelebirrWebhookService {
}
switch (payload.trade_status) {
case "SUCCEEDED":
console.log(payment.id)
await this.paymentRepo.update({ id: payment.id }, { status: "success" })
await this.paymentRepo.update({ id: payment.id }, { status: "success", paidAt: new Date() })
switch (payment.type) {
case "booking":
await this.bookingRepo.update(payment.refId, { paymentStatus: "PAID" })
await this.bookingRepo.update(payment.refId, { paymentStatus: "PAID", })
break;
}
break;