From c826bdc36ba1318484a2b27bba2ae5fe004f125f Mon Sep 17 00:00:00 2001 From: VivianDee <115420678+VivianDee@users.noreply.github.com> Date: Mon, 31 Mar 2025 16:24:05 +0100 Subject: [PATCH] [add]: RACCHECK --- app/api/integrations/__init__.py | 1 + app/api/integrations/simbrella.py | 33 +++++++++++++++++++++++++++ app/api/services/eligibility_check.py | 14 ++++++++++++ app/config.py | 6 ++++- requirements.txt | 4 ++++ 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 app/api/integrations/__init__.py create mode 100644 app/api/integrations/simbrella.py diff --git a/app/api/integrations/__init__.py b/app/api/integrations/__init__.py new file mode 100644 index 0000000..54ad10b --- /dev/null +++ b/app/api/integrations/__init__.py @@ -0,0 +1 @@ +from .simbrella import SimbrellaClient \ No newline at end of file diff --git a/app/api/integrations/simbrella.py b/app/api/integrations/simbrella.py new file mode 100644 index 0000000..d6f3a0e --- /dev/null +++ b/app/api/integrations/simbrella.py @@ -0,0 +1,33 @@ +import requests +from app.utils.logger import logger +from app.config import settings + +class SimbrellaClient: + BASE_URL = settings.SIMBRELLA_BASE_URL + + @staticmethod + def rac_check(customer_id, account_id, transaction_id, country_code, msisdn): + """ + Calls the RACCheck endpoit + """ + url = f"{SimbrellaClient.BASE_URL}/RACCheck" + + payload = { + "customerId": customer_id, + "accountId": account_id, + "transactionId": transaction_id, + "countryCode": country_code, + "msisdn": msisdn + } + + try: + response = requests.post(url, json=payload, timeout=10) + + # Raise an error for non-200 responses + # response.raise_for_status() + + + return response.json() + except requests.exceptions.RequestException as err: + logger.error(f"RACCheck API call failed: {str(err)}", exc_info=True) + return {"error": "RACCheck API error", "details": str(err)} diff --git a/app/api/services/eligibility_check.py b/app/api/services/eligibility_check.py index 37fcaa1..852a584 100644 --- a/app/api/services/eligibility_check.py +++ b/app/api/services/eligibility_check.py @@ -4,6 +4,7 @@ from app.api.services.base_service import BaseService from app.api.schemas.eligibility_check import EligibilityCheckSchema from marshmallow import ValidationError from app.api.enums import TransactionType +from app.api.integrations import SimbrellaClient class EligibilityCheckService(BaseService): TRANSACTION_TYPE = TransactionType.ELIGIBILITY_CHECK @@ -40,6 +41,19 @@ class EligibilityCheckService(BaseService): "message": "Invalid Customer or Account" }), 400 + # Call RACCheck + response = SimbrellaClient.rac_check( + customer_id=customer_id, + account_id=account_id, + transaction_id=validated_data.get("transactionId"), + country_code=validated_data.get("countryCode"), + msisdn=validated_data.get("msisdn") + ) + + if "error" in response or response.get("status") != 200: + return jsonify({"message": "RACCheck failed", "error": response.get("message", response)}), 400 + + offers = [ { diff --git a/app/config.py b/app/config.py index a5609ac..fb66b2d 100644 --- a/app/config.py +++ b/app/config.py @@ -22,4 +22,8 @@ class Config: SQLALCHEMY_DATABASE_URI = ( f"postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}" ) - SQLALCHEMY_TRACK_MODIFICATIONS = False \ No newline at end of file + SQLALCHEMY_TRACK_MODIFICATIONS = False + SIMBRELLA_BASE_URL = os.getenv("SIMBRELLA_BASE_URL", "http://127.0.0.1:6337") + + +settings = Config() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index b807973..7e47465 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,3 +23,7 @@ flask-swagger-ui # Env python-dotenv + +# Requests +requests +