mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 18:48:11 +00:00
Merge pull request #1131 from Tria-plc/freight_feature/usermanagement
feat(billing): enhance invoice payment processing and revert handling
This commit is contained in:
@@ -1059,16 +1059,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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1077,12 +1085,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) ───────────────────
|
||||
|
||||
Reference in New Issue
Block a user