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

@@ -1058,16 +1058,24 @@ export class BillingService {
* settlement; settleByPaymentId still performs the real transition.
*/
async markInvoicePaymentProcessing(paymentId: string): Promise<void> {
await this.dataSource.getRepository(Invoice).update(
{
paymentId,
status: In([
Freight.InvoiceStatus.Issued,
Freight.InvoiceStatus.Pending,
]),
},
{ status: Freight.InvoiceStatus.PaymentProcessing },
);
const repo = this.dataSource.getRepository(Invoice);
const invoices = await repo.findBy({
paymentId,
status: In([
Freight.InvoiceStatus.Issued,
Freight.InvoiceStatus.Pending,
]),
});
for (const invoice of invoices) {
await repo.update(
{ id: invoice.id, status: invoice.status },
{ status: Freight.InvoiceStatus.PaymentProcessing },
);
this.emitInvoiceEvent("payment-processing", {
...invoice,
status: Freight.InvoiceStatus.PaymentProcessing,
} as Invoice);
}
}
/**
@@ -1076,12 +1084,21 @@ export class BillingService {
* retry. No-op from any other status.
*/
async revertInvoicePaymentProcessing(paymentId: string): Promise<void> {
await this.dataSource
.getRepository(Invoice)
.update(
{ paymentId, status: Freight.InvoiceStatus.PaymentProcessing },
const repo = this.dataSource.getRepository(Invoice);
const invoices = await repo.findBy({
paymentId,
status: Freight.InvoiceStatus.PaymentProcessing,
});
for (const invoice of invoices) {
await repo.update(
{ id: invoice.id, status: Freight.InvoiceStatus.PaymentProcessing },
{ status: Freight.InvoiceStatus.Pending },
);
this.emitInvoiceEvent("payment-processing-reverted", {
...invoice,
status: Freight.InvoiceStatus.Pending,
} as Invoice);
}
}
// ── Payment initiation & settlement (the gateway boundary) ───────────────────