[add]: loan ref to repayment
This commit is contained in:
@@ -5,9 +5,8 @@ class RepaymentSchema(Schema):
|
||||
type = fields.Str(required=False)
|
||||
msisdn = fields.Str(required=False) #optional
|
||||
debtId = fields.Str(required=True)
|
||||
productId = fields.Str(required=True)
|
||||
transactionId = fields.Str(required=True)
|
||||
accountId = fields.Str(required=True)
|
||||
customerId = fields.Str(required=True)
|
||||
channel = fields.Str(required=True)
|
||||
loanRef = fields.Str(required=True)
|
||||
initiatedBy = fields.Str(required=False)
|
||||
|
||||
@@ -32,20 +32,22 @@ class RepaymentService(BaseService):
|
||||
customer_id = validated_data.get('customerId')
|
||||
request_id = validated_data.get('requestId')
|
||||
loan_id = validated_data.get('debtId')
|
||||
product_id = validated_data.get('productId')
|
||||
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')
|
||||
initiated_by = validated_data.get('initiatedBy')
|
||||
|
||||
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
|
||||
repayment = Repayment.create_repayment(
|
||||
customer_id = customer_id,
|
||||
loan_id = loan_id,
|
||||
product_id = product_id,
|
||||
transaction_id=transaction_id
|
||||
loan = loan,
|
||||
transaction_id = transaction_id
|
||||
)
|
||||
|
||||
if not repayment:
|
||||
@@ -66,7 +68,8 @@ class RepaymentService(BaseService):
|
||||
response_data = {
|
||||
"transactionId": transaction_id,
|
||||
"customerId": customer_id,
|
||||
"productId": product_id,
|
||||
"productId": loan.product_id,
|
||||
"loanRef": loan_ref,
|
||||
"debtId": loan_id
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,11 @@ class SelectOfferService(BaseService):
|
||||
|
||||
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.")
|
||||
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)
|
||||
|
||||
@@ -48,6 +48,8 @@ class Customer(db.Model):
|
||||
def create_customer(cls, id, msisdn, country_code, account_id, account_type='savings'):
|
||||
if cls.query.filter_by(id=id).first():
|
||||
raise ValueError("Customer already exists")
|
||||
elif Account.query.filter_by(id=account_id).first():
|
||||
raise ValueError("Account already exists")
|
||||
|
||||
# Create the customer
|
||||
customer = cls(
|
||||
|
||||
+3
-11
@@ -23,15 +23,7 @@ class Repayment(db.Model):
|
||||
transaction_id = db.Column(db.String(50), nullable=True)
|
||||
|
||||
@classmethod
|
||||
def create_repayment(cls, customer_id, loan_id, product_id, 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)
|
||||
def create_repayment(cls, customer_id, loan, transaction_id):
|
||||
|
||||
# Check that the loan is active
|
||||
if loan.status not in [LoanStatus.ACTIVE, LoanStatus.START_REPAY]:
|
||||
@@ -40,8 +32,8 @@ class Repayment(db.Model):
|
||||
|
||||
repayment = cls(
|
||||
customer_id=customer_id,
|
||||
loan_id=loan_id,
|
||||
product_id=product_id,
|
||||
loan_id=loan.id,
|
||||
product_id=loan.product_id,
|
||||
transaction_id = transaction_id,
|
||||
created_at=datetime.now(timezone.utc),
|
||||
updated_at=datetime.now(timezone.utc)
|
||||
|
||||
@@ -9,10 +9,6 @@
|
||||
"type": "string",
|
||||
"example": "10"
|
||||
},
|
||||
"productId": {
|
||||
"type": "string",
|
||||
"example": "101"
|
||||
},
|
||||
"transactionId": {
|
||||
"type": "string",
|
||||
"example": "20171209232115"
|
||||
@@ -21,9 +17,9 @@
|
||||
"type": "string",
|
||||
"example": "CID0000025585"
|
||||
},
|
||||
"channel": {
|
||||
"loanRef": {
|
||||
"type": "string",
|
||||
"example": "USSD"
|
||||
"example": "Trx5847365252USSD3MPC"
|
||||
},
|
||||
"accountId": {
|
||||
"type": "string",
|
||||
|
||||
Reference in New Issue
Block a user