[add]: account_id to loan status and repayment
This commit is contained in:
@@ -32,17 +32,24 @@ class LoanStatusService(BaseService):
|
|||||||
customer_id = validated_data.get('customerId')
|
customer_id = validated_data.get('customerId')
|
||||||
customer = Customer.get_customer(customer_id)
|
customer = Customer.get_customer(customer_id)
|
||||||
transactionId = validated_data.get('transactionId')
|
transactionId = validated_data.get('transactionId')
|
||||||
|
account_id = validated_data.get('accountId')
|
||||||
|
|
||||||
# Get loans
|
if(LoanStatusService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
|
||||||
loans = [loan.to_dict() for loan in customer.loans if loan.status == LoanStatus.ACTIVE]
|
|
||||||
|
|
||||||
transaction = LoanStatusService.log_transaction(validated_data = validated_data)
|
# Get loans
|
||||||
|
loans = [loan.to_dict() for loan in customer.loans if loan.status == LoanStatus.ACTIVE]
|
||||||
|
|
||||||
if not transaction:
|
transaction = LoanStatusService.log_transaction(validated_data = validated_data)
|
||||||
logger.error(f"Failed to log transaction")
|
|
||||||
|
if not transaction:
|
||||||
|
logger.error(f"Failed to log transaction")
|
||||||
|
return jsonify({
|
||||||
|
"message": "Failed to log transaction."
|
||||||
|
}), 400
|
||||||
|
else:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"message": "Failed to log transaction."
|
"message": "Invalid Customer or Account"
|
||||||
}), 400
|
}), 400
|
||||||
|
|
||||||
|
|
||||||
# loans = [
|
# loans = [
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from flask import request, jsonify
|
|||||||
from marshmallow import ValidationError
|
from marshmallow import ValidationError
|
||||||
from app.api.enums.loan_status import LoanStatus
|
from app.api.enums.loan_status import LoanStatus
|
||||||
from app.models import Repayment
|
from app.models import Repayment
|
||||||
|
from app.models.customer import Customer
|
||||||
from app.models.loan import Loan
|
from app.models.loan import Loan
|
||||||
from app.utils.logger import logger
|
from app.utils.logger import logger
|
||||||
from app.api.schemas.repayment import RepaymentSchema
|
from app.api.schemas.repayment import RepaymentSchema
|
||||||
@@ -31,34 +32,41 @@ class RepaymentService(BaseService):
|
|||||||
request_id = validated_data.get('requestId')
|
request_id = validated_data.get('requestId')
|
||||||
loan_id = validated_data.get('debtId')
|
loan_id = validated_data.get('debtId')
|
||||||
product_id = validated_data.get('productId')
|
product_id = validated_data.get('productId')
|
||||||
|
account_id = validated_data.get('accountId')
|
||||||
|
customer = Customer.get_customer(customer_id)
|
||||||
|
|
||||||
# Save the repayment details
|
if(RepaymentService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
|
||||||
repayment = Repayment.create_repayment(
|
|
||||||
customer_id = customer_id,
|
|
||||||
loan_id = loan_id,
|
|
||||||
product_id = product_id
|
|
||||||
|
|
||||||
)
|
# Save the repayment details
|
||||||
|
repayment = Repayment.create_repayment(
|
||||||
|
customer_id = customer_id,
|
||||||
|
loan_id = loan_id,
|
||||||
|
product_id = product_id
|
||||||
|
|
||||||
if not repayment:
|
)
|
||||||
logger.error(f"Failed to save repayment details")
|
|
||||||
return jsonify({
|
if not repayment:
|
||||||
"message": "Failed to save repayment details."
|
logger.error(f"Failed to save repayment details")
|
||||||
}), 400
|
return jsonify({
|
||||||
|
"message": "Failed to save repayment details."
|
||||||
|
}), 400
|
||||||
|
|
||||||
#Update Loan status
|
|
||||||
Loan.update_status(loan_id = loan_id, status = LoanStatus.REPAID)
|
#Update Loan status
|
||||||
|
Loan.update_status(loan_id = loan_id, status = LoanStatus.REPAID)
|
||||||
transaction = RepaymentService.log_transaction(validated_data = validated_data)
|
|
||||||
|
transaction = RepaymentService.log_transaction(validated_data = validated_data)
|
||||||
|
|
||||||
if not transaction:
|
if not transaction:
|
||||||
logger.error(f"Failed to log transaction")
|
logger.error(f"Failed to log transaction")
|
||||||
|
return jsonify({
|
||||||
|
"message": "Failed to log transaction."
|
||||||
|
}), 400
|
||||||
|
else:
|
||||||
return jsonify({
|
return jsonify({
|
||||||
"message": "Failed to log transaction."
|
"message": "Invalid Customer or Account"
|
||||||
}), 400
|
}), 400
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Simulated processing logic
|
# Simulated processing logic
|
||||||
|
|||||||
@@ -16,6 +16,10 @@
|
|||||||
"channel": {
|
"channel": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "USSD"
|
"example": "USSD"
|
||||||
|
},
|
||||||
|
"accountId": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "ACN8263457"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"xml": {
|
"xml": {
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
"channel": {
|
"channel": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"example": "USSD"
|
"example": "USSD"
|
||||||
|
},
|
||||||
|
"accountId": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "ACN8263457"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"xml": {
|
"xml": {
|
||||||
|
|||||||
Reference in New Issue
Block a user