viaro 1.0.0__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.
viaro/__init__.py ADDED
@@ -0,0 +1,48 @@
1
+ from .client import AsyncViaro, Viaro
2
+ from .errors import (
3
+ ViaroAPIError,
4
+ ViaroAuthenticationError,
5
+ ViaroConnectionError,
6
+ ViaroError,
7
+ ViaroIdempotencyError,
8
+ ViaroInvalidRequestError,
9
+ ViaroPermissionError,
10
+ ViaroRateLimitError,
11
+ ViaroSignatureVerificationError,
12
+ )
13
+ from .http_client import (
14
+ DEFAULT_API_VERSION,
15
+ DEFAULT_LIVE_BASE_URL,
16
+ DEFAULT_MAX_RETRIES,
17
+ DEFAULT_TEST_BASE_URL,
18
+ DEFAULT_TIMEOUT_SECONDS,
19
+ SDK_VERSION,
20
+ )
21
+ from .models import ViaroListObject, ViaroObject
22
+ from .webhooks import DEFAULT_TOLERANCE_SECONDS, Webhooks
23
+
24
+ __version__ = SDK_VERSION
25
+
26
+ __all__ = [
27
+ "DEFAULT_API_VERSION",
28
+ "DEFAULT_LIVE_BASE_URL",
29
+ "DEFAULT_MAX_RETRIES",
30
+ "DEFAULT_TEST_BASE_URL",
31
+ "DEFAULT_TIMEOUT_SECONDS",
32
+ "DEFAULT_TOLERANCE_SECONDS",
33
+ "SDK_VERSION",
34
+ "AsyncViaro",
35
+ "Viaro",
36
+ "ViaroAPIError",
37
+ "ViaroAuthenticationError",
38
+ "ViaroConnectionError",
39
+ "ViaroError",
40
+ "ViaroIdempotencyError",
41
+ "ViaroInvalidRequestError",
42
+ "ViaroListObject",
43
+ "ViaroObject",
44
+ "ViaroPermissionError",
45
+ "ViaroRateLimitError",
46
+ "ViaroSignatureVerificationError",
47
+ "Webhooks",
48
+ ]
viaro/client.py ADDED
@@ -0,0 +1,193 @@
1
+ from __future__ import annotations
2
+
3
+ import httpx
4
+
5
+ from .http_client import (
6
+ DEFAULT_API_VERSION,
7
+ DEFAULT_MAX_RETRIES,
8
+ DEFAULT_TIMEOUT_SECONDS,
9
+ AsyncHttpClient,
10
+ SyncHttpClient,
11
+ )
12
+ from .resources import (
13
+ AsyncBalanceResource,
14
+ AsyncBillsResource,
15
+ AsyncCounterpartiesResource,
16
+ AsyncCryptoResource,
17
+ AsyncCustomersResource,
18
+ AsyncFxResource,
19
+ AsyncInstitutionsResource,
20
+ AsyncInvoicesResource,
21
+ AsyncIssuingResource,
22
+ AsyncPaymentLinksResource,
23
+ AsyncPaymentsResource,
24
+ AsyncPayoutsResource,
25
+ AsyncPlansResource,
26
+ AsyncRefundsResource,
27
+ AsyncSubscriptionsResource,
28
+ AsyncVirtualAccountsResource,
29
+ BalanceResource,
30
+ BillsResource,
31
+ CounterpartiesResource,
32
+ CryptoResource,
33
+ CustomersResource,
34
+ FxResource,
35
+ InstitutionsResource,
36
+ InvoicesResource,
37
+ IssuingResource,
38
+ PaymentLinksResource,
39
+ PaymentsResource,
40
+ PayoutsResource,
41
+ PlansResource,
42
+ RefundsResource,
43
+ SubscriptionsResource,
44
+ VirtualAccountsResource,
45
+ )
46
+ from .webhooks import Webhooks
47
+
48
+
49
+ class Viaro:
50
+ """
51
+ Official Viaro Synchronous Python SDK Client.
52
+
53
+ Example:
54
+ ```python
55
+ from viaro import Viaro
56
+
57
+ viaro = Viaro("sk_live_...")
58
+ intent = viaro.payments.create(
59
+ amount=15000,
60
+ currency="XAF",
61
+ phone="+237677000000",
62
+ payment_method="mobile_money",
63
+ network="MTN",
64
+ )
65
+ ```
66
+ """
67
+
68
+ def __init__(
69
+ self,
70
+ api_key: str | None = None,
71
+ *,
72
+ base_url: str | None = None,
73
+ timeout: float = DEFAULT_TIMEOUT_SECONDS,
74
+ max_network_retries: int = DEFAULT_MAX_RETRIES,
75
+ api_version: str = DEFAULT_API_VERSION,
76
+ http_client: httpx.Client | None = None,
77
+ ) -> None:
78
+ self.http_client = SyncHttpClient(
79
+ api_key=api_key,
80
+ base_url=base_url,
81
+ timeout=timeout,
82
+ max_network_retries=max_network_retries,
83
+ api_version=api_version,
84
+ http_client=http_client,
85
+ )
86
+ self.payments = PaymentsResource(self.http_client)
87
+ self.payment_intents = self.payments
88
+ self.subscriptions = SubscriptionsResource(self.http_client)
89
+ self.plans = PlansResource(self.http_client)
90
+ self.customers = CustomersResource(self.http_client)
91
+ self.payment_links = PaymentLinksResource(self.http_client)
92
+ self.invoices = InvoicesResource(self.http_client)
93
+ self.refunds = RefundsResource(self.http_client)
94
+ self.balance = BalanceResource(self.http_client)
95
+ self.payouts = PayoutsResource(self.http_client)
96
+ self.virtual_accounts = VirtualAccountsResource(self.http_client)
97
+ self.counterparties = CounterpartiesResource(self.http_client)
98
+ self.fx = FxResource(self.http_client)
99
+ self.institutions = InstitutionsResource(self.http_client)
100
+ self.issuing = IssuingResource(self.http_client)
101
+ self.bills = BillsResource(self.http_client)
102
+ self.crypto = CryptoResource(self.http_client)
103
+ self.webhooks = Webhooks()
104
+
105
+ @property
106
+ def environment(self) -> str:
107
+ return self.http_client.environment
108
+
109
+ @property
110
+ def base_url(self) -> str:
111
+ return self.http_client.base_url
112
+
113
+ def close(self) -> None:
114
+ self.http_client.close()
115
+
116
+ def __enter__(self) -> Viaro: # noqa: PYI034
117
+ return self
118
+
119
+ def __exit__(self, exc_type: object, exc_val: object, exc_tb: object) -> None:
120
+ self.close()
121
+
122
+
123
+ class AsyncViaro:
124
+ """
125
+ Official Viaro Asynchronous Python SDK Client (for FastAPI, asyncio, and async workers).
126
+
127
+ Example:
128
+ ```python
129
+ from viaro import AsyncViaro
130
+
131
+ async with AsyncViaro("sk_live_...") as viaro:
132
+ sub = await viaro.subscriptions.create(
133
+ customer_id="cus_123",
134
+ plan_id="plan_pro",
135
+ payment_method="mobile_money",
136
+ mobile_money={"phone": "+237670112233", "network": "MTN", "country": "CM"},
137
+ )
138
+ ```
139
+ """
140
+
141
+ def __init__(
142
+ self,
143
+ api_key: str | None = None,
144
+ *,
145
+ base_url: str | None = None,
146
+ timeout: float = DEFAULT_TIMEOUT_SECONDS,
147
+ max_network_retries: int = DEFAULT_MAX_RETRIES,
148
+ api_version: str = DEFAULT_API_VERSION,
149
+ http_client: httpx.AsyncClient | None = None,
150
+ ) -> None:
151
+ self.http_client = AsyncHttpClient(
152
+ api_key=api_key,
153
+ base_url=base_url,
154
+ timeout=timeout,
155
+ max_network_retries=max_network_retries,
156
+ api_version=api_version,
157
+ http_client=http_client,
158
+ )
159
+ self.payments = AsyncPaymentsResource(self.http_client)
160
+ self.payment_intents = self.payments
161
+ self.subscriptions = AsyncSubscriptionsResource(self.http_client)
162
+ self.plans = AsyncPlansResource(self.http_client)
163
+ self.customers = AsyncCustomersResource(self.http_client)
164
+ self.payment_links = AsyncPaymentLinksResource(self.http_client)
165
+ self.invoices = AsyncInvoicesResource(self.http_client)
166
+ self.refunds = AsyncRefundsResource(self.http_client)
167
+ self.balance = AsyncBalanceResource(self.http_client)
168
+ self.payouts = AsyncPayoutsResource(self.http_client)
169
+ self.virtual_accounts = AsyncVirtualAccountsResource(self.http_client)
170
+ self.counterparties = AsyncCounterpartiesResource(self.http_client)
171
+ self.fx = AsyncFxResource(self.http_client)
172
+ self.institutions = AsyncInstitutionsResource(self.http_client)
173
+ self.issuing = AsyncIssuingResource(self.http_client)
174
+ self.bills = AsyncBillsResource(self.http_client)
175
+ self.crypto = AsyncCryptoResource(self.http_client)
176
+ self.webhooks = Webhooks()
177
+
178
+ @property
179
+ def environment(self) -> str:
180
+ return self.http_client.environment
181
+
182
+ @property
183
+ def base_url(self) -> str:
184
+ return self.http_client.base_url
185
+
186
+ async def aclose(self) -> None:
187
+ await self.http_client.aclose()
188
+
189
+ async def __aenter__(self) -> AsyncViaro: # noqa: PYI034
190
+ return self
191
+
192
+ async def __aexit__(self, exc_type: object, exc_val: object, exc_tb: object) -> None:
193
+ await self.aclose()
viaro/errors.py ADDED
@@ -0,0 +1,104 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+
6
+ class ViaroError(Exception):
7
+ """Base exception for all Viaro SDK errors."""
8
+
9
+ def __init__(
10
+ self,
11
+ message: str,
12
+ *,
13
+ error_type: str = "api_error",
14
+ code: str | None = None,
15
+ param: str | None = None,
16
+ status_code: int | None = None,
17
+ request_id: str | None = None,
18
+ raw: Any | None = None,
19
+ ) -> None:
20
+ super().__init__(message)
21
+ self.message = message
22
+ self.type = error_type
23
+ self.code = code
24
+ self.param = param
25
+ self.status_code = status_code
26
+ self.request_id = request_id
27
+ self.raw = raw
28
+
29
+ def __repr__(self) -> str:
30
+ return (
31
+ f"{self.__class__.__name__}(message={self.message!r}, type={self.type!r}, "
32
+ f"code={self.code!r}, status_code={self.status_code!r}, request_id={self.request_id!r})"
33
+ )
34
+
35
+
36
+ class ViaroAuthenticationError(ViaroError):
37
+ """Raised on HTTP 401 or invalid/missing API keys."""
38
+
39
+ def __init__(self, message: str, **kwargs: Any) -> None:
40
+ kwargs.setdefault("error_type", "authentication_error")
41
+ super().__init__(message, **kwargs)
42
+
43
+
44
+ class ViaroPermissionError(ViaroError):
45
+ """Raised on HTTP 403 cross-tenant or IP allowlist errors."""
46
+
47
+ def __init__(self, message: str, **kwargs: Any) -> None:
48
+ kwargs.setdefault("error_type", "permission_error")
49
+ super().__init__(message, **kwargs)
50
+
51
+
52
+ class ViaroInvalidRequestError(ViaroError):
53
+ """Raised on HTTP 400, 404, or 422 validation errors."""
54
+
55
+ def __init__(self, message: str, **kwargs: Any) -> None:
56
+ kwargs.setdefault("error_type", "invalid_request_error")
57
+ super().__init__(message, **kwargs)
58
+
59
+
60
+ class ViaroIdempotencyError(ViaroError):
61
+ """Raised on HTTP 409 idempotency conflict."""
62
+
63
+ def __init__(self, message: str, **kwargs: Any) -> None:
64
+ kwargs.setdefault("error_type", "idempotency_error")
65
+ super().__init__(message, **kwargs)
66
+
67
+
68
+ class ViaroRateLimitError(ViaroError):
69
+ """Raised on HTTP 429 rate limit exceeded."""
70
+
71
+ def __init__(self, message: str, **kwargs: Any) -> None:
72
+ kwargs.setdefault("error_type", "rate_limit_error")
73
+ super().__init__(message, **kwargs)
74
+
75
+
76
+ class ViaroAPIError(ViaroError):
77
+ """Raised on HTTP 5xx server errors."""
78
+
79
+ def __init__(self, message: str, **kwargs: Any) -> None:
80
+ kwargs.setdefault("error_type", "api_error")
81
+ super().__init__(message, **kwargs)
82
+
83
+
84
+ class ViaroConnectionError(ViaroError):
85
+ """Raised on network or timeout errors when communicating with Viaro."""
86
+
87
+ def __init__(self, message: str, **kwargs: Any) -> None:
88
+ kwargs.setdefault("error_type", "api_connection_error")
89
+ super().__init__(message, **kwargs)
90
+
91
+
92
+ class ViaroSignatureVerificationError(ViaroError):
93
+ """Raised when X-Viaro-Signature HMAC verification or replay timestamp check fails."""
94
+
95
+ def __init__(
96
+ self,
97
+ message: str,
98
+ *,
99
+ sig_header: str | None = None,
100
+ payload: str | bytes | None = None,
101
+ ) -> None:
102
+ super().__init__(message, error_type="signature_verification_error")
103
+ self.sig_header = sig_header
104
+ self.payload = payload