Initial commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
"""
|
||||
Controller for loan disbursement endpoints.
|
||||
"""
|
||||
from flask import Blueprint, request, jsonify
|
||||
from api.middleware import api_key_required
|
||||
from api.models import DisbursementRequest, DisbursementResponse
|
||||
import logging
|
||||
|
||||
# Configure logger
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Create blueprint
|
||||
disbursement_bp = Blueprint('disbursement', __name__)
|
||||
|
||||
@disbursement_bp.route('/Disbursement', methods=['POST'])
|
||||
@api_key_required
|
||||
def disbursement():
|
||||
"""
|
||||
Endpoint to process loan disbursement requests from Simbrella.
|
||||
|
||||
This method handles requests to disburse loans to customer accounts.
|
||||
The operation should be executed atomically, providing the loan and
|
||||
collecting upfront fees within the same transaction.
|
||||
|
||||
Returns:
|
||||
JSON response with disbursement status
|
||||
"""
|
||||
try:
|
||||
# Parse and validate request
|
||||
data = request.get_json()
|
||||
if not data:
|
||||
return jsonify({
|
||||
'resultCode': '400',
|
||||
'resultDescription': 'Invalid JSON payload'
|
||||
}), 400
|
||||
|
||||
# Validate required fields
|
||||
required_fields = ['requestId', 'debtId', 'transactionId', 'customerId',
|
||||
'accountId', 'productId', 'provideAmount', 'countryId']
|
||||
for field in required_fields:
|
||||
if field not in data:
|
||||
return jsonify({
|
||||
'resultCode': '422',
|
||||
'resultDescription': f'Missing required field: {field}'
|
||||
}), 422
|
||||
|
||||
# Create request model
|
||||
req = DisbursementRequest.from_dict(data)
|
||||
|
||||
# Process disbursement request (this would connect to the business logic)
|
||||
# For demonstration, we'll return a mock response
|
||||
|
||||
# Create response
|
||||
response = DisbursementResponse(
|
||||
requestId=req.requestId,
|
||||
debtId=req.debtId,
|
||||
transactionId=req.transactionId,
|
||||
customerId=req.customerId,
|
||||
accountId=req.accountId,
|
||||
productId=req.productId,
|
||||
provideAmount=req.provideAmount,
|
||||
resultCode="00",
|
||||
resultDescription="Loan Request Completed Successfully!",
|
||||
collectAmountInterest=req.collectAmountInterest,
|
||||
collectAmountMgtFee=req.collectAmountMgtFee,
|
||||
collectAmountInsurance=req.collectAmountInsurance,
|
||||
collectAmountVAT=req.collectAmountVAT
|
||||
)
|
||||
|
||||
logger.info(f"Processed disbursement for customer {req.customerId}, amount {req.provideAmount}")
|
||||
return jsonify(response.to_dict())
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing disbursement: {str(e)}")
|
||||
return jsonify({
|
||||
'resultCode': '500',
|
||||
'resultDescription': 'Internal server error'
|
||||
}), 500
|
||||
Reference in New Issue
Block a user