[add]: RACCHECK

This commit is contained in:
VivianDee
2025-03-31 16:24:05 +01:00
parent d9c99627ae
commit c826bdc36b
5 changed files with 57 additions and 1 deletions
+1
View File
@@ -0,0 +1 @@
from .simbrella import SimbrellaClient
+33
View File
@@ -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)}
+14
View File
@@ -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 = [
{
+5 -1
View File
@@ -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
SQLALCHEMY_TRACK_MODIFICATIONS = False
SIMBRELLA_BASE_URL = os.getenv("SIMBRELLA_BASE_URL", "http://127.0.0.1:6337")
settings = Config()
+4
View File
@@ -23,3 +23,7 @@ flask-swagger-ui
# Env
python-dotenv
# Requests
requests