diff --git a/pyproject.toml b/pyproject.toml index ff08145..a58ba26 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=61.0"] +requires = ["setuptools>=61.0,<70.0"] build-backend = "setuptools.build_meta" [project] @@ -17,8 +17,8 @@ classifiers = [ "Operating System :: OS Independent", ] dependencies = [ - "requests>=2.25.1", - "pydantic>=2.0.0" + "requests>=2.25.1,<3.0.0", + "pydantic>=2.0.0,<3.0.0" ] [project.urls] diff --git a/src/paysgator/__init__.py b/src/paysgator/__init__.py index d0cf227..a781604 100644 --- a/src/paysgator/__init__.py +++ b/src/paysgator/__init__.py @@ -1,3 +1,5 @@ +"""Paysgator SDK - A client library for the Paysgator API.""" + from .client import PaysgatorClient from .exceptions import PaysgatorError, AuthenticationError, APIError diff --git a/src/paysgator/client.py b/src/paysgator/client.py index a067367..5b0fb0f 100644 --- a/src/paysgator/client.py +++ b/src/paysgator/client.py @@ -50,10 +50,11 @@ def get_balance(self) -> WalletBalanceResponse: return WalletBalanceResponse(**response_data) class PaysgatorClient: - BASE_URL = "https://paysgator.com/api/v1" + DEFAULT_BASE_URL = "https://paysgator.com/api/v1" def __init__(self, api_key: str): self.api_key = api_key + self._base_url = self.DEFAULT_BASE_URL self.session = requests.Session() self.session.headers.update({ "X-Api-Key": self.api_key, @@ -66,13 +67,15 @@ def __init__(self, api_key: str): self.wallet = Wallet(self) def set_base_url(self, url: str): - self.BASE_URL = url + self._base_url = url def request(self, method: str, endpoint: str, data: Optional[dict] = None) -> dict: - url = f"{self.BASE_URL}{endpoint}" + url = f"{self._base_url}{endpoint}" response = self.session.request(method, url, json=data) - if response.status_code >= 400: - raise APIError(response.status_code, response.text) + if response.status_code == 401 or response.status_code == 403: + raise AuthenticationError(response.status_code, response.text) + elif response.status_code >= 400: + raise APIError(response.status_code, response.text) return response.json() diff --git a/src/paysgator/exceptions.py b/src/paysgator/exceptions.py index 3067741..5c0b53d 100644 --- a/src/paysgator/exceptions.py +++ b/src/paysgator/exceptions.py @@ -8,7 +8,8 @@ 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, response_data: dict = None): self.status_code = status_code self.message = message + self.response_data = response_data super().__init__(f"API Error {status_code}: {message}") diff --git a/src/paysgator/models.py b/src/paysgator/models.py index 8863e2d..00a1e4d 100644 --- a/src/paysgator/models.py +++ b/src/paysgator/models.py @@ -10,7 +10,7 @@ class PaymentCreateRequest(BaseModel): amount: float currency: str external_transaction_id: Optional[str] = Field(None, alias="externalTransactionId") - payment_methods: Optional[List[str]] = Field(None, alias="payment_methods") + payment_methods: Optional[List[str]] = Field(None, alias="paymentMethods") fields: Optional[List[str]] = None return_url: Optional[str] = Field(None, alias="returnUrl") metadata: Optional[Dict[str, Any]] = None @@ -73,5 +73,5 @@ class TransactionResponse(BaseModel): class WalletBalanceResponse(BaseModel): wallet_id: str = Field(..., alias="walletId") currency: str - balance: str + balance: float mode: str