[add]: RACCHECK
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
from .simbrella import SimbrellaClient
|
||||||
@@ -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)}
|
||||||
@@ -4,6 +4,7 @@ from app.api.services.base_service import BaseService
|
|||||||
from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
from app.api.schemas.eligibility_check import EligibilityCheckSchema
|
||||||
from marshmallow import ValidationError
|
from marshmallow import ValidationError
|
||||||
from app.api.enums import TransactionType
|
from app.api.enums import TransactionType
|
||||||
|
from app.api.integrations import SimbrellaClient
|
||||||
|
|
||||||
class EligibilityCheckService(BaseService):
|
class EligibilityCheckService(BaseService):
|
||||||
TRANSACTION_TYPE = TransactionType.ELIGIBILITY_CHECK
|
TRANSACTION_TYPE = TransactionType.ELIGIBILITY_CHECK
|
||||||
@@ -40,6 +41,19 @@ class EligibilityCheckService(BaseService):
|
|||||||
"message": "Invalid Customer or Account"
|
"message": "Invalid Customer or Account"
|
||||||
}), 400
|
}), 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 = [
|
offers = [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,3 +23,7 @@ class Config:
|
|||||||
f"postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}"
|
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()
|
||||||
@@ -23,3 +23,7 @@ flask-swagger-ui
|
|||||||
|
|
||||||
# Env
|
# Env
|
||||||
python-dotenv
|
python-dotenv
|
||||||
|
|
||||||
|
# Requests
|
||||||
|
requests
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user