Updated Disbursement
This commit is contained in:
@@ -7,3 +7,5 @@ from app.api.services.revoke_enable_consent import RevokeEnableConsentService
|
||||
from app.api.services.token_validation import TokenValidationService
|
||||
from app.api.services.lien_check import LienCheckService
|
||||
from app.api.services.new_transaction_check import NewTransactionCheckService
|
||||
from app.api.services.repayment import RepaymentService
|
||||
from app.api.services.status_call import StatusCallService
|
||||
@@ -1,8 +1,7 @@
|
||||
from flask import request, jsonify
|
||||
from marshmallow import ValidationError
|
||||
from app.utils.logger import logger
|
||||
from app.api.helpers.response_helper import ResponseHelper
|
||||
from app.api.schemas.disbursement import DisbursementSchema
|
||||
from app.api.schemas.disbursement import DisbursementSchema, DisbursementResponseSchema
|
||||
|
||||
class DisbursementService:
|
||||
@staticmethod
|
||||
@@ -23,40 +22,47 @@ class DisbursementService:
|
||||
schema = DisbursementSchema()
|
||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||
|
||||
# Extract fees details for easier access
|
||||
fees_details = validated_data.get('feesDetails', {})
|
||||
|
||||
# Simulated processing logic
|
||||
# In a real implementation, this would interact with your business logic
|
||||
response_data = {
|
||||
"transactionId": "T001",
|
||||
"TransactionId": "Tr201712RK9232P115",
|
||||
"debtId": "273194670",
|
||||
"customerId": "CN621868",
|
||||
"accountId": "2017821799",
|
||||
"productId": "101",
|
||||
"provideAmount": 100000.0,
|
||||
"collectAmountInterest": 5000,
|
||||
"collectAmountMgtFee": 1000,
|
||||
"collectAmountInsurance": 1000,
|
||||
"collectAmountVAT": 75,
|
||||
"countryId": "01",
|
||||
"requestId": validated_data.get('requestId'),
|
||||
"countryCode": validated_data.get('countryCode'),
|
||||
"transactionId": validated_data.get('transactionId'),
|
||||
"debtId": validated_data.get('debtId'),
|
||||
"customerId": validated_data.get('customerId'),
|
||||
"accountId": validated_data.get('accountId'),
|
||||
"productId": validated_data.get('productId'),
|
||||
"provideAmount": validated_data.get('provideAmount'),
|
||||
"totalFees": validated_data.get('totalFees'),
|
||||
"feesDetails": {
|
||||
"collectAmountInterest": fees_details.get('collectAmountInterest'),
|
||||
"collectAmountMgtFee": fees_details.get('collectAmountMgtFee'),
|
||||
"collectAmountInsurance": fees_details.get('collectAmountInsurance'),
|
||||
"collectAmountVAT": fees_details.get('collectAmountVAT')
|
||||
},
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Request Completed Successfully!"
|
||||
}
|
||||
|
||||
# Validate the response using the response schema
|
||||
response_schema = DisbursementResponseSchema()
|
||||
validated_response = response_schema.dump(response_data)
|
||||
|
||||
# return ResponseHelper.success(
|
||||
# data=response_data,
|
||||
# message="Disbursement completed successfully"
|
||||
# )
|
||||
|
||||
return response_data
|
||||
return jsonify(validated_response)
|
||||
|
||||
except ValidationError as err:
|
||||
logger.error(f"Validation Error: {err.messages}")
|
||||
return jsonify({
|
||||
"message": "Validation exception"
|
||||
}) , 422
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Validation error: {err.messages}"
|
||||
}), 422
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"An error occurred: {str(e)}", exc_info=True)
|
||||
return jsonify({
|
||||
"message": "Internal Server Error"
|
||||
}) , 500
|
||||
"resultCode": "08",
|
||||
"resultDescription": f"Error occurred: {str(e)}"
|
||||
}), 500
|
||||
@@ -0,0 +1,64 @@
|
||||
from flask import jsonify
|
||||
from app.utils.logger import logger
|
||||
|
||||
|
||||
class RepaymentService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process a repayment request from Simbrella to FirstBank
|
||||
|
||||
Args:
|
||||
data (dict): The request data containing repayment details
|
||||
|
||||
Returns:
|
||||
flask.Response: JSON response with the result of the repayment operation
|
||||
"""
|
||||
try:
|
||||
# Log the incoming request
|
||||
logger.info(f"Processing repayment request: {data}")
|
||||
|
||||
# Validate required fields
|
||||
required_fields = [
|
||||
"requestId", "countryCode", "transactionId", "debtId",
|
||||
"customerId", "accountId", "productId", "collectAmount",
|
||||
"collectionMethod", "lienAmount"
|
||||
]
|
||||
|
||||
for field in required_fields:
|
||||
if field not in data:
|
||||
logger.error(f"Missing required field: {field}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Missing required field: {field}"
|
||||
}), 400
|
||||
|
||||
# Process the repayment request
|
||||
# This is where you would implement the actual business logic
|
||||
# For now, we'll just return a successful response
|
||||
|
||||
response = {
|
||||
"requestId": data.get("requestId"),
|
||||
"countryCode": data.get("countryCode"),
|
||||
"transactionId": data.get("transactionId"),
|
||||
"debtId": data.get("debtId"),
|
||||
"customerId": data.get("customerId"),
|
||||
"accountId": data.get("accountId"),
|
||||
"productId": data.get("productId"),
|
||||
"collectAmount": data.get("collectAmount"),
|
||||
"penalCharge": data.get("penalCharge", 0),
|
||||
"lienAmount": data.get("lienAmount"),
|
||||
"comment": data.get("comment", ""),
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Collection Successful"
|
||||
}
|
||||
|
||||
logger.info(f"Repayment response: {response}")
|
||||
return jsonify(response)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing repayment request: {str(e)}")
|
||||
return jsonify({
|
||||
"resultCode": "08",
|
||||
"resultDescription": "Error occurred"
|
||||
}), 500
|
||||
@@ -0,0 +1,84 @@
|
||||
from flask import jsonify
|
||||
from app.utils.logger import logger
|
||||
|
||||
|
||||
class StatusCallService:
|
||||
@staticmethod
|
||||
def process_request(data):
|
||||
"""
|
||||
Process a status call request to check transaction status
|
||||
|
||||
Args:
|
||||
data (dict): The request data containing transaction details to check
|
||||
|
||||
Returns:
|
||||
flask.Response: JSON response with the status of the transaction
|
||||
"""
|
||||
try:
|
||||
# Log the incoming request
|
||||
logger.info(f"Processing status call request: {data}")
|
||||
|
||||
# Validate required fields
|
||||
required_fields = [
|
||||
"transactionId", "transactionType", "customerId"
|
||||
]
|
||||
|
||||
for field in required_fields:
|
||||
if field not in data:
|
||||
logger.error(f"Missing required field: {field}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Missing required field: {field}"
|
||||
}), 400
|
||||
|
||||
# Process the status call request based on transaction type
|
||||
transaction_type = data.get("transactionType")
|
||||
|
||||
# Prepare the response based on transaction type
|
||||
if transaction_type == "Disbursement":
|
||||
status = {
|
||||
"providedAmount": 1000.00,
|
||||
"collectedAmount": 0.00,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Provision is successful"
|
||||
}
|
||||
elif transaction_type == "Collection":
|
||||
status = {
|
||||
"providedAmount": 0.00,
|
||||
"collectedAmount": 100.00,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Loan Collection is successful"
|
||||
}
|
||||
elif transaction_type == "PenalCharge":
|
||||
status = {
|
||||
"transactionId": data.get("transactionId"),
|
||||
"providedAmount": 0.00,
|
||||
"collectedAmount": 100.00,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "Penal Charge is successful"
|
||||
}
|
||||
else:
|
||||
logger.error(f"Invalid transaction type: {transaction_type}")
|
||||
return jsonify({
|
||||
"resultCode": "01",
|
||||
"resultDescription": f"Invalid transaction type: {transaction_type}"
|
||||
}), 400
|
||||
|
||||
response = {
|
||||
"requestId": data.get("requestId", ""),
|
||||
"countryCode": data.get("countryCode", "NGR"),
|
||||
"transactionId": data.get("transactionId"),
|
||||
"Status": status,
|
||||
"resultCode": "00",
|
||||
"resultDescription": "SUCCESS"
|
||||
}
|
||||
|
||||
logger.info(f"Status call response: {response}")
|
||||
return jsonify(response)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing status call request: {str(e)}")
|
||||
return jsonify({
|
||||
"resultCode": "08",
|
||||
"resultDescription": "Error occurred"
|
||||
}), 500
|
||||
Reference in New Issue
Block a user