feat(billing): enhance invoice payment processing and revert handling

feat(bookings): add event handlers for booking invoice payment processing
fix(bookings): include PAYMENT_VERIFICATION_IN_PROGRESS status in queries
fix(train-scheduling): update status checks to include PAYMENT_VERIFICATION_IN_PROGRESS
feat(notifier): notify customers when a train is cancelled
This commit is contained in:
Marshal
2026-08-05 20:46:44 +00:00
parent 1b5f364294
commit 8089e5cfd9
8 changed files with 102 additions and 24 deletions

View File

@@ -115,6 +115,34 @@ export class BookingInvoiceService {
}
}
/**
* Success-redirect ack: the customer finished provider checkout, webhook not
* in yet. Mirror the invoice's PAYMENT_PROCESSING on the booking so the
* portal stops offering "Pay now". Display state only — settlement
* (`booking.invoice.paid`) still drives PAID. Status-guarded, so it never
* touches a booking that already advanced or was terminated.
*/
@OnEvent("booking.invoice.payment-processing")
async onBookingInvoicePaymentProcessing(
payload: InvoiceEventPayload,
): Promise<void> {
await this.dataSource.getRepository(Booking).update(
{ id: payload.sourceId, status: "SELECTED_FOR_BATCH" },
{ status: "PAYMENT_VERIFICATION_IN_PROGRESS" },
);
}
/** Payment failed after a redirect ack — the booking reads payable again. */
@OnEvent("booking.invoice.payment-processing-reverted")
async onBookingInvoicePaymentProcessingReverted(
payload: InvoiceEventPayload,
): Promise<void> {
await this.dataSource.getRepository(Booking).update(
{ id: payload.sourceId, status: "PAYMENT_VERIFICATION_IN_PROGRESS" },
{ status: "SELECTED_FOR_BATCH" },
);
}
updateStatus(
invoiceId: string,
status: Freight.InvoiceStatus,

View File

@@ -1405,7 +1405,9 @@ export class BookingsRepository extends BaseRepository<Booking> {
.leftJoinAndSelect('bookingContainer.containerType', 'containerType')
.leftJoinAndSelect('booking.cargoType', 'cargoType')
.where('booking.train_schedule_id = :scheduleId', { scheduleId })
.andWhere(`booking.status IN ('SELECTED_FOR_BATCH', 'AWAITING_PAYMENT')`)
.andWhere(
`booking.status IN ('SELECTED_FOR_BATCH', 'AWAITING_PAYMENT', 'PAYMENT_VERIFICATION_IN_PROGRESS')`,
)
.getMany();
}