Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/paysgator/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/paysgator/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
2 changes: 1 addition & 1 deletion src/paysgator/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ class TransactionResponse(BaseModel):
class WalletBalanceResponse(BaseModel):
wallet_id: str = Field(..., alias="walletId")
currency: str
balance: str
balance: float
mode: str
5 changes: 3 additions & 2 deletions test_sdk.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
from src.paysgator.client import PaysgatorClient

#Mpesa direct charge test

api_key = "<Api Key>"
api_key = os.getenv("PAYSGATOR_API_KEY", "<Api Key>")

wallet_id = "<Wallet Id>"
wallet_id = os.getenv("PAYSGATOR_WALLET_ID", "<Wallet Id>")

client = PaysgatorClient(api_key, wallet_id)

Expand Down