fix : sep gateway
This commit is contained in:
@@ -7,6 +7,38 @@ import { BadRequestError } from "../app/app.errors";
|
||||
|
||||
@injectable()
|
||||
export class ValidationMiddleware {
|
||||
static validateInputWithLogging(DTO: ClassConstructor<any>, logPrefix: string = "Request Body"): RequestHandler {
|
||||
return async (req: Request, _res: Response, next: NextFunction): Promise<void> => {
|
||||
try {
|
||||
// Log the raw request body before validation
|
||||
console.log(`${logPrefix}:`, JSON.stringify(req.body, null, 2));
|
||||
|
||||
// Convert the request body to an instance of the DTO class
|
||||
const validationClass = plainToInstance(DTO, req.body, {
|
||||
excludeExtraneousValues: true,
|
||||
});
|
||||
|
||||
// Validate the DTO instance, including nested objects
|
||||
const errors: ValidationError[] = await validate(validationClass, {
|
||||
whitelist: true,
|
||||
// forbidNonWhitelisted: true,
|
||||
// transform: true,
|
||||
});
|
||||
if (errors.length > 0) {
|
||||
const errorMsg = errors.map((error) => ValidationMiddleware.flattenValidationErrors(error)).flat();
|
||||
|
||||
next(new BadRequestError(errorMsg));
|
||||
// throw new BadRequestError("Bad Request", errorMsg);
|
||||
} else {
|
||||
req.body = validationClass;
|
||||
next();
|
||||
}
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static validateInput(DTO: ClassConstructor<any>): RequestHandler {
|
||||
return async (req: Request, _res: Response, next: NextFunction): Promise<void> => {
|
||||
try {
|
||||
|
||||
@@ -51,7 +51,7 @@ class SepGateway implements IGateway {
|
||||
RedirectUrl: `${this.callBackURL}${callBackPath}`,
|
||||
ResNum: Date.now().toString(),
|
||||
CellNumber: _mobile,
|
||||
GetMethod:true
|
||||
// GetMethod:true
|
||||
};
|
||||
|
||||
const response = await axios.post<SepRequestPaymentResponse>(requesturl, purchaseData, { headers: this.requestHeader });
|
||||
|
||||
@@ -111,7 +111,7 @@ class PaymentController extends BaseController {
|
||||
@ApiOperation("verify a payment for current session user for cartCheckout (method post for SEP)")
|
||||
@ApiResponse("successful", HttpStatus.Ok)
|
||||
@ApiParam("gateway", "the name of api gateway", true)
|
||||
@httpPost("/verify/:gateway/cart", ValidationMiddleware.validateInput(VerifyOnlinePaymentDTO))
|
||||
@httpPost("/verify/:gateway/cart", ValidationMiddleware.validateInputWithLogging(VerifyOnlinePaymentDTO, "Verify Cart Checkout"))
|
||||
public async VerifyCartCheckoutPost(
|
||||
@requestParam("gateway") gateway: string,
|
||||
@response() res: Response,
|
||||
|
||||
Reference in New Issue
Block a user