mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
resolve merge conflict
This commit is contained in:
@@ -62,107 +62,6 @@ export class PaymentService {
|
||||
|
||||
const result = await this.telebirrProvider.initiate(input);
|
||||
|
||||
<<<<<<< HEAD
|
||||
const queryRunner = this.datasource.createQueryRunner();
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
console.log(paymentResp.expiresAt);
|
||||
try {
|
||||
const resp = await cb(queryRunner);
|
||||
const payment = await this.paymentRepo.createTr(queryRunner, {
|
||||
amount,
|
||||
currency,
|
||||
method,
|
||||
refId: resp.id,
|
||||
type: resp.type,
|
||||
merchantOrderId: orderId,
|
||||
rawInitiation: paymentResp.rawInitiation,
|
||||
clientAction: paymentResp.clientAction,
|
||||
expiresAt: paymentResp.expiresAt,
|
||||
reason,
|
||||
});
|
||||
await queryRunner.commitTransaction();
|
||||
return {
|
||||
refId: payment.refId,
|
||||
clientAction: paymentResp.clientAction,
|
||||
status: payment.status,
|
||||
paidAt: payment.paidAt?.toISOString(),
|
||||
failureCode: payment.failerCode ?? undefined,
|
||||
failureMessage: payment.failureMessage ?? undefined,
|
||||
};
|
||||
} catch (err) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw new Error("payment failed");
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
async getActivePaymentByRefIdAndMethod(
|
||||
refId: string,
|
||||
method: PaymentEntity["method"],
|
||||
): Promise<PaymentEntity | null> {
|
||||
return this.paymentRepo.getActivePaymentByRefIdAndMethod(refId, method);
|
||||
}
|
||||
|
||||
async genReceiptHtml(orderId: string) {
|
||||
const payment = await this.paymentRepo.findOneBy({
|
||||
merchantOrderId: orderId,
|
||||
status: "success",
|
||||
});
|
||||
if (!payment) {
|
||||
throw new BadRequestException();
|
||||
}
|
||||
|
||||
const filePath = path.join(__dirname, "templates", "receipt.hbs");
|
||||
if (!fs.existsSync(filePath)) {
|
||||
throw new InternalServerErrorException();
|
||||
}
|
||||
const source = fs.readFileSync(filePath, "utf8");
|
||||
const template = Handlebars.compile(source);
|
||||
|
||||
const html = template({
|
||||
vendorName: "Ethio Djibouti Railway Ticket Booking",
|
||||
vendorAddress: "Addis Ababa",
|
||||
receiptDate: payment.paidAt,
|
||||
paymentMethod: payment?.method,
|
||||
subtotal: payment?.amount.toString(),
|
||||
total: payment?.amount.toString(),
|
||||
currency: payment?.currency,
|
||||
reason: payment?.reason,
|
||||
});
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
async checkStatusAndUpdate(orderId: string) {
|
||||
const resp = await this.paymentRepo.findOneBy({ merchantOrderId: orderId });
|
||||
if (!resp) {
|
||||
throw new NotFoundException("order id not found");
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this.telebirrPaymentStategy.queryStatus(
|
||||
resp.merchantOrderId,
|
||||
);
|
||||
const bizContent = result.rawResponse.biz_content as {
|
||||
order_status: string;
|
||||
};
|
||||
|
||||
const ordersStatus = bizContent.order_status;
|
||||
if (ordersStatus == "PAY_SUCCESS") {
|
||||
await this.datasource.transaction(async (mg) => {
|
||||
const now = new Date();
|
||||
const holdExpires = new Date(now.getTime() + 3 * 60 * 60 * 1000);
|
||||
await mg.update(Booking, { id: resp.refId }, {
|
||||
status: "PAID",
|
||||
schedulingStatus: SchedulingStatus.Holding,
|
||||
holdStartedAt: now,
|
||||
holdExpiresAt: holdExpires,
|
||||
});
|
||||
await mg.update(PaymentEntity, { id: resp.id }, { status: "success" });
|
||||
=======
|
||||
const payment = await this.paymentRepo.create({
|
||||
amount: amount,
|
||||
currency: DEFAULT_CURRENCY,
|
||||
@@ -174,7 +73,6 @@ export class PaymentService {
|
||||
clientAction: result.clientAction as Record<string, unknown>,
|
||||
expiresAt: result.expiresAt,
|
||||
reason: `Payment for booking`,
|
||||
>>>>>>> eda21e22d872344b74c0c72308f87ce7435b299f
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user