added loop #27
@@ -182,7 +182,7 @@ class SimbrellaClient:
|
||||
def collect_loan_user_initiated(data):
|
||||
# InitiatedBy = USER_INITIATED
|
||||
logger.info(f"Calling CollectLoan collect_loan_user_initiated ******* endpoint with data: {data}")
|
||||
return SimbrellaClient._collect_loan(data,1)
|
||||
return SimbrellaClient._collect_loan(data,"1")
|
||||
|
||||
@staticmethod
|
||||
def collect_loan_user_salary_detect(data):
|
||||
@@ -198,28 +198,28 @@ class SimbrellaClient:
|
||||
# return ResponseHelper.error(message="Failed to call salary endpoint",
|
||||
# status_code=400,
|
||||
# error=str(e) )
|
||||
return SimbrellaClient._collect_loan(data,2)
|
||||
return SimbrellaClient._collect_loan(data,"2")
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def collect_loan_user_due_payment(data):
|
||||
# InitiatedBy = REPAYMENT_DUE
|
||||
return SimbrellaClient._collect_loan(data,3)
|
||||
return SimbrellaClient._collect_loan(data,"3")
|
||||
|
||||
@staticmethod
|
||||
def _collect_loan(data, collectionMethod: int):
|
||||
def _collect_loan(data, collectionMethod: str):
|
||||
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}{SimbrellaClient.BANK_CALL_COLLECT_LOAN_ENDPOINT}"
|
||||
logger.info(f"Calling CollectLoan api_url==> : {api_url}")
|
||||
logger.info(f"Calling CollectLoan endpoint with data: {data}")
|
||||
|
||||
# Check if the repayment exists
|
||||
logger.info(f"Checking if repayment exists")
|
||||
repayment = RepaymentService.get_repayment_by_transaction_id(transaction_id=data['transactionId'])
|
||||
repayment = RepaymentService.get_repayment_by_id(id=data['Id'])
|
||||
logger.info(f"Repayment Response From Database ** : {repayment}")
|
||||
|
||||
if not repayment:
|
||||
logger.info(f"Repayment with transactionId: {data['transactionId']}, was not found")
|
||||
logger.info(f"Repayment with id: {data['Id']}, was not found")
|
||||
return ResponseHelper.error("Repayment not found")
|
||||
logger.info(f"Repayment Response From Database ** : {repayment.to_dict()}")
|
||||
repayment_data = repayment.to_dict()
|
||||
@@ -252,7 +252,7 @@ class SimbrellaClient:
|
||||
"customerId": repayment_data['customerId'],
|
||||
"accountId": loan_data['accountId'],
|
||||
"productId": repayment_data['productId'],
|
||||
"collectAmount": loan_data['repaymentAmount'],
|
||||
"collectAmount": loan_data['repaymentAmount'] or 0,
|
||||
"penalCharge": 5,
|
||||
"channel": "USSD",
|
||||
"collectionMethod": collectionMethod,
|
||||
@@ -263,7 +263,7 @@ class SimbrellaClient:
|
||||
|
||||
try:
|
||||
logger.info(f"Here is your CollectLoan Request data ***** : {collect_loan_data}")
|
||||
response = requests.post(api_url, json=collect_loan_data, headers=get_headers())
|
||||
response = requests.post(api_url, json=collect_loan_data,timeout=30, headers=get_headers())
|
||||
|
||||
logger.info(f"CollectLoan response: {response.json()}")
|
||||
RepaymentService.set_repay_result(repayment_data['Id'], response.json().get('responseCode', ''), response.json().get('responseMessage', ''))
|
||||
|
||||
@@ -93,6 +93,9 @@ class Repayment(db.Model):
|
||||
@classmethod
|
||||
def get_repayment_by_transaction_id(cls, transaction_id):
|
||||
return cls.query.filter_by(transaction_id=transaction_id).first()
|
||||
@classmethod
|
||||
def get_repayment_by_id(cls, id):
|
||||
return cls.query.filter_by(id=id).first()
|
||||
|
||||
@classmethod
|
||||
def set_repay_date(cls, repayment_id, customer_id):
|
||||
|
||||
@@ -75,7 +75,7 @@ def refresh_collection():
|
||||
repayment = RepaymentService.get_latest_repayment_without_repay_date()
|
||||
#repayment = RepaymentService.get_latest_repayment_with_loanId(13735)
|
||||
if not repayment:
|
||||
logger.info(f"No repayment found without disbursement date")
|
||||
logger.info(f"No repayment found without repay date")
|
||||
return 0
|
||||
logger.info(f"Calling repay loan endpoint with data: {repayment}")
|
||||
repayment_data = repayment.to_dict()
|
||||
@@ -86,6 +86,7 @@ def refresh_collection():
|
||||
"debtId": repayment_data['loanId'],
|
||||
"customerId": repayment_data['customerId'],
|
||||
"productId": repayment_data['productId'],
|
||||
"Id":repayment_data['Id']
|
||||
}
|
||||
logger.info(f"Data being sent to Simbrella: {data}")
|
||||
logger.info(f"calling simbrella")
|
||||
|
||||
@@ -8,6 +8,12 @@ class RepaymentService:
|
||||
Get the repayment by transaction ID
|
||||
"""
|
||||
return Repayment.get_repayment_by_transaction_id(transaction_id)
|
||||
@staticmethod
|
||||
def get_repayment_by_id(id):
|
||||
"""
|
||||
Get the repayment by ID
|
||||
"""
|
||||
return Repayment.get_repayment_by_id(id)
|
||||
|
||||
@classmethod
|
||||
def set_repay_date(cls, repayment_id, customer_id):
|
||||
|
||||
Reference in New Issue
Block a user