clickpesa-python-sdk 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
clickpesa/_version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.0"
1
+ __version__ = "0.1.2"
clickpesa/async_client.py CHANGED
@@ -118,45 +118,69 @@ class AsyncClickPesaClient:
118
118
  return self._token
119
119
 
120
120
  logger.debug("Refreshing ClickPesa access token …")
121
- try:
122
- response = await self._http.post(
123
- _AUTH_PATH,
124
- headers={
125
- "client-id": self.client_id,
126
- "api-key": self.api_key,
127
- },
128
- )
129
- except httpx.TransportError as exc:
130
- raise ClickPesaError(
131
- f"Network error during authentication: {exc}"
132
- ) from exc
121
+ last_exc: Exception | None = None
122
+ for attempt in range(1, self.max_retries + 1):
123
+ try:
124
+ response = await self._http.post(
125
+ _AUTH_PATH,
126
+ headers={
127
+ "client-id": self.client_id,
128
+ "api-key": self.api_key,
129
+ },
130
+ )
131
+ except httpx.TransportError as exc:
132
+ last_exc = exc
133
+ if attempt < self.max_retries:
134
+ logger.warning(
135
+ "Auth network error on attempt %d/%d — retrying: %s",
136
+ attempt, self.max_retries, exc,
137
+ )
138
+ await _async_backoff(attempt)
139
+ continue
140
+ raise ClickPesaError(
141
+ f"Network error during authentication: {exc}"
142
+ ) from exc
143
+
144
+ if response.status_code in _RETRY_STATUSES and attempt < self.max_retries:
145
+ logger.warning(
146
+ "Auth server error %d on attempt %d/%d — retrying …",
147
+ response.status_code, attempt, self.max_retries,
148
+ )
149
+ await _async_backoff(attempt)
150
+ continue
151
+
152
+ if response.status_code == 401:
153
+ raise AuthenticationError(
154
+ "Invalid client-id or api-key", status_code=401, response=_safe_json(response)
155
+ )
156
+ if response.status_code == 403:
157
+ data = _safe_json(response)
158
+ raise ForbiddenError(
159
+ data.get("message", "Forbidden"),
160
+ status_code=403,
161
+ response=data,
162
+ )
163
+ if not response.is_success:
164
+ data = _safe_json(response)
165
+ raise ClickPesaError(
166
+ data.get("message", f"Authentication failed ({response.status_code})"),
167
+ status_code=response.status_code,
168
+ response=data,
169
+ )
133
170
 
134
- if response.status_code == 401:
135
- raise AuthenticationError(
136
- "Invalid client-id or api-key", status_code=401
137
- )
138
- if response.status_code == 403:
139
171
  data = _safe_json(response)
140
- raise ForbiddenError(
141
- data.get("message", "Forbidden"),
142
- status_code=403,
143
- response=data,
144
- )
145
- if not response.is_success:
146
- raise ClickPesaError(
147
- f"Authentication failed ({response.status_code}): {response.text}",
148
- status_code=response.status_code,
149
- )
172
+ token = data.get("token")
173
+ if not token:
174
+ raise ClickPesaError("Authentication response missing 'token' field")
150
175
 
151
- data = _safe_json(response)
152
- token = data.get("token")
153
- if not token:
154
- raise ClickPesaError("Authentication response missing 'token' field")
176
+ self._token = token
177
+ self._token_expires_at = now + _TOKEN_TTL
178
+ logger.debug("Access token cached for %d seconds.", _TOKEN_TTL)
179
+ return self._token
155
180
 
156
- self._token = token
157
- self._token_expires_at = now + _TOKEN_TTL
158
- logger.debug("Access token cached for %d seconds.", _TOKEN_TTL)
159
- return self._token
181
+ raise ClickPesaError(
182
+ f"Authentication failed after {self.max_retries} attempts"
183
+ ) from last_exc
160
184
 
161
185
  # ------------------------------------------------------------------
162
186
  # Core request dispatcher
clickpesa/client.py CHANGED
@@ -108,43 +108,67 @@ class ClickPesaClient:
108
108
  return self._token
109
109
 
110
110
  logger.debug("Refreshing ClickPesa access token …")
111
- try:
112
- response = self._http.post(
113
- _AUTH_PATH,
114
- headers={
115
- "client-id": self.client_id,
116
- "api-key": self.api_key,
117
- },
118
- )
119
- except httpx.TransportError as exc:
120
- raise ClickPesaError(f"Network error during authentication: {exc}") from exc
111
+ last_exc: Exception | None = None
112
+ for attempt in range(1, self.max_retries + 1):
113
+ try:
114
+ response = self._http.post(
115
+ _AUTH_PATH,
116
+ headers={
117
+ "client-id": self.client_id,
118
+ "api-key": self.api_key,
119
+ },
120
+ )
121
+ except httpx.TransportError as exc:
122
+ last_exc = exc
123
+ if attempt < self.max_retries:
124
+ logger.warning(
125
+ "Auth network error on attempt %d/%d — retrying: %s",
126
+ attempt, self.max_retries, exc,
127
+ )
128
+ _backoff(attempt)
129
+ continue
130
+ raise ClickPesaError(f"Network error during authentication: {exc}") from exc
131
+
132
+ if response.status_code in _RETRY_STATUSES and attempt < self.max_retries:
133
+ logger.warning(
134
+ "Auth server error %d on attempt %d/%d — retrying …",
135
+ response.status_code, attempt, self.max_retries,
136
+ )
137
+ _backoff(attempt)
138
+ continue
139
+
140
+ if response.status_code == 401:
141
+ raise AuthenticationError(
142
+ "Invalid client-id or api-key", status_code=401, response=_safe_json(response)
143
+ )
144
+ if response.status_code == 403:
145
+ data = _safe_json(response)
146
+ raise ForbiddenError(
147
+ data.get("message", "Forbidden"),
148
+ status_code=403,
149
+ response=data,
150
+ )
151
+ if not response.is_success:
152
+ data = _safe_json(response)
153
+ raise ClickPesaError(
154
+ data.get("message", f"Authentication failed ({response.status_code})"),
155
+ status_code=response.status_code,
156
+ response=data,
157
+ )
121
158
 
122
- if response.status_code == 401:
123
- raise AuthenticationError(
124
- "Invalid client-id or api-key", status_code=401
125
- )
126
- if response.status_code == 403:
127
159
  data = _safe_json(response)
128
- raise ForbiddenError(
129
- data.get("message", "Forbidden"),
130
- status_code=403,
131
- response=data,
132
- )
133
- if not response.is_success:
134
- raise ClickPesaError(
135
- f"Authentication failed ({response.status_code}): {response.text}",
136
- status_code=response.status_code,
137
- )
160
+ token = data.get("token")
161
+ if not token:
162
+ raise ClickPesaError("Authentication response missing 'token' field")
138
163
 
139
- data = _safe_json(response)
140
- token = data.get("token")
141
- if not token:
142
- raise ClickPesaError("Authentication response missing 'token' field")
164
+ self._token = token
165
+ self._token_expires_at = now + _TOKEN_TTL
166
+ logger.debug("Access token cached for %d seconds.", _TOKEN_TTL)
167
+ return self._token
143
168
 
144
- self._token = token
145
- self._token_expires_at = now + _TOKEN_TTL
146
- logger.debug("Access token cached for %d seconds.", _TOKEN_TTL)
147
- return self._token
169
+ raise ClickPesaError(
170
+ f"Authentication failed after {self.max_retries} attempts"
171
+ ) from last_exc
148
172
 
149
173
  # ------------------------------------------------------------------
