diff --git a/app/integrations/simbrella.py b/app/integrations/simbrella.py index 54f622b..78b5989 100644 --- a/app/integrations/simbrella.py +++ b/app/integrations/simbrella.py @@ -183,23 +183,17 @@ class SimbrellaClient: # InitiatedBy = USER_INITIATED logger.info(f"Calling CollectLoan collect_loan_user_initiated ******* endpoint with data: {data}") return SimbrellaClient._collect_loan(data,"1") - @staticmethod def collect_loan_user_salary_detect(data): - #InitiatedBy = SALARY_DETECT - # logger.info(f"salary data: {data}") - # try: - # salary = SalaryService.add_salary_data(data) - # if salary: - # return ResponseHelper.success(salary.to_dict(), "Successful") - # - # except Exception as e: - # logger.info(f"Failed to save salary: {e}") - # return ResponseHelper.error(message="Failed to call salary endpoint", - # status_code=400, - # error=str(e) ) - return SimbrellaClient._collect_loan(data,"2") - + try: + return SimbrellaClient._collect_loan(data, "2") + except Exception as e: + logger.error(f"Error in collect_loan_user_salary_detect: {e}") + return ResponseHelper.error( + message="Failed to collect loan for salary detection", + status_code=500, + error=str(e) + ) @staticmethod diff --git a/app/models/salary.py b/app/models/salary.py index d11315b..2099187 100644 --- a/app/models/salary.py +++ b/app/models/salary.py @@ -29,7 +29,7 @@ class Salary(db.Model): 'id': self.id, 'customerId': self.customer_id, 'accountId' : self.account_id, - 'amount': self.amount, + 'salaryAmount': self.amount, 'status': self.status, 'createdAt': self.created_at.isoformat() if self.created_at else None, 'updatedAt': self.updated_at.isoformat() if self.updated_at else None, @@ -45,7 +45,7 @@ class Salary(db.Model): try: new_data = cls( customer_id=data.get('customerId'), - amount=data.get('amount', 0.0), + amount=data.get('salaryAmount', 0.0), status='START', salary_date = datetime.strptime(data.get('salaryDate'), "%Y-%m-%d").date() if data.get('salaryDate') else None, account_id=data.get('accountId') diff --git a/app/routes/autocall.py b/app/routes/autocall.py index b0c551f..4f06455 100644 --- a/app/routes/autocall.py +++ b/app/routes/autocall.py @@ -121,6 +121,10 @@ def salary_detect(): payload = request.get_json() logger.info("Calling Salary Detect endpoint") + if payload is None: + logger.warning("No payload received in request") + return ResponseHelper.error("Missing request payload", status_code=400) + # Step 1: Try to add new salary data try: new_salary = SalaryService.add_salary_data(payload) diff --git a/openapi.yml b/openapi.yml index c21a14a..8bedff7 100644 --- a/openapi.yml +++ b/openapi.yml @@ -192,7 +192,7 @@ paths: example: "OP621868" status: type: string - amount: + salaryAmount: type: number example: 200000 salaryDate: