Merge branch 'loan_reference' of DigiFi/digifi-BankToProductCore into master

This commit is contained in:
2025-05-28 20:22:53 +00:00
committed by Gogs
7 changed files with 26 additions and 26 deletions
+1 -2
View File
@@ -5,9 +5,8 @@ class RepaymentSchema(Schema):
type = fields.Str(required=False) type = fields.Str(required=False)
msisdn = fields.Str(required=False) #optional msisdn = fields.Str(required=False) #optional
debtId = fields.Str(required=True) debtId = fields.Str(required=True)
productId = fields.Str(required=True)
transactionId = fields.Str(required=True) transactionId = fields.Str(required=True)
accountId = fields.Str(required=True) accountId = fields.Str(required=True)
customerId = fields.Str(required=True) customerId = fields.Str(required=True)
channel = fields.Str(required=True) loanRef = fields.Str(required=True)
initiatedBy = fields.Str(required=False) initiatedBy = fields.Str(required=False)
+3
View File
@@ -64,6 +64,9 @@ class ProvideLoanService(BaseService):
if(amount < transaction_offer.min_amount): if(amount < transaction_offer.min_amount):
return ResponseHelper.error(result_description="The amount is less than the minimum allowed transaction amount.") return ResponseHelper.error(result_description="The amount is less than the minimum allowed transaction amount.")
elif amount > transaction_offer.max_amount:
return ResponseHelper.error(result_description="The amount is greater than the maximum allowed transaction amount.")
# transaction_offer_id = int(offer_id[5:]) # The last part is int # transaction_offer_id = int(offer_id[5:]) # The last part is int
+9 -6
View File
@@ -32,20 +32,22 @@ class RepaymentService(BaseService):
customer_id = validated_data.get('customerId') customer_id = validated_data.get('customerId')
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')
account_id = validated_data.get('accountId') account_id = validated_data.get('accountId')
customer = Customer.get_customer_with_loan_list(customer_id) loan_ref = validated_data.get('loanRef')
# customer = Customer.get_customer_with_loan_list(customer_id)
transaction_id = validated_data.get('transactionId') transaction_id = validated_data.get('transactionId')
initiated_by = validated_data.get('initiatedBy') initiated_by = validated_data.get('initiatedBy')
if(RepaymentService.validate_account_ownership(account_id = account_id, customer_id = customer_id)): if(RepaymentService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
# Check loan exists
loan = Loan.get_customer_loan(loan_id = loan_id, customer_id = customer_id)
# Save the repayment details # Save the repayment details
repayment = Repayment.create_repayment( repayment = Repayment.create_repayment(
customer_id = customer_id, customer_id = customer_id,
loan_id = loan_id, loan = loan,
product_id = product_id, transaction_id = transaction_id
transaction_id=transaction_id
) )
if not repayment: if not repayment:
@@ -66,7 +68,8 @@ class RepaymentService(BaseService):
response_data = { response_data = {
"transactionId": transaction_id, "transactionId": transaction_id,
"customerId": customer_id, "customerId": customer_id,
"productId": product_id, "productId": loan.product_id,
"loanRef": loan_ref,
"debtId": loan_id "debtId": loan_id
} }
+4 -1
View File
@@ -59,8 +59,11 @@ class SelectOfferService(BaseService):
db.session.flush() db.session.flush()
if(amount < offer.min_amount): if amount < offer.min_amount:
return ResponseHelper.error(result_description="The amount is less than the minimum allowed offer amount.") return ResponseHelper.error(result_description="The amount is less than the minimum allowed offer amount.")
elif amount > offer.max_amount:
return ResponseHelper.error(result_description="The amount is greater than the maximum allowed offer amount.")
charges = SelectOfferService.calculate_charges(offer, amount) charges = SelectOfferService.calculate_charges(offer, amount)
+4
View File
@@ -48,6 +48,10 @@ class Customer(db.Model):
def create_customer(cls, id, msisdn, country_code, account_id, account_type='savings'): def create_customer(cls, id, msisdn, country_code, account_id, account_type='savings'):
if cls.query.filter_by(id=id).first(): if cls.query.filter_by(id=id).first():
raise ValueError("Customer already exists") raise ValueError("Customer already exists")
elif Account.query.filter_by(id=account_id).first():
raise ValueError("Account already exists")
elif cls.query.filter_by(msisdn=msisdn).first():
raise ValueError("msisdn already exists")
# Create the customer # Create the customer
customer = cls( customer = cls(
+3 -11
View File
@@ -23,15 +23,7 @@ class Repayment(db.Model):
transaction_id = db.Column(db.String(50), nullable=True) transaction_id = db.Column(db.String(50), nullable=True)
@classmethod @classmethod
def create_repayment(cls, customer_id, loan_id, product_id, transaction_id): def create_repayment(cls, customer_id, loan, transaction_id):
# Check customer exists
if not Customer.is_valid_customer(customer_id):
raise ValueError("Invalid customer")
# Check loan exists
loan = Loan.get_customer_loan(loan_id = loan_id, customer_id = customer_id)
# Check that the loan is active # Check that the loan is active
if loan.status not in [LoanStatus.ACTIVE, LoanStatus.START_REPAY]: if loan.status not in [LoanStatus.ACTIVE, LoanStatus.START_REPAY]:
@@ -40,8 +32,8 @@ class Repayment(db.Model):
repayment = cls( repayment = cls(
customer_id=customer_id, customer_id=customer_id,
loan_id=loan_id, loan_id=loan.id,
product_id=product_id, product_id=loan.product_id,
transaction_id = transaction_id, transaction_id = transaction_id,
created_at=datetime.now(timezone.utc), created_at=datetime.now(timezone.utc),
updated_at=datetime.now(timezone.utc) updated_at=datetime.now(timezone.utc)
+2 -6
View File
@@ -9,10 +9,6 @@
"type": "string", "type": "string",
"example": "10" "example": "10"
}, },
"productId": {
"type": "string",
"example": "101"
},
"transactionId": { "transactionId": {
"type": "string", "type": "string",
"example": "20171209232115" "example": "20171209232115"
@@ -21,9 +17,9 @@
"type": "string", "type": "string",
"example": "CID0000025585" "example": "CID0000025585"
}, },
"channel": { "loanRef": {
"type": "string", "type": "string",
"example": "USSD" "example": "Trx5847365252USSD3MPC"
}, },
"accountId": { "accountId": {
"type": "string", "type": "string",