From ebe59f491aa82ec0150668bd222fa33183d85ecb Mon Sep 17 00:00:00 2001 From: Tria Date: Fri, 5 Jun 2026 17:34:33 +0300 Subject: [PATCH] payment | webhook --- .../src/modules/payment/payment.controller.ts | 28 +-- .../src/modules/payment/payment.service.ts | 209 +----------------- .../webhooks/providers/telebirr.service.ts | 5 +- 3 files changed, 17 insertions(+), 225 deletions(-) diff --git a/apps/edr-freight-api/src/modules/payment/payment.controller.ts b/apps/edr-freight-api/src/modules/payment/payment.controller.ts index c82192148..05b127968 100644 --- a/apps/edr-freight-api/src/modules/payment/payment.controller.ts +++ b/apps/edr-freight-api/src/modules/payment/payment.controller.ts @@ -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) + // } + // } diff --git a/apps/edr-freight-api/src/modules/payment/payment.service.ts b/apps/edr-freight-api/src/modules/payment/payment.service.ts index 76f2f068e..b714d5175 100644 --- a/apps/edr-freight-api/src/modules/payment/payment.service.ts +++ b/apps/edr-freight-api/src/modules/payment/payment.service.ts @@ -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 ` - - - - - - Receipt - ${data.vendorName} - - - - - -
-
-

${data.vendorName}

-

${data.vendorAddress}

-
- - - - - - - - - - - - - - - - -
Date${data.receiptDate}
Payment Method - ${data.paymentMethod} -
Description${data.reason ?? "-"}
- -
- - - - - - - - - - -
Subtotal - ${data.currency} ${data.subtotal ?? "0.00"} -
- Total Paid - - ${data.currency} ${data.total ?? "0.00"} -
-
- - - -
- -
-
- - - - -`; - } - - 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(), diff --git a/apps/edr-freight-api/src/modules/payment/webhooks/providers/telebirr.service.ts b/apps/edr-freight-api/src/modules/payment/webhooks/providers/telebirr.service.ts index ae101815a..a57c79982 100644 --- a/apps/edr-freight-api/src/modules/payment/webhooks/providers/telebirr.service.ts +++ b/apps/edr-freight-api/src/modules/payment/webhooks/providers/telebirr.service.ts @@ -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;