mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 00:52:50 +00:00
64 lines
2.3 KiB
TypeScript
64 lines
2.3 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
HttpCode,
|
|
HttpStatus,
|
|
Post,
|
|
SetMetadata,
|
|
UseGuards,
|
|
} from "@nestjs/common";
|
|
import { ApiOperation, ApiTags } from "@nestjs/swagger";
|
|
import { PaymentReferenceType } from "@edr/types";
|
|
import { ServiceAuthGuard } from "../../common/guards/service-auth.guard";
|
|
import {
|
|
PaymentEventDto,
|
|
MarkPaidResponseDto,
|
|
BillQueryRequestDto,
|
|
BillQueryResponseDto,
|
|
} from "./internal-payments.dto";
|
|
import { PaymentsService } from "./payments.service";
|
|
|
|
/**
|
|
* Consumer side of the payment microservice's outbox relay (docs/payment-service §7.3).
|
|
* Only the payment service may call this (shared service token). Idempotent by design:
|
|
* the relay delivers at-least-once, so duplicates must be harmless. Becomes a queue
|
|
* consumer when RabbitMQ lands — the handler logic is transport-agnostic.
|
|
*/
|
|
@ApiTags("Internal Payments")
|
|
// isPublic only skips the global IAM user-JWT guard — these routes stay protected by
|
|
// ServiceAuthGuard's shared service token (the payment service is not an IAM user).
|
|
@SetMetadata("isPublic", true)
|
|
@UseGuards(ServiceAuthGuard)
|
|
@Controller("internal/payments")
|
|
export class InternalPaymentsController {
|
|
constructor(private readonly paymentsService: PaymentsService) {}
|
|
|
|
@Post("mark-paid")
|
|
@HttpCode(HttpStatus.OK)
|
|
@ApiOperation({
|
|
summary:
|
|
"Apply a payment.succeeded/payment.failed event from the payment service (idempotent)",
|
|
})
|
|
async markPaid(@Body() event: PaymentEventDto): Promise<MarkPaidResponseDto> {
|
|
return this.paymentsService.handlePaymentEvent(event);
|
|
}
|
|
|
|
@Post("bill-query")
|
|
@HttpCode(HttpStatus.OK)
|
|
@ApiOperation({
|
|
summary:
|
|
"Live still-payable check + payer name for a CBE bill (called while CBE is on the line)",
|
|
})
|
|
async billQuery(
|
|
@Body() request: BillQueryRequestDto,
|
|
): Promise<BillQueryResponseDto> {
|
|
// Routed on referenceType: the passenger app issues CBE bills for bookings AND for excess
|
|
// baggage charges, and they live in different tables. Treating every referenceId as a
|
|
// bookingId would report a perfectly payable baggage bill as NOT_FOUND to the teller.
|
|
if (request.referenceType === PaymentReferenceType.EXCESS_BAGGAGE) {
|
|
return this.paymentsService.billQueryExcessBaggage(request.referenceId);
|
|
}
|
|
return this.paymentsService.billQuery(request.referenceId);
|
|
}
|
|
}
|