1 Commits

Author SHA1 Message Date
VivianDee 03478c8dbd Update rac_check.py 2025-06-12 15:24:38 +01:00
13 changed files with 63 additions and 242 deletions
+2 -31
View File
@@ -1,5 +1,4 @@
from flask import Flask, Blueprint, request, jsonify, send_from_directory from flask import Flask, Blueprint, request, jsonify, send_from_directory
import sys
import os import os
from app.api.services import ( from app.api.services import (
RACCheckService, RACCheckService,
@@ -17,7 +16,6 @@ from app.utils.logger import logger
from app.api.middlewares import require_api_key, require_app_id, enforce_json from app.api.middlewares import require_api_key, require_app_id, enforce_json
api = Blueprint("api", __name__) api = Blueprint("api", __name__)
@@ -164,34 +162,7 @@ def new_transaction_check():
response = NewTransactionCheckService.process_request(data) response = NewTransactionCheckService.process_request(data)
return response return response
# Health Check Endpoint # Health Check Endpoint
@api.route('/system-health-check', methods=['GET']) @api.route('/health', methods=['GET'])
def health_check(): def health_check():
"""Basic system health check""" return {"status": "ok"} , 200
try:
checks = {
"python_version": sys.version_info >= (3, 6),
"disk_space": os.statvfs('/').f_bavail * os.statvfs('/').f_frsize > 500 * 1024 * 1024,
"system_operational": True
}
if all(checks.values()):
return jsonify({
"status": "Active",
"responseCode": "00",
"responseMessage": "Successful"
}), 200
else:
return jsonify({
"status": "Degraded",
"responseCode": "01",
"responseMessage": "System check failed"
}), 200
except Exception as e:
return jsonify({
"status": "Error",
"responseCode": "99",
"responseMessage": f"Health check failed: {str(e)}"
}), 500
-8
View File
@@ -14,7 +14,6 @@ class DisbursementSchema(Schema):
collectAmountVAT = fields.Float(required=True) collectAmountVAT = fields.Float(required=True)
countryId = fields.Str(required=False, allow_none=True) countryId = fields.Str(required=False, allow_none=True)
comment = fields.Str(required=False, allow_none=True) comment = fields.Str(required=False, allow_none=True)
class DisburseLoanResponseSchema(Schema): class DisburseLoanResponseSchema(Schema):
@@ -32,12 +31,5 @@ class DisburseLoanResponseSchema(Schema):
countryId = fields.Str(allow_none=True) countryId = 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)
disburseMessage = fields.Str(allow_none=True)
disburseDate = fields.Str(allow_none=True)
disburseVerify = fields.Str(allow_none=True)
disburseDescription = fields.Str(allow_none=True)
verifyResult = fields.Str(allow_none=True)
verifyDescription = fields.Str(allow_none=True)
+1 -5
View File
@@ -18,8 +18,4 @@ class TransactionVerifyResponseSchema(Schema):
providedAmount = fields.Float(required=True) providedAmount = fields.Float(required=True)
collectedAmount = fields.Float(required=True) collectedAmount = fields.Float(required=True)
transactionId = fields.Str(allow_none=True) transactionId = fields.Str(allow_none=True)
transactionType = fields.Str(allow_none=True) transactionType = fields.Str(allow_none=True)
disburseVerify = fields.Str(allow_none=True)
verifyDescription = fields.Str(allow_none=True)
verifyResult = fields.Str(allow_none=True)
+21 -52
View File
@@ -2,20 +2,20 @@ 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.collect_loan import CollectLoanSchema, CollectLoanResponseSchema from app.api.schemas.collect_loan import CollectLoanSchema, CollectLoanResponseSchema
"""
Process the CollectLoan request.
Args:
data (dict): The request data.
Returns:
tuple: JSON response and status code.
"""
class CollectLoanService: class CollectLoanService:
@staticmethod @staticmethod
def process_request(data): def process_request(data):
"""
Process the CollectLoan request.
Args:
data (dict): The request data.
Returns:
tuple: JSON response and status code.
"""
try: try:
logger.info("Processing CollectLoan request") logger.info("Processing CollectLoan request")
@@ -23,53 +23,22 @@ class CollectLoanService:
schema = CollectLoanSchema() schema = CollectLoanSchema()
validated_data = schema.load(data) validated_data = schema.load(data)
amountForCollection = validated_data.get("collectAmount")
amountCollected = amountForCollection
responseDescr= "Loan Collection Successful EMULATOR"
fullDescription= "Loan collection completed successfully EMULATOR"
responseMessage= "Loan collection completed successfully EMULATOR"
if amountForCollection in [5555.0, 6666.0, 7777.0, 8888.0 , 9999.0, 22222.0] :
amountCollected = amountForCollection * 0.85
responseDescr = "Partial Loan Collection Successful EMULATOR"
fullDescription = "Partial Loan collection completed successfully EMULATOR"
responseMessage = "Partial Loan collection completed successfully EMULATOR"
# Simulated processing logic # Simulated processing logic
response_data = { response_data = {
"transactionId": validated_data.get("transactionId"), "transactionId": validated_data.get("transactionId", "T002"),
"debtId": validated_data.get("debtId"), "debtId": validated_data.get("debtId", "273194670"),
"customerId": validated_data.get("customerId"), "customerId": validated_data.get("customerId", "CN621868"),
"accountId": validated_data.get("accountId"), "accountId": validated_data.get("accountId", "2017821799"),
"productId": validated_data.get("productId"), "productId": validated_data.get("productId", "101"),
"amountCollected": amountCollected, "amountCollected": validated_data.get("collectAmount", 60000.00),
"countryId": validated_data.get("countryId"), "countryId": validated_data.get("countryId", "01"),
"comment": validated_data.get("comment", "Testing CollectionLoanRequest EMULATOR"), "comment": validated_data.get("comment", "Testing CollectionLoanRequest"),
"responseCode": "00", "responseCode": "00",
"responseDescr": responseDescr, "responseDescr": "Loan Collection Successful",
"fullDescription": fullDescription, "fullDescription": "Loan collection completed successfully",
"responseMessage": responseMessage "responseMessage": "Loan collection completed successfully"
} }
# # Simulated processing logic
# response_data = {
# "transactionId": validated_data.get("transactionId", "T002"),
# "debtId": validated_data.get("debtId", "273194670"),
# "customerId": validated_data.get("customerId", "CN621868"),
# "accountId": validated_data.get("accountId", "2017821799"),
# "productId": validated_data.get("productId", "101"),
# "amountCollected": validated_data.get("collectAmount", 60000.00),
# "countryId": validated_data.get("countryId", "01"),
# "comment": validated_data.get("comment", "Testing CollectionLoanRequest"),
# "responseCode": "00",
# "responseDescr": "Loan Collection Successful",
# "fullDescription": "Loan collection completed successfully",
# "responseMessage": "Loan collection completed successfully"
# }
#
# Validate and serialize the response data # Validate and serialize the response data
response_schema = CollectLoanResponseSchema() response_schema = CollectLoanResponseSchema()
result = response_schema.dump(response_data) result = response_schema.dump(response_data)
+2 -6
View File
@@ -2,7 +2,6 @@ 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.schemas.disbursement import DisbursementSchema, DisburseLoanResponseSchema from app.api.schemas.disbursement import DisbursementSchema, DisburseLoanResponseSchema
import datetime
class DisbursementService: class DisbursementService:
@staticmethod @staticmethod
@@ -27,7 +26,7 @@ class DisbursementService:
# For demo purposes, we simulate a response using the validated data # For demo purposes, we simulate a response using the validated data
response_data = { response_data = {
"transactionId": validated_data.get("transactionId"), "transactionId": validated_data.get("transactionId"),
"fbnTransactionId": validated_data.get("fbnTransactionId"), # Example or generated value "FbnTransactionId": validated_data.get("FbnTransactionId"), # Example or generated value
"debtId": validated_data.get("debtId"), "debtId": validated_data.get("debtId"),
"customerId": validated_data.get("customerId"), "customerId": validated_data.get("customerId"),
"accountId": validated_data.get("accountId"), "accountId": validated_data.get("accountId"),
@@ -39,10 +38,7 @@ class DisbursementService:
"collectAmountVAT": validated_data.get("collectAmountVAT"), "collectAmountVAT": validated_data.get("collectAmountVAT"),
"countryId": validated_data.get("countryId"), "countryId": validated_data.get("countryId"),
"responseCode": "00", # success code example "responseCode": "00", # success code example
"responseMessage": "Loan Request Completed Successfully!", "responseMessage": "Loan Request Completed Successfully!"
"disburseDate": datetime.datetime.now().isoformat(),
"disburseResult": "00",
"disburseDescription": "Loan Request Completed Successfully!",
} }
# Serialize response # Serialize response
+36 -49
View File
@@ -25,66 +25,53 @@ class RACCheckService:
schema = RACCheckSchema() schema = RACCheckSchema()
validated_data = schema.load(data) validated_data = schema.load(data)
customer_id = validated_data["customerId"] # Simulated RAC check logic — create racResponse manually or via logic
is_valid = not ( # rac_response = {
int(customer_id[-1]) in [2, 7, 9] # "hasSalaryAccount": True,
) # "bvnValidated": True,
# "creditBureauCheck": False,
# "crmsCheck": True,
try: # "accountStatus": True,
salary_count = int(str(customer_id)[-1]) + 1 # "hasLien": False,
if salary_count < 1 or salary_count > 6: # "noBouncedCheck": True,
salary_count = 3 # "isWhitelisted": True,
except ValueError: # "hasPastDueLoan": False
salary_count = 3 # }
salary_payments = {}
total_salary = 0
for i in range(1, salary_count + 1):
salary = ((salary_count + i ) * 7919) % 200000 + 10000
salary_payments[f"salarypaymenT_{i}"] = salary
total_salary += salary
average_salary = total_salary // salary_count if salary_count > 0 else 0
rac_response = { rac_response = {
"procesS_DATE": datetime.strptime("2025-06-05", "%Y-%m-%d").date(), "procesS_DATE": datetime.strptime("2025-06-05", "%Y-%m-%d").date(),
"ciF_ID": "416405737", "ciF_ID": "416405737",
"customeR_id": customer_id, "customeR_id": "7032744",
"salaccT_1": "4142904114", "salaccT_1": "4142904114",
"alerT_PHONE": "2348039301606", "alerT_PHONE": "2348039301606",
"averagE_SALARY": average_salary, "averagE_SALARY": 5000,
"loaN_OUSTANDING_BAL": 0, "loaN_OUSTANDING_BAL": 0,
"emi": 1000, "emi": 1000,
"eliG_AMT": 25000, "eliG_AMT": 25000,
"rule1_45day_sal": is_valid, "rule1_45day_sal": True,
"rule2_2m_sal": is_valid, "rule2_2m_sal": True,
"rule3_no_bounced_check": is_valid, "rule3_no_bounced_check": True,
"rule4_current_loan_payments": True if is_valid is False else is_valid, "rule4_current_loan_payments": True,
"rule5_no_past_due_fadv_loan": is_valid, "rule5_no_past_due_fadv_loan": True,
"rule6_no_past_due_other_loan": is_valid, "rule6_no_past_due_other_loan": True,
"rule7_consistent_salary_amount": is_valid, "rule7_consistent_salary_amount": True,
"rule8_whitelisted": True if is_valid is False else is_valid, "rule8_whitelisted": True,
"rule9_regular_account": True if is_valid is False else is_valid, "rule9_regular_account": True,
"rule10_bvn_validation": is_valid, "rule10_bvn_validation": True,
"rule11_CRC_no_delinquency": is_valid, "rule11_CRC_no_delinquency": True,
"rule12_CRMS_no_delinquency": True if is_valid is False else is_valid, "rule12_CRMS_no_delinquency": True,
"rule13_BVN_ignore": is_valid, "rule13_BVN_ignore": True,
"rule14_no_lien": is_valid, "rule14_no_lien": True,
"rule15_null_ignore": True if is_valid is False else is_valid, "rule15_null_ignore": True,
"overalL_ELIG": is_valid "overalL_ELIG": True,
# "salarypaymenT_1": 180000, "salarypaymenT_1": 180000,
# "salarypaymenT_2": 50000, "salarypaymenT_2": 50000,
# "salarypaymenT_3": 70000, "salarypaymenT_3": 70000,
# "salarypaymenT_4": 0, "salarypaymenT_4": 0,
# "salarypaymenT_5": 0, "salarypaymenT_5": 0,
# "salarypaymenT_6": 0 "salarypaymenT_6": 0
} }
rac_response.update(salary_payments)
full_response = { full_response = {
"transactionId": validated_data["transactionId"], "transactionId": validated_data["transactionId"],
+1 -5
View File
@@ -6,7 +6,6 @@ from app.api.schemas.transaction_verify import (
TransactionVerifySchema, TransactionVerifySchema,
TransactionVerifyResponseSchema TransactionVerifyResponseSchema
) )
import datetime
class TransactionVerifyService: class TransactionVerifyService:
@@ -38,10 +37,7 @@ class TransactionVerifyService:
"providedAmount": 0.0, "providedAmount": 0.0,
"collectedAmount": 7.50, "collectedAmount": 7.50,
"transactionId": validated_data.get("transactionId"), "transactionId": validated_data.get("transactionId"),
"transactionType": validated_data.get("transactionType"), "transactionType": validated_data.get("transactionType")
"disburseVerify": datetime.datetime.now().isoformat(),
"verifyResult": "00",
"verifyDescription": "Collect Status retrieved successfully.",
} }
# Validate and serialize response with TransactionVerifyResponseSchema # Validate and serialize response with TransactionVerifyResponseSchema
-3
View File
@@ -110,9 +110,6 @@
} }
], ],
"paths": { "paths": {
"/api/system-health-check": {
"$ref": "swagger/paths/HealthCheck.json"
},
"/api/rac-check": { "/api/rac-check": {
"$ref": "swagger/paths/RACCheck.json" "$ref": "swagger/paths/RACCheck.json"
}, },
-19
View File
@@ -1,19 +0,0 @@
{
"get": {
"tags": ["System"],
"summary": "System Health Check",
"description": "Returns the current health status of the system",
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "../schemas/HealthCheckResponse.json"
}
}
}
}
}
}
}
@@ -70,22 +70,6 @@
"type": "string", "type": "string",
"example": "Loan Request Completed Successfully!", "example": "Loan Request Completed Successfully!",
"nullable": true "nullable": true
},
"disburseDate": {
"type": "string",
"format": "date-time",
"example": "2023-10-01T12:00:00Z",
"nullable": true
},
"disburseResult": {
"type": "string",
"example": "00",
"nullable": true
},
"disburseDescription": {
"type": "string",
"example": "Loan Request Completed Successfully!",
"nullable": true
} }
}, },
"required": [ "required": [
@@ -1,17 +0,0 @@
{
"type": "object",
"properties": {
"status": {
"type": "string",
"example": "Active"
},
"responseCode": {
"type": "string",
"example": "00"
},
"responseMessage": {
"type": "string",
"example": "Successful"
}
}
}
@@ -1,17 +0,0 @@
{
"type": "object",
"properties": {
"status": {
"type": "string",
"example": "Active"
},
"responseCode": {
"type": "string",
"example": "00"
},
"responseMessage": {
"type": "string",
"example": "Successful"
}
}
}
@@ -38,20 +38,6 @@
"transactionType": { "transactionType": {
"type": "string", "type": "string",
"example": "Disbursement" "example": "Disbursement"
},
"disburseVerify":{
"type": "string",
"format": "date-time",
"example": "2023-10-01T12:00:00Z",
"nullable": true
},
"verifyResult": {
"type": "string",
"example": "Success"
},
"verifyDescription": {
"type": "string",
"example": "Disbursement was verified and collection completed."
} }
}, },
"required": [ "required": [