From e14e290ff97f93ee7c4517781fb4c0aaa696baf5 Mon Sep 17 00:00:00 2001 From: VivianDee <115420678+VivianDee@users.noreply.github.com> Date: Wed, 16 Apr 2025 22:46:48 +0100 Subject: [PATCH] [update]: RACChecks --- app/api/integrations/simbrella.py | 48 +++++++++++++-------------- app/api/services/eligibility_check.py | 6 ++-- requirements.txt | 3 +- 3 files changed, 29 insertions(+), 28 deletions(-) diff --git a/app/api/integrations/simbrella.py b/app/api/integrations/simbrella.py index 9bd7638..5db7012 100644 --- a/app/api/integrations/simbrella.py +++ b/app/api/integrations/simbrella.py @@ -1,8 +1,9 @@ -import requests +import httpx import json -from requests.auth import HTTPBasicAuth from app.utils.logger import logger from app.config import settings +import logging + class SimbrellaIntegration: BASE_URL = settings.SIMBRELLA_BASE_URL @@ -13,42 +14,41 @@ class SimbrellaIntegration: Calls the RACCheck endpoit """ url = f"{SimbrellaIntegration.BASE_URL}/RACCheck" - + payload = { "customerId": customer_id, "accountId": account_id, - "transactionId": transaction_id, + "transactionId": str(transaction_id), + "fbnTransactionId": f"FBN{transaction_id}", "RAC_Array": [ - { - "salaryAccount": True, - "bvn": "12345678901", - "crc": False, - "crms": True, - "accountStatus": "active", - "lien": False, - "noBouncedCheck": True, - "existingLoan": False, - "whitelist": True, - "noPastDueSalaryLoan": True, - "noPastDueOtherLoans": False - } - ] + "SalaryAccount", + "BVN", + "BVNAttachedtoAccount", + "CRC", + "CRMS", + "AccountStatus", + "Lien", + "NoBouncedCheck", + "Whitelist", + "NoPastDueSalaryLoan", + "NoPastDueOtherLoan", + ], } - logger.error(f"This is PayLoad: {str(payload)}",exc_info=True) + logger.error(f"This is PayLoad: {str(payload)}", exc_info=True) headers = { - 'Content-Type': 'application/json', - 'x-api-key': f'{settings.VALID_API_KEY}', - 'App-Id': f'{settings.VALID_APP_ID}' + "Content-Type": "application/json", + "x-api-key": f"{settings.VALID_API_KEY}", + "App-Id": f"{settings.VALID_APP_ID}", } try: - response = requests.post(url, json=payload, timeout=10, headers=headers) + response = httpx.post(url, json=payload, headers=headers, timeout=10.0) logger.error(f"This is Response: {str(response)}", exc_info=True) - return response.json() + return response except Exception as e: logger.error(f"RACCheck API call failed: {str(e)}", exc_info=True) raise Exception(f"RACCheck API call failed: {str(e)}") diff --git a/app/api/services/eligibility_check.py b/app/api/services/eligibility_check.py index ebd94dd..6cdf075 100644 --- a/app/api/services/eligibility_check.py +++ b/app/api/services/eligibility_check.py @@ -48,17 +48,17 @@ class EligibilityCheckService(BaseService): "message": "Invalid Customer or Account" }), 400 + db.session.flush() + # Call RACCheck response = SimbrellaIntegration.rac_check( customer_id = customer_id, account_id = account_id, transaction_id = transaction.id, ) - - logger.error(f"This is Response Returned ****** : {str(response)}") # this chck for error is not valid - if response.get("status") != 200: + if response.status_code != 200: return jsonify({"message": "RACCheck failed"}), 400 offers = [offer.to_dict() for offer in Offer.get_all_offers()] diff --git a/requirements.txt b/requirements.txt index 9d5c945..95d8b87 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,7 +25,8 @@ flask-swagger-ui python-dotenv # Requests -requests +httpx + # JWT flask-jwt-extended