mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 09:58:12 +00:00
auto allocation and batch managemnt, tracking the train
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
forwardRef,
|
||||
Inject,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
NotFoundException,
|
||||
@@ -23,6 +25,7 @@ import {
|
||||
} from "@edr/payment-providers";
|
||||
import { ProviderInitiationInput } from "@edr/types"
|
||||
import { InitiateResponseDto, PaymentPlatformDto } from "./payments.dto";
|
||||
import { BookingBatchService } from "../train-scheduling/booking-batch.service";
|
||||
|
||||
const DEFAULT_CURRENCY = "ETB";
|
||||
|
||||
@@ -33,6 +36,8 @@ export class PaymentService {
|
||||
private readonly datasource: DataSource,
|
||||
private readonly paymentRepo: PaymentRepository,
|
||||
private readonly telebirrProvider: TelebirrProvider,
|
||||
@Inject(forwardRef(() => BookingBatchService))
|
||||
private readonly bookingBatchService: BookingBatchService,
|
||||
) { }
|
||||
|
||||
async initBookingTelebirr(
|
||||
@@ -125,15 +130,12 @@ export class PaymentService {
|
||||
|
||||
if (result.status === ProviderPaymentStatus.SUCCEEDED) {
|
||||
await this.datasource.transaction(async (mg) => {
|
||||
const booking = await mg.findOne(Booking, { where: { id: resp.refId } })
|
||||
if (booking?.status === "AWAITING_PAYMENT") {
|
||||
// Batch flow: mark paid but keep the reservation — the batch settle job allocates it.
|
||||
await mg.update(Booking, { id: resp.refId }, { paymentStatus: "PAID" })
|
||||
} else {
|
||||
await mg.update(Booking, { id: resp.refId }, { status: "PAID" })
|
||||
}
|
||||
await mg.update(PaymentEntity, { id: resp.id }, { status: "success" })
|
||||
await mg.update(Booking, { id: resp.refId }, { paymentStatus: "PAID" })
|
||||
})
|
||||
if (resp.type === "booking") {
|
||||
await this.bookingBatchService.ensurePaidBookingAllocated(resp.refId)
|
||||
}
|
||||
}
|
||||
return {
|
||||
status: result.status
|
||||
|
||||
Reference in New Issue
Block a user