150
174
  # Core request dispatcher
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clickpesa-python-sdk
3
- Version: 0.1.1
3
+ Version: 0.1.2
4
4
  Summary: Production-grade Python SDK for the ClickPesa API — sync & async, collections, payouts, BillPay and more
5
5
  Author-email: Jackson Linus <jacksonlinus95@gmail.com>
6
6
  License-Expression: MIT
@@ -1,7 +1,7 @@
1
1
  clickpesa/__init__.py,sha256=dkQGqZMGhris8LTg9pCu4LZ8Q8JmKVl_SbdK8K15sI4,4531
2
- clickpesa/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
3
- clickpesa/async_client.py,sha256=BHO0qWUNmHprLqrF9HlXwKaexOEB-UpFgqIv8oA4Jkg,10385
4
- clickpesa/client.py,sha256=HrzIDSR8EKedvwId5rJWVJtM9C7dFeCHKIp9JxGNE7k,10284
2
+ clickpesa/_version.py,sha256=YvuYzWnKtqBb-IqG8HAu-nhIYAsgj9Vmc_b9o7vO-js,22
3
+ clickpesa/async_client.py,sha256=6HivDjAm3T-dnED-5Sxh4EowRo0o74YWbaFK52nQfUM,11661
4
+ clickpesa/client.py,sha256=xB-fBFRZlFd_ubcB8Ed9EHFn075LfcSGEi415mT_AT0,11528
5
5
  clickpesa/exceptions.py,sha256=PJyEmOkP7UdsYJLQ5csZJG4k3WFTdZGTczgssSiFeSs,2311
6
6
  clickpesa/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  clickpesa/security.py,sha256=JXWZXZj9Ap9G_BPfjUSznzO2FIsxYylMdG7YW2g3ow8,2578
@@ -13,8 +13,8 @@ clickpesa/services/exchange.py,sha256=jv4PfT1svaKQrfRbUpxCkMwZdo5EWz5YevylNOvF03
13
13
  clickpesa/services/links.py,sha256=A3ZNU7Z-haiazqOX4VHApsdq8FOqsBIL8C_97mtw7W0,6113
14
14
  clickpesa/services/payments.py,sha256=zUPSraoxzGPFcvsdCfbNHnwgeNTZdlADozHO4mwkR0M,8579
15
15
  clickpesa/services/payouts.py,sha256=bT5uoEj14YuGgJPQUhFqlYKC0QPMWYa55nm8LrA4URw,10431
16
- clickpesa_python_sdk-0.1.1.dist-info/licenses/LICENSE,sha256=3JOYdzl7RSKg6-b0-yGz-LwssM-qVjYEAJ_GGWfVxb8,1070
17
- clickpesa_python_sdk-0.1.1.dist-info/METADATA,sha256=JMBXK2Pd7xqbD6wATsYpH8gl_EHSxrEuGuSObpW6DUc,15139
18
- clickpesa_python_sdk-0.1.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
19
- clickpesa_python_sdk-0.1.1.dist-info/top_level.txt,sha256=4ijtPYCQzYuF0upkzfKlku_Pf1C3ym-77M6Rg8MkJPY,10
20
- clickpesa_python_sdk-0.1.1.dist-info/RECORD,,
16
+ clickpesa_python_sdk-0.1.2.dist-info/licenses/LICENSE,sha256=3JOYdzl7RSKg6-b0-yGz-LwssM-qVjYEAJ_GGWfVxb8,1070
17
+ clickpesa_python_sdk-0.1.2.dist-info/METADATA,sha256=L2hvqj9PKVnTuLC0BG9GD5V3p2nAezgNAldALX0UjBk,15139
18
+ clickpesa_python_sdk-0.1.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
19
+ clickpesa_python_sdk-0.1.2.dist-info/top_level.txt,sha256=4ijtPYCQzYuF0upkzfKlku_Pf1C3ym-77M6Rg8MkJPY,10
20
+ clickpesa_python_sdk-0.1.2.dist-info/RECORD,,