receipt template

This commit is contained in:
Tria
2026-06-05 17:23:21 +03:00
parent 620607e50c
commit 6786bdd210
12 changed files with 381 additions and 112 deletions

View File

@@ -1,4 +1,4 @@
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
import { BadRequestException, Injectable, InternalServerErrorException, NotFoundException } from "@nestjs/common";
import { DataSource, QueryRunner } from "typeorm";
import { PaymentEntity } from "./entities/payment.entity";
import { PaymentStrategy } from "./strategies/payment.strategy";
@@ -6,11 +6,10 @@ import { PaymentTelebirrStrategy } from "./strategies/payment.telebirr.strategy"
import { PaymentRepository } from "./payment.repository";
import { ClientAction, PaymentPlatform } from "./strategies/payments.types";
import * as crypto from 'crypto';
import { PaymentStatus, UpdatePaymentStatusDto } from "./dto/update-payment-status.dto";
// import * as fs from 'fs';
// import * as path from 'path';
// import * as Handlebars from 'handlebars';
import * as fs from 'fs';
import * as path from 'path';
import * as Handlebars from 'handlebars';
type PaymentMethod = PaymentEntity["method"]
@@ -97,28 +96,6 @@ export class PaymentService {
}
async handleTelebirrPaymentCb(dto: UpdatePaymentStatusDto): Promise<void> {
switch (dto.status) {
case PaymentStatus.SUCCEEDED:
await this.paymentRepo.update({ merchantOrderId: dto.orderId }, { status: "success" })
break;
case PaymentStatus.FAILED:
await this.paymentRepo.update({ merchantOrderId: dto.orderId }, { status: "failed", failureMessage: dto.failureMessage })
break;
case PaymentStatus.CANCELLED:
await this.paymentRepo.update({ merchantOrderId: dto.orderId }, { status: "canceled" })
break;
case PaymentStatus.PROCESSING:
await this.paymentRepo.update({ merchantOrderId: dto.orderId }, { status: "canceled" })
break;
case PaymentStatus.REFUNDED:
await this.paymentRepo.update({ merchantOrderId: dto.orderId }, { status: "canceled" })
break;
}
}
getReceiptTemplate(data: {
@@ -333,17 +310,15 @@ export class PaymentService {
if (!payment) {
throw new BadRequestException()
}
// const templatePath = path.join(
// process.cwd(),
// 'src/modules/payment/templates/receipt.hbs',
// );
const filePath = path.join(__dirname, "templates", "ceiepts.hbs");
if (!fs.existsSync(filePath)) {
throw new InternalServerErrorException()
}
const source = fs.readFileSync(filePath, "utf8");
const template = Handlebars.compile(source);
// console.log(templatePath)
// const source = fs.readFileSync(templatePath, 'utf8');
// const template = Handlebars.compile(source);
return this.getReceiptTemplate({
const html = template({
vendorName: "Ethio Djibouti Railway Ticket Booking",
vendorAddress: "Addis Ababa",
receiptDate: new Date().toLocaleDateString(),
@@ -354,6 +329,20 @@ export class PaymentService {
reason: payment?.reason
});
return html;
}
}
// const templatePath = path.join(
// process.cwd(),
// 'src/modules/payment/templates/receipt.hbs',
// );
// console.log(templatePath)
// const source = fs.readFileSync(templatePath, 'utf8');
// const template = Handlebars.compile(source);
// return this.getReceiptTemplate();
}