59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
// src/controllers/billing.controller.ts
|
|
import { Controller, Post, Body, Headers, HttpException, HttpStatus } from '@nestjs/common';
|
|
import { MockDataService } from '../services/mock-data.service';
|
|
|
|
@Controller('payment/mea/v1')
|
|
export class BillingController {
|
|
constructor(private mockData: MockDataService) {}
|
|
|
|
@Post('acr:X-Orange-ISE2/transactions/amount')
|
|
chargeUser(
|
|
@Headers('x-orange-ise2') ise2: string,
|
|
@Headers('x-orange-mco') mco: string,
|
|
@Body() body: any,
|
|
) {
|
|
console.log('[MOCK] Charge request:', { ise2, mco, body });
|
|
|
|
const { amountTransaction } = body;
|
|
|
|
if (!amountTransaction) {
|
|
throw new HttpException({
|
|
requestError: {
|
|
serviceException: {
|
|
messageId: 'SVC0002',
|
|
text: 'Invalid input value for message part amountTransaction'
|
|
}
|
|
}
|
|
}, HttpStatus.BAD_REQUEST);
|
|
}
|
|
|
|
const amount = parseFloat(amountTransaction.paymentAmount.chargingInformation.amount);
|
|
|
|
// Simuler une transaction
|
|
const result = this.mockData.createTransaction({
|
|
endUserId: ise2,
|
|
amount,
|
|
...amountTransaction,
|
|
});
|
|
|
|
if (!result.success) {
|
|
throw new HttpException({
|
|
requestError: {
|
|
policyException: {
|
|
messageId: result.error.code,
|
|
text: result.error.message
|
|
}
|
|
}
|
|
}, HttpStatus.FORBIDDEN);
|
|
}
|
|
|
|
return {
|
|
amountTransaction: {
|
|
...amountTransaction,
|
|
serverReferenceCode: result.transaction.serverReferenceCode,
|
|
transactionOperationStatus: 'Charged',
|
|
resourceURL: `http://localhost:3001/payment/mea/v1/transactions/${result.transaction.serverReferenceCode}`
|
|
}
|
|
};
|
|
}
|
|
} |