5 Commits

5 changed files with 44 additions and 31 deletions
+3 -4
View File
@@ -125,17 +125,16 @@ def transaction_verify():
logger.exception("Unhandled exception in /TransactionVerify route") logger.exception("Unhandled exception in /TransactionVerify route")
return jsonify({"message": "Unhandled server error"}), 500 return jsonify({"message": "Unhandled server error"}), 500
# PenalCharge Endpoint # CollectPenalCharge Endpoint
@api.route('/CollectPenalFee', methods=['POST']) @api.route('/CollectPenalCharge', methods=['POST'])
@jwt_required() @jwt_required()
def penal_charge(): def penal_charge():
try: try:
data = request.get_json() data = request.get_json()
# logger.info(f"PenalCharge request received: {data}")
response = PenalChargeService.process_request(data) response = PenalChargeService.process_request(data)
return response return response
except Exception as e: except Exception as e:
logger.exception("Unhandled exception in /PenalCharge route") logger.exception("Unhandled exception in /CollectPenalCharge route")
return jsonify({"message": "Unhandled server error"}), 500 return jsonify({"message": "Unhandled server error"}), 500
+11 -10
View File
@@ -2,22 +2,23 @@ from marshmallow import Schema, fields
# This file contains the schema for penal charge operations # This file contains the schema for penal charge operations
class PenalChargeSchema(Schema): class PenalChargeSchema(Schema):
channel = fields.Str(allow_none=True) channel = fields.Str(required=True)
transactionId = fields.Str(allow_none=True) transactionId = fields.Str(required=True)
fbnTransactionId = fields.Str(allow_none=True) fbnTransactionId = fields.Str(required=True)
debtId = fields.Str(allow_none=True) debtId = fields.Str(required=True)
accountId = fields.Str(allow_none=True) accountId = fields.Str(required=True)
penalCharge = fields.Float(required=True) penalCharge = fields.Int(required=True)
customerId = fields.Str(allow_none=True) customerId = fields.Str(required=True)
lienAmount = fields.Float(required=True) lienAmount = fields.Int(required=True)
comment = fields.Str(allow_none=True) comment = fields.Str(required=True)
countryId = fields.Str(allow_none=True) countryId = fields.Str(required=True)
#represents the response schema for penal charge #represents the response schema for penal charge
class CollectPenalFeeResponseSchema(Schema): class CollectPenalFeeResponseSchema(Schema):
customerId = fields.Str(allow_none=True) customerId = fields.Str(allow_none=True)
transactionId = fields.Str(allow_none=True) transactionId = fields.Str(allow_none=True)
amountCollected = fields.Float(required=True) amountCollected = fields.Float(required=True)
lienAmount = fields.Int(allow_none=True)
accountId = fields.Str(allow_none=True) accountId = fields.Str(allow_none=True)
responseCode = fields.Str(allow_none=True) responseCode = fields.Str(allow_none=True)
responseMessage = fields.Str(allow_none=True) responseMessage = fields.Str(allow_none=True)
+21 -14
View File
@@ -2,7 +2,10 @@ from flask import request, jsonify
from marshmallow import ValidationError from marshmallow import ValidationError
from app.utils.logger import logger from app.utils.logger import logger
from app.api.helpers.response_helper import ResponseHelper from app.api.helpers.response_helper import ResponseHelper
from app.api.schemas.penal_charge import PenalChargeSchema, CollectPenalFeeResponseSchema from app.api.schemas.penal_charge import (
PenalChargeSchema,
CollectPenalFeeResponseSchema,
)
class PenalChargeService: class PenalChargeService:
@@ -24,14 +27,20 @@ class PenalChargeService:
schema = PenalChargeSchema() schema = PenalChargeSchema()
validated_data = schema.load(data) validated_data = schema.load(data)
# Simulated processing logic customerId = validated_data["customerId"]
transactionId = validated_data["transactionId"]
penalCharge = validated_data["penalCharge"]
accountId = validated_data["accountId"]
lienAmount = validated_data["lienAmount"]
response_data = { response_data = {
"customerId": validated_data.get("customerId"),
"transactionId": validated_data.get("transactionId"),
"amountCollected": validated_data.get("penalCharge", 0.0),
"accountId": validated_data.get("accountId"),
"responseCode": "00", "responseCode": "00",
"responseMessage": "Penal charge debited successfully" "responseMessage": "Penal Collection Successful",
"customerId": customerId,
"transactionId": transactionId,
"amountCollected": penalCharge,
"lienAmount": lienAmount,
"accountId": accountId,
} }
# Optionally validate/serialize response using schema # Optionally validate/serialize response using schema
@@ -42,13 +51,11 @@ class PenalChargeService:
except ValidationError as err: except ValidationError as err:
logger.error(f"Validation Error: {err.messages}") logger.error(f"Validation Error: {err.messages}")
return jsonify({ return (
"message": "Validation exception", jsonify({"message": "Validation exception", "errors": err.messages}),
"errors": err.messages 422,
}), 422 )
except Exception as e: except Exception as e:
logger.error(f"An error occurred: {str(e)}", exc_info=True) logger.error(f"An error occurred: {str(e)}", exc_info=True)
return jsonify({ return jsonify({"message": "Internal Server Error"}), 500
"message": "Internal Server Error"
}), 500
+1 -1
View File
@@ -151,7 +151,7 @@
"/api/TransactionVerify": { "/api/TransactionVerify": {
"$ref": "swagger/paths/TransactionVerify.json" "$ref": "swagger/paths/TransactionVerify.json"
}, },
"/api/CollectPenalFee": { "/api/CollectPenalCharge": {
"$ref": "swagger/paths/PenalCharge.json" "$ref": "swagger/paths/PenalCharge.json"
}, },
"/api/RevokeEnableConsent": { "/api/RevokeEnableConsent": {
+8 -2
View File
@@ -16,6 +16,10 @@
"format": "double", "format": "double",
"example": 101.2 "example": 101.2
}, },
"lienAmount": {
"type": "integer",
"example": 1000
},
"accountId": { "accountId": {
"type": "string", "type": "string",
"nullable": true, "nullable": true,
@@ -32,6 +36,8 @@
"example": "Penal charge debited successfully" "example": "Penal charge debited successfully"
} }
}, },
"required": ["amountCollected"], "required": [
"amountCollected"
],
"additionalProperties": false "additionalProperties": false
} }