feat: ( payment ) implement cbe payment

This commit is contained in:
Abubeker
2026-07-31 07:50:10 +00:00
parent e4a2c61224
commit 37855b0a83
52 changed files with 2244 additions and 368 deletions

View File

@@ -0,0 +1,57 @@
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 "3"; 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);
}
}