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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=61.0"]
requires = ["setuptools>=61.0.0"]
build-backend = "setuptools.build_meta"

[project]
Expand Down
2 changes: 1 addition & 1 deletion pyvenv.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ home = /usr/bin
include-system-site-packages = false
version = 3.12.3
executable = /usr/bin/python3.12
command = /usr/bin/python3 -m venv /home/mucamba/paysgatorsdks/python
command = /usr/bin/python3 -m venv .
14 changes: 9 additions & 5 deletions src/paysgator/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def confirm(self, payment_link_id: str, payment_method: str, **kwargs) -> Paymen
class Subscriptions(Resource):
def update(self, subscription_id: str, action: str) -> SubscriptionResponse:
request_model = SubscriptionUpdateRequest(action=action)
response_data = self.client.request("PATCH", f"/subscriptions/{subscription_id}", data=request_model.model_dump(by_alias=True))
response_data = self.client.request("PATCH", f"/subscriptions/{subscription_id}", data=request_model.model_dump(by_alias=True, exclude_none=True))
return SubscriptionResponse(**response_data)

class Transactions(Resource):
Expand Down Expand Up @@ -66,13 +66,17 @@ 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}"
def request(self, method: str, endpoint: str, data: Optional[dict] = None) -> Dict[str, Any]:
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)
try:
error_data = response.json()
raise APIError(response.status_code, error_data)
except ValueError:
raise APIError(response.status_code, response.text)

return response.json()
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
4 changes: 2 additions & 2 deletions test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

#Mpesa direct charge test

api_key = "<Api Key>"
# api_key = "<Api Key>"

wallet_id = "<Wallet Id>"
# wallet_id = "<Wallet Id>"

client = PaysgatorClient(api_key, wallet_id)

Expand Down