mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 12:00:59 +00:00
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { Controller, Get, NotFoundException, Param, Post, Res } from "@nestjs/common";
|
|
import { PaymentService } from "./payment.service";
|
|
import { Public } from "@edr/api-common";
|
|
import { Response } from "express"
|
|
|
|
@Public()
|
|
@Controller("payments")
|
|
export class PaymentController {
|
|
constructor(private readonly paymentService: PaymentService,) { }
|
|
|
|
@Post("/initiate")
|
|
initiate() {
|
|
return this.paymentService.initBookingTelebirr("123", "web")
|
|
}
|
|
|
|
@Post("/bookings/check-payment/:orderId")
|
|
checkPayment(@Param("orderId") orderId: string) {
|
|
return this.paymentService.checkStatusAndUpdate(orderId)
|
|
}
|
|
|
|
@Get("/bookings/telebirr/redirect/:orderId")
|
|
async pay(@Param("orderId") orderId: string, @Res() res: Response) {
|
|
const payment = await this.paymentService.getActivePaymentByOrderIdAndMethod(orderId, "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>
|
|
`);
|
|
}
|
|
}
|