Files
edr-platform/apps/edr-freight-api/src/modules/payment/payment.controller.ts
2026-06-05 12:57:44 +03:00

53 lines
1.3 KiB
TypeScript

import { Controller, Get, NotFoundException, Param, ParseUUIDPipe, Post, Res } from "@nestjs/common";
import { PaymentService } from "./payment.service";
import { Public } from "@edr/api-common";
import { randomUUID } from "crypto";
import { Response } from "express"
@Public()
@Controller("payments")
export class PaymentController {
constructor(private readonly paymentService: PaymentService) { }
@Post("/initiate")
async initiatePayment() {
//Only for testing..
const data = await this.paymentService.pay(20, "ETB", "telebirr", (_) => {
return new Promise((resp, _) => {
resp({
id: randomUUID(),
type: "booking"
})
});
})
return data
}
@Get("/telebirr/:refId")
async pay(@Param("refId", ParseUUIDPipe) refId: string, @Res() res: Response) {
const payment = await this.paymentService.getActivePaymentByRefIdAndMethod(refId, "telebirr")
if (!payment) {
throw new NotFoundException('payment not found')
}
return res.send(`
<!DOCTYPE html>
<html>
<head>
<title>Redirecting...</title>
</head>
<body>
<p>Redirecting...</p>
<script>
window.location.href = "${payment.clientAction?.url}";
</script>
</body>
</html>
`);
}
}