Files
edr-platform/apps/edr-payment-api/src/modules/cbe-bill/cbe-bill.controller.ts

58 lines
2.1 KiB
TypeScript

import {
Body,
Controller,
HttpCode,
HttpStatus,
Post,
UseFilters,
UseGuards,
} from "@nestjs/common";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { CbeAuthGuard } from "./cbe-auth.guard";
import { CbeExceptionFilter } from "./cbe-exception.filter";
import { CbeBillService } from "./cbe-bill.service";
import { TokenRequestDto } from "./dto/token-request.dto";
import { TokenResponseDto } from "./dto/token-response.dto";
import { CbeQueryRequestDto } from "./dto/cbe-query-request.dto";
import { CbeQueryResponseDto } from "./dto/cbe-query-response.dto";
import { CbePaymentRequestDto } from "./dto/cbe-payment-request.dto";
import { CbePaymentResponseDto } from "./dto/cbe-payment-response.dto";
/**
* CBE Unified Bill Payment — the INBOUND surface CBE core banking calls (docs/cbe/). We are
* the biller: CBE authenticates against /cbe/oauth/token with credentials we issued, then
* presents the bearer token on /cbe/query and /cbe/payment. Business failures answer HTTP 200
* with Response_Code "2"; only authentication answers 401 (plan D6/D7).
*/
@ApiTags("CBE Unified Bill (inbound)")
@Controller("cbe")
@UseFilters(CbeExceptionFilter)
export class CbeBillController {
constructor(private readonly cbeBillService: CbeBillService) {}
@Post("oauth/token")
@HttpCode(HttpStatus.OK)
@ApiOperation({ summary: "OAuth client_credentials token for CBE (we are the auth server)" })
async token(@Body() dto: TokenRequestDto): Promise<TokenResponseDto> {
return this.cbeBillService.generateToken(dto);
}
@Post("query")
@HttpCode(HttpStatus.OK)
@UseGuards(CbeAuthGuard)
@ApiOperation({ summary: "Bill lookup — amount due + payer name for a Bill_Id" })
async query(@Body() dto: CbeQueryRequestDto): Promise<CbeQueryResponseDto> {
return this.cbeBillService.query(dto);
}
@Post("payment")
@HttpCode(HttpStatus.OK)
@UseGuards(CbeAuthGuard)
@ApiOperation({ summary: "Settle a bill — customer already debited by CBE" })
async payment(
@Body() dto: CbePaymentRequestDto,
): Promise<CbePaymentResponseDto> {
return this.cbeBillService.pay(dto);
}
}