[add]: code refractoring and cleanup

This commit is contained in:
VivianDee
2025-09-07 23:07:40 +01:00
parent 2cc3d70f4f
commit 6de9583aaf
25 changed files with 86 additions and 60 deletions
+44
View File
@@ -0,0 +1,44 @@
from django.conf import settings
import httpx
import json
from app.config import SIMBRELLA_BASE_URL, SIMBRELLA_ENDPOINT_RAC_CHECKS
from app.utils.logger import logger
class SimbrellaIntegration:
BASE_URL = SIMBRELLA_BASE_URL
ENDPOINT_RAC_CHECKS = SIMBRELLA_ENDPOINT_RAC_CHECKS
@staticmethod
def rac_check(customer_id, account_id, transaction_id):
"""
Calls the RACCheck endpoit
"""
url = f"{SimbrellaIntegration.BASE_URL}/{SimbrellaIntegration.ENDPOINT_RAC_CHECKS}"
logger.info(f"Contacting Rack Checks EndPoint: {str(url)}", exc_info=True)
payload = {
"customerId": customer_id,
"accountId": account_id,
"transactionId": str(transaction_id),
"fbnTransactionId": str(transaction_id),
"countryCode": "NG",
"channel": "USSD"
}
headers = {
"Content-Type": "application/json",
"x-api-key": f"{settings.VALID_API_KEY}",
"App-Id": f"{settings.VALID_APP_ID}",
}
try:
response = httpx.post(url, json=payload, headers=headers, timeout=10.0)
logger.info(f"This is Response: {str(response)}", exc_info=True)
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)}")
@@ -0,0 +1,36 @@
import time
import threading
import requests
from ...config import SALARY_DETECT_URL, SALARY_DETECT_HEADERS, get_random_salary_payload
from app.utils.logger import logger
class SalaryDetect:
def __init__(self):
self._running = False
self._thread = None
def _run(self):
while self._running:
logger.info(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] Detecting salary...")
try:
payload = get_random_salary_payload()
response = requests.post(SALARY_DETECT_URL, headers=SALARY_DETECT_HEADERS, json=payload)
logger.info(f"POST {SALARY_DETECT_URL} status: {response.status_code}, response: {response.text}")
except Exception as e:
logger.error(f"Error during POST: {e}")
logger.info(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] Salary detection complete")
time.sleep(120)
def start(self):
if not self._running:
self._running = True
self._thread = threading.Thread(target=self._run, daemon=True)
self._thread.start()
def stop(self):
self._running = False
if self._thread:
self._thread.join()