diff --git a/src/paysgator/client.py b/src/paysgator/client.py index a067367..5cb7703 100644 --- a/src/paysgator/client.py +++ b/src/paysgator/client.py @@ -53,6 +53,8 @@ class PaysgatorClient: BASE_URL = "https://paysgator.com/api/v1" def __init__(self, api_key: str): + if not api_key or not isinstance(api_key, str) or len(api_key.strip()) < 10: + raise ValueError("API key must be a non-empty string with at least 10 characters") self.api_key = api_key self.session = requests.Session() self.session.headers.update({ @@ -70,7 +72,7 @@ def set_base_url(self, url: str): def request(self, method: str, endpoint: str, data: Optional[dict] = None) -> dict: url = f"{self.BASE_URL}{endpoint}" - response = self.session.request(method, url, json=data) + response = self.session.request(method, url, json=data, timeout=30) if response.status_code >= 400: raise APIError(response.status_code, response.text) diff --git a/src/paysgator/exceptions.py b/src/paysgator/exceptions.py index 3067741..bab806a 100644 --- a/src/paysgator/exceptions.py +++ b/src/paysgator/exceptions.py @@ -8,7 +8,7 @@ class AuthenticationError(PaysgatorError): class APIError(PaysgatorError): """Raised when the API returns an error""" - def __init__(self, status_code: int, message: str): + def __init__(self, status_code: int, message: str, *args, **kwargs): self.status_code = status_code self.message = message super().__init__(f"API Error {status_code}: {message}") diff --git a/src/paysgator/models.py b/src/paysgator/models.py index 8863e2d..2f7bf1c 100644 --- a/src/paysgator/models.py +++ b/src/paysgator/models.py @@ -73,5 +73,5 @@ class TransactionResponse(BaseModel): class WalletBalanceResponse(BaseModel): wallet_id: str = Field(..., alias="walletId") currency: str - balance: str + balance: float mode: str diff --git a/test_sdk.py b/test_sdk.py index 7ee8b76..c22bbdd 100644 --- a/test_sdk.py +++ b/test_sdk.py @@ -1,10 +1,11 @@ +import os from src.paysgator.client import PaysgatorClient #Mpesa direct charge test -api_key = "" +api_key = os.getenv("PAYSGATOR_API_KEY", "") -wallet_id = "" +wallet_id = os.getenv("PAYSGATOR_WALLET_ID", "") client = PaysgatorClient(api_key, wallet_id)