providers

This commit is contained in:
Eyosiyas
2026-06-06 11:32:14 +03:00
parent 06276764e0
commit b5f64bc9ad
8 changed files with 107 additions and 79 deletions

View File

@@ -10,6 +10,8 @@ import * as crypto from 'crypto';
import * as fs from 'fs';
import * as path from 'path';
import * as Handlebars from 'handlebars';
import { ConfigService } from "@nestjs/config";
import { Booking } from "../bookings/entities/booking.entity";
type PaymentMethod = PaymentEntity["method"]
@@ -20,6 +22,7 @@ export class PaymentService {
private strategies: Map<PaymentMethod, PaymentStrategy>;
constructor(
private readonly configService: ConfigService,
private readonly datasource: DataSource,
private readonly paymentRepo: PaymentRepository,
private readonly telebirrPaymentStategy: PaymentTelebirrStrategy) {
@@ -47,7 +50,8 @@ export class PaymentService {
let redirectUrl: string;
switch (type) {
case "booking":
redirectUrl = `http://localhost:3001/api/payments/receipts/${orderId}/html`
const url = this.configService.get<string>("TELEBIRR_SUCCESS_REDIRECT_BASE_URL")
redirectUrl = `${url}/check-status/${orderId}`
break;
}
@@ -132,17 +136,27 @@ export class PaymentService {
return html;
}
// const templatePath = path.join(
// process.cwd(),
// 'src/modules/payment/templates/receipt.hbs',
// );
async checkStatusAndUpdate(orderId: string) {
const resp = await this.paymentRepo.findOneBy({ merchantOrderId: orderId })
if (!resp) {
throw new NotFoundException("order id not found")
}
const result = await this.telebirrPaymentStategy.queryStatus(resp.merchantOrderId)
const bizContent = result.rawResponse.biz_content as {
order_status: string;
};
// console.log(templatePath)
// const source = fs.readFileSync(templatePath, 'utf8');
// const template = Handlebars.compile(source);
// return this.getReceiptTemplate();
const ordersStatus = bizContent.order_status
if (ordersStatus == "PAY_SUCCESS") {
await this.datasource.transaction(async (mg) => {
await mg.update(Booking, { id: resp.refId }, { status: "PAID" })
await mg.update(PaymentEntity, { id: resp.id }, { status: "success" })
})
}
return {
status: result.status
}
}
}