Updated Disbursement
This commit is contained in:
Generated
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
<module type="WEB_MODULE" version="4">
|
<module type="WEB_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$" />
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="jdk" jdkName="Python 3.13" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.13" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
from flask import Flask, Blueprint, request, jsonify, send_from_directory
|
from flask import Flask, Blueprint, request, jsonify, send_from_directory
|
||||||
import os
|
import os
|
||||||
from app.api.services import (
|
from app.api.services import (
|
||||||
RACCheckService,
|
RACCheckService,
|
||||||
@@ -10,6 +10,8 @@ from app.api.services import (
|
|||||||
TokenValidationService,
|
TokenValidationService,
|
||||||
LienCheckService,
|
LienCheckService,
|
||||||
NewTransactionCheckService,
|
NewTransactionCheckService,
|
||||||
|
RepaymentService, # Added RepaymentService
|
||||||
|
StatusCallService, # Added StatusCallService
|
||||||
)
|
)
|
||||||
from app.utils.logger import logger
|
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
|
||||||
@@ -32,7 +34,6 @@ def swagger_json():
|
|||||||
return send_from_directory(swagger_dir, "digifi_swagger.json")
|
return send_from_directory(swagger_dir, "digifi_swagger.json")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@api.route('/swagger/<path:filename>')
|
@api.route('/swagger/<path:filename>')
|
||||||
def serve_paths(filename):
|
def serve_paths(filename):
|
||||||
swagger_dir = os.path.join("swagger")
|
swagger_dir = os.path.join("swagger")
|
||||||
@@ -53,7 +54,6 @@ def rac_check():
|
|||||||
@require_api_key
|
@require_api_key
|
||||||
@require_app_id
|
@require_app_id
|
||||||
def disbursement():
|
def disbursement():
|
||||||
|
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
# logger.info(f"Disbursement request received: {data}")
|
# logger.info(f"Disbursement request received: {data}")
|
||||||
response = DisbursementService.process_request(data)
|
response = DisbursementService.process_request(data)
|
||||||
@@ -129,7 +129,27 @@ def new_transaction_check():
|
|||||||
response = NewTransactionCheckService.process_request(data)
|
response = NewTransactionCheckService.process_request(data)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
# Repayment Endpoint - Added based on updated Repayment.json
|
||||||
|
@api.route('/Repayment', methods=['POST'])
|
||||||
|
@require_api_key
|
||||||
|
@require_app_id
|
||||||
|
def repayment():
|
||||||
|
data = request.get_json()
|
||||||
|
# logger.info(f"Repayment request received: {data}")
|
||||||
|
response = RepaymentService.process_request(data)
|
||||||
|
return response
|
||||||
|
|
||||||
|
# StatusCall Endpoint - Added based on updated StatusCall.json
|
||||||
|
@api.route('/StatusCall', methods=['POST'])
|
||||||
|
@require_api_key
|
||||||
|
@require_app_id
|
||||||
|
def status_call():
|
||||||
|
data = request.get_json()
|
||||||
|
# logger.info(f"StatusCall request received: {data}")
|
||||||
|
response = StatusCallService.process_request(data)
|
||||||
|
return response
|
||||||
|
|
||||||
# Health Check Endpoint
|
# Health Check Endpoint
|
||||||
@api.route('/health', methods=['GET'])
|
@api.route('/health', methods=['GET'])
|
||||||
def health_check():
|
def health_check():
|
||||||
return {"status": "ok"} , 200
|
return {"status": "ok"}, 200
|
||||||
@@ -1,17 +1,38 @@
|
|||||||
from marshmallow import Schema, fields
|
from marshmallow import Schema, fields, validate
|
||||||
|
|
||||||
# Disbursement Schema
|
# Schema for the fees details object
|
||||||
|
class FeesDetailsSchema(Schema):
|
||||||
|
collectAmountInterest = fields.Float(required=True, description="Interest Amount to be collected immediately after loan is provided (Only for 30 days)")
|
||||||
|
collectAmountMgtFee = fields.Float(required=True, description="Management Fee Amount to be collected immediately after loan is provided")
|
||||||
|
collectAmountInsurance = fields.Float(required=True, description="Insurance Amount to be collected immediately after loan is provided")
|
||||||
|
collectAmountVAT = fields.Float(required=True, description="VAT Amount to be collected immediately after loan is provided")
|
||||||
|
|
||||||
|
# Disbursement Request Schema
|
||||||
class DisbursementSchema(Schema):
|
class DisbursementSchema(Schema):
|
||||||
requestId = fields.Str(required=True)
|
requestId = fields.Str(required=True, description="Unique identifier of request")
|
||||||
debtId = fields.Str(required=True)
|
countryCode = fields.Str(required=True, description="Unique country code. Please refer to Country Codes table")
|
||||||
transactionId = fields.Str(required=True)
|
transactionId = fields.Str(required=True, description="Unique identifier of transaction in Simbrella system")
|
||||||
customerId = fields.Str(required=True)
|
debtId = fields.Str(required=True, description="Unique identifier of a loan in Simbrella system that is going to be collected (it correlates with provision request)")
|
||||||
accountId = fields.Str(required=True)
|
customerId = fields.Str(required=True, description="Unique identifier of a user")
|
||||||
productId = fields.Str(required=True)
|
accountId = fields.Str(required=True, description="Specific identifier of a user's account")
|
||||||
provideAmount = fields.Float(required=True)
|
productId = fields.Str(required=True, description="Identifier of a product to be provided to a user")
|
||||||
collectAmountInterest = fields.Float(required=False) # Optional
|
provideAmount = fields.Float(required=True, description="Amount of loan (including service fee) to be provided on a specific account of a user")
|
||||||
collectAmountMgtFee = fields.Float(required=True)
|
totalFees = fields.Float(required=True, description="Total amount of all fees combined")
|
||||||
collectAmountInsurance = fields.Float(required=True)
|
feesDetails = fields.Nested(FeesDetailsSchema, required=True, description="Detailed breakdown of all fees")
|
||||||
collectAmountVAT = fields.Float(required=True)
|
countryId = fields.Str(required=True, description="Set to static value '01'")
|
||||||
countryId = fields.Str(required=True)
|
comment = fields.Str(required=False, description="Any additional comment for provided loan operation")
|
||||||
comment = fields.Str(required=False) # Optional
|
|
||||||
|
# Disbursement Response Schema
|
||||||
|
class DisbursementResponseSchema(Schema):
|
||||||
|
requestId = fields.Str(required=True, description="Unique identifier of request")
|
||||||
|
countryCode = fields.Str(required=True, description="Unique country code.")
|
||||||
|
transactionId = fields.Str(required=True, description="Unique ID of customer's USSD session. Must be consistent throughout whole USSD journey")
|
||||||
|
debtId = fields.Str(required=True, description="Unique identifier of a loan in Simbrella system that is going to be collected (it correlates with provision request)")
|
||||||
|
customerId = fields.Str(required=True, description="Unique identifier of a user")
|
||||||
|
accountId = fields.Str(required=True, description="Specific identifier of a user's account")
|
||||||
|
productId = fields.Str(required=True, description="Identifier of a product to be provided to a user")
|
||||||
|
provideAmount = fields.Float(required=True, description="Amount of loan (including service fee) to be provided on a specific account of a user")
|
||||||
|
totalFees = fields.Float(required=True, description="Total amount of all fees combined")
|
||||||
|
feesDetails = fields.Nested(FeesDetailsSchema, required=True, description="Detailed breakdown of all fees")
|
||||||
|
resultCode = fields.Str(required=True, description="Result code of executed transaction, e.g. (00 – Success etc.) see result codes table")
|
||||||
|
resultDescription = fields.Str(required=True, description="Description of provided result code")
|
||||||
@@ -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.token_validation import TokenValidationService
|
||||||
from app.api.services.lien_check import LienCheckService
|
from app.api.services.lien_check import LienCheckService
|
||||||
from app.api.services.new_transaction_check import NewTransactionCheckService
|
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 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.schemas.disbursement import DisbursementSchema, DisbursementResponseSchema
|
||||||
from app.api.schemas.disbursement import DisbursementSchema
|
|
||||||
|
|
||||||
class DisbursementService:
|
class DisbursementService:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -23,40 +22,47 @@ class DisbursementService:
|
|||||||
schema = DisbursementSchema()
|
schema = DisbursementSchema()
|
||||||
validated_data = schema.load(data) # Raises ValidationError if invalid
|
validated_data = schema.load(data) # Raises ValidationError if invalid
|
||||||
|
|
||||||
|
# Extract fees details for easier access
|
||||||
|
fees_details = validated_data.get('feesDetails', {})
|
||||||
|
|
||||||
# Simulated processing logic
|
# Simulated processing logic
|
||||||
|
# In a real implementation, this would interact with your business logic
|
||||||
response_data = {
|
response_data = {
|
||||||
"transactionId": "T001",
|
"requestId": validated_data.get('requestId'),
|
||||||
"TransactionId": "Tr201712RK9232P115",
|
"countryCode": validated_data.get('countryCode'),
|
||||||
"debtId": "273194670",
|
"transactionId": validated_data.get('transactionId'),
|
||||||
"customerId": "CN621868",
|
"debtId": validated_data.get('debtId'),
|
||||||
"accountId": "2017821799",
|
"customerId": validated_data.get('customerId'),
|
||||||
"productId": "101",
|
"accountId": validated_data.get('accountId'),
|
||||||
"provideAmount": 100000.0,
|
"productId": validated_data.get('productId'),
|
||||||
"collectAmountInterest": 5000,
|
"provideAmount": validated_data.get('provideAmount'),
|
||||||
"collectAmountMgtFee": 1000,
|
"totalFees": validated_data.get('totalFees'),
|
||||||
"collectAmountInsurance": 1000,
|
"feesDetails": {
|
||||||
"collectAmountVAT": 75,
|
"collectAmountInterest": fees_details.get('collectAmountInterest'),
|
||||||
"countryId": "01",
|
"collectAmountMgtFee": fees_details.get('collectAmountMgtFee'),
|
||||||
|
"collectAmountInsurance": fees_details.get('collectAmountInsurance'),
|
||||||
|
"collectAmountVAT": fees_details.get('collectAmountVAT')
|
||||||
|
},
|
||||||
"resultCode": "00",
|
"resultCode": "00",
|
||||||
"resultDescription": "Loan Request Completed Successfully!"
|
"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(
|
return jsonify(validated_response)
|
||||||
# data=response_data,
|
|
||||||
# message="Disbursement completed successfully"
|
|
||||||
# )
|
|
||||||
|
|
||||||
return response_data
|
|
||||||
|
|
||||||
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 jsonify({
|
||||||
"message": "Validation exception"
|
"resultCode": "01",
|
||||||
}) , 422
|
"resultDescription": f"Validation error: {err.messages}"
|
||||||
|
}), 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"
|
"resultCode": "08",
|
||||||
}) , 500
|
"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