[add]: Account Balance check
This commit was merged in pull request #77.
This commit is contained in:
@@ -10,6 +10,7 @@ class SimbrellaIntegration:
|
||||
ENDPOINT_RAC_CHECKS = settings.SIMBRELLA_ENDPOINT_RAC_CHECKS
|
||||
HEALTH_ENDPOINT = settings.SIMBRELLA_HEALTH
|
||||
AUTH_ENDPOINT = settings.BANK_CALL_AUTH_ENDPOINT
|
||||
SIMBRELLA_VERIFY_BALANCE_ENDPOINT = settings.SIMBRELLA_VERIFY_BALANCE_ENDPOINT
|
||||
|
||||
_access_token = None # cache token in memory
|
||||
_token_expiry = 0
|
||||
@@ -94,6 +95,58 @@ class SimbrellaIntegration:
|
||||
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)}")
|
||||
|
||||
|
||||
@staticmethod
|
||||
def verify_account_balance(account_id: str, amount: float, request_id: str):
|
||||
"""
|
||||
Calls the Verify Account Balance endpoint
|
||||
"""
|
||||
url = f"{SimbrellaIntegration.BASE_URL}/{SimbrellaIntegration.SIMBRELLA_VERIFY_BALANCE_ENDPOINT}"
|
||||
logger.info(f"Contacting Verify Account Balance Endpoint: {url}")
|
||||
|
||||
payload = {
|
||||
"accountId": account_id,
|
||||
"amount": amount,
|
||||
"requestId": str(request_id),
|
||||
}
|
||||
|
||||
try:
|
||||
access_token = SimbrellaIntegration._get_token()
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {access_token}",
|
||||
}
|
||||
|
||||
response = httpx.post(
|
||||
url,
|
||||
json=payload,
|
||||
headers=headers,
|
||||
timeout=10.0,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
f"Verify Account Balance Response: "
|
||||
f"status={response.status_code}, body={response.text}"
|
||||
)
|
||||
|
||||
response.raise_for_status()
|
||||
return response
|
||||
|
||||
except httpx.HTTPStatusError as e:
|
||||
logger.error(
|
||||
f"Verify Account Balance failed with status "
|
||||
f"{e.response.status_code}: {e.response.text}",
|
||||
exc_info=True,
|
||||
)
|
||||
raise Exception("Verify Account Balance API returned an error")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Verify Account Balance API call failed: {str(e)}",
|
||||
exc_info=True,
|
||||
)
|
||||
raise Exception(f"Verify Account Balance API call failed: {str(e)}")
|
||||
|
||||
@staticmethod
|
||||
def health_check():
|
||||
|
||||
Reference in New Issue
Block a user