vexpay 0.1.0__tar.gz
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.
- vexpay-0.1.0/.gitignore +6 -0
- vexpay-0.1.0/LICENSE +21 -0
- vexpay-0.1.0/PKG-INFO +274 -0
- vexpay-0.1.0/README.md +248 -0
- vexpay-0.1.0/pyproject.toml +59 -0
- vexpay-0.1.0/src/vexpay/__init__.py +58 -0
- vexpay-0.1.0/src/vexpay/_async_resources.py +515 -0
- vexpay-0.1.0/src/vexpay/_client.py +112 -0
- vexpay-0.1.0/src/vexpay/_core.py +298 -0
- vexpay-0.1.0/src/vexpay/_errors.py +109 -0
- vexpay-0.1.0/src/vexpay/_generated/__init__.py +0 -0
- vexpay-0.1.0/src/vexpay/_generated/models.py +1515 -0
- vexpay-0.1.0/src/vexpay/_generated/routes.py +137 -0
- vexpay-0.1.0/src/vexpay/_pagination.py +107 -0
- vexpay-0.1.0/src/vexpay/_resource.py +79 -0
- vexpay-0.1.0/src/vexpay/_resources.py +516 -0
- vexpay-0.1.0/src/vexpay/_version.py +1 -0
- vexpay-0.1.0/src/vexpay/_webhooks.py +201 -0
- vexpay-0.1.0/src/vexpay/py.typed +0 -0
vexpay-0.1.0/.gitignore
ADDED
vexpay-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 VEXPay
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
vexpay-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: vexpay
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for the VEXPay API — Venezuelan payments (Pago Móvil C2P, cards, débito inmediato), payouts, checkout sessions, and signed webhooks.
|
|
5
|
+
Project-URL: Homepage, https://github.com/chuventures/vexpay-python
|
|
6
|
+
Project-URL: Issues, https://github.com/chuventures/vexpay-python/issues
|
|
7
|
+
Author: VEXPay
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: bolivares,c2p,pago movil,payments,sdk,venezuela,vexpay
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: httpx<1,>=0.25
|
|
23
|
+
Requires-Dist: pydantic<3,>=2.5
|
|
24
|
+
Requires-Dist: typing-extensions>=4.7
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# VEXPay Python SDK
|
|
28
|
+
|
|
29
|
+
The official Python library for the [VEXPay](https://vexwallet.co/vexpay) API: accept Venezuelan payments (Pago Móvil C2P, cards, débito inmediato), pay out to merchants, create checkout sessions, and verify signed webhooks.
|
|
30
|
+
|
|
31
|
+
- Sync (`VexPay`) and async (`AsyncVexPay`) clients with the same methods
|
|
32
|
+
- Typed Pydantic v2 models generated from the VEXPay OpenAPI contract
|
|
33
|
+
- Safe retries: every `POST` carries an `Idempotency-Key`, so a retried charge never charges twice
|
|
34
|
+
- Auto-pagination
|
|
35
|
+
- Webhook signature verification with replay protection
|
|
36
|
+
- Python 3.9+
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
pip install vexpay
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quickstart
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from vexpay import VexPay
|
|
48
|
+
|
|
49
|
+
vexpay = VexPay() # reads VEXPAY_API_KEY from the environment
|
|
50
|
+
|
|
51
|
+
quote = vexpay.quotes.retrieve({"usdAmount": 25})
|
|
52
|
+
print(f"$25 = Bs {quote.vesAmount} at BCV {quote.bcvRate}")
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Keep your API key on the server. Use your test-mode key while you build; it runs against the sandbox provider. Request bodies and query parameters use the API's field names (`usdAmount`, `debtorBankCode`, …) — pass a `dict` or one of the models in `vexpay._generated.models`.
|
|
56
|
+
|
|
57
|
+
## Collect a Pago Móvil C2P payment
|
|
58
|
+
|
|
59
|
+
C2P is two steps: create an intent (the payer's bank sends them a token by SMS), then charge with the token your customer types in.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from vexpay import VexPay
|
|
63
|
+
|
|
64
|
+
vexpay = VexPay()
|
|
65
|
+
|
|
66
|
+
payer = {
|
|
67
|
+
"usdAmount": 25,
|
|
68
|
+
"debtorId": "V12345678",
|
|
69
|
+
"debtorCellPhone": "584141234567",
|
|
70
|
+
"debtorBankCode": 102,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
intent = vexpay.payments.c2p.request({**payer, "externalRef": "order-1042"})
|
|
74
|
+
|
|
75
|
+
token = input("Bank token: ") # the customer reads it from their bank SMS
|
|
76
|
+
|
|
77
|
+
payment = vexpay.payments.c2p.execute({**payer, "intentId": intent.intentId, "token": token})
|
|
78
|
+
print(payment.paymentId, payment.status) # "COMPLETED" or "PENDING" — confirm with the payment.* webhook
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Checkout sessions (hosted or embedded)
|
|
82
|
+
|
|
83
|
+
Let VEXPay collect the payment details. Redirect the buyer to `url`, or embed the checkout on your own site with [`@vexpay/js`](https://www.npmjs.com/package/@vexpay/js) and the one-time `clientSecret`.
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from vexpay import VexPay
|
|
87
|
+
|
|
88
|
+
vexpay = VexPay()
|
|
89
|
+
|
|
90
|
+
session = vexpay.checkout.sessions.create(
|
|
91
|
+
{
|
|
92
|
+
"amountUsd": 25,
|
|
93
|
+
"reference": "order-1042",
|
|
94
|
+
"description": "Pedido #1042",
|
|
95
|
+
"successUrl": "https://shop.example/gracias",
|
|
96
|
+
"metadata": {"orderId": "1042"},
|
|
97
|
+
}
|
|
98
|
+
)
|
|
99
|
+
print(session.url) # redirect here, or send session.clientSecret to the browser (never log or store it)
|
|
100
|
+
|
|
101
|
+
# Later — fulfil only after checking on the server:
|
|
102
|
+
current = vexpay.checkout.sessions.retrieve(session.id)
|
|
103
|
+
if current.status == "paid":
|
|
104
|
+
print("ship order 1042")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Webhooks
|
|
108
|
+
|
|
109
|
+
VEXPay signs every delivery with a `VexPay-Signature` header. Verify it with the **raw** request body — parsing and re-serializing JSON changes the bytes and breaks the signature (Flask: `request.get_data()`, Django: `request.body`, FastAPI: `await request.body()`).
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import os
|
|
113
|
+
from typing import Optional
|
|
114
|
+
|
|
115
|
+
from vexpay import PaymentEvent, SignatureVerificationError, Webhook
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def handle_webhook(raw_body: bytes, signature: Optional[str]) -> int:
|
|
119
|
+
"""Framework-agnostic handler: returns the HTTP status to answer with."""
|
|
120
|
+
try:
|
|
121
|
+
event = Webhook.construct_event(raw_body, signature, os.environ["VEXPAY_WEBHOOK_SECRET"])
|
|
122
|
+
except SignatureVerificationError:
|
|
123
|
+
return 400
|
|
124
|
+
|
|
125
|
+
if isinstance(event, PaymentEvent) and event.event == "payment.completed":
|
|
126
|
+
data = event.data
|
|
127
|
+
reference = data.externalRef or (data.checkoutSession.reference if data.checkoutSession else None)
|
|
128
|
+
print("paid", data.paymentId, reference)
|
|
129
|
+
return 204
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Deliveries older than 5 minutes are rejected as possible replays; pass `tolerance=` (seconds) to change that. Each delivery also carries a `VexPay-Event-Id` header you can use to deduplicate. In your own tests, sign fixtures with `Webhook.generate_test_header(payload, secret)`.
|
|
133
|
+
|
|
134
|
+
## Errors
|
|
135
|
+
|
|
136
|
+
Every error extends `VexPayError` and carries `status`, the API `code` (e.g. `insufficient_balance`), and the response `body`.
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from vexpay import ConflictError, InvalidRequestError, NotFoundError, VexPay, VexPayError
|
|
140
|
+
|
|
141
|
+
vexpay = VexPay()
|
|
142
|
+
|
|
143
|
+
try:
|
|
144
|
+
vexpay.payouts.create(
|
|
145
|
+
{
|
|
146
|
+
"merchantId": "4f0c6f1e-2b7d-4c1a-9e3f-5a6b7c8d9e0f",
|
|
147
|
+
"monto": "1523.40",
|
|
148
|
+
"concepto": "Liquidación semana 30",
|
|
149
|
+
"externalRef": "po_2026_30_maria",
|
|
150
|
+
}
|
|
151
|
+
)
|
|
152
|
+
except InvalidRequestError as error:
|
|
153
|
+
print("fix the request:", error.code, error.message)
|
|
154
|
+
except NotFoundError:
|
|
155
|
+
print("no such merchant")
|
|
156
|
+
except ConflictError as error:
|
|
157
|
+
print("externalRef reused with a different payload", error.body)
|
|
158
|
+
except VexPayError as error:
|
|
159
|
+
print(error.status, error.code, error.message)
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
| Class | When |
|
|
163
|
+
|---|---|
|
|
164
|
+
| `AuthenticationError` | 401 — missing or invalid API key |
|
|
165
|
+
| `InvalidRequestError` | 400, 403, 410, 422 — fix the request |
|
|
166
|
+
| `NotFoundError` | 404 |
|
|
167
|
+
| `ConflictError` | 409 — e.g. `external_ref_conflict`, `idempotency_key_reused` |
|
|
168
|
+
| `RateLimitError` | 429, after retries |
|
|
169
|
+
| `APIError` | 5xx, after retries |
|
|
170
|
+
| `APIConnectionError` / `APITimeoutError` | no HTTP answer, after retries |
|
|
171
|
+
| `SignatureVerificationError` | a webhook did not verify |
|
|
172
|
+
|
|
173
|
+
## Retries and idempotency
|
|
174
|
+
|
|
175
|
+
The SDK retries connection errors, timeouts, `429`, `5xx`, and `409 idempotency_request_in_progress` up to `max_network_retries` times (default 2) with exponential backoff, honouring `Retry-After`. Every `POST` gets a random `Idempotency-Key` that stays the same across its retries. Supply your own to make retries safe across process restarts too:
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from vexpay import VexPay
|
|
179
|
+
|
|
180
|
+
vexpay = VexPay(max_network_retries=3, timeout=20.0)
|
|
181
|
+
|
|
182
|
+
quote = vexpay.quotes.retrieve({"usdAmount": 10}, timeout=5.0)
|
|
183
|
+
session = vexpay.checkout.sessions.create(
|
|
184
|
+
{"amountUsd": 10, "reference": "order-1043"},
|
|
185
|
+
idempotency_key="order-1043-session",
|
|
186
|
+
)
|
|
187
|
+
print(quote.vesAmount, session.id)
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Pagination
|
|
191
|
+
|
|
192
|
+
`list()` on payouts, merchants, and products returns the first page; iterate it to walk every item across pages:
|
|
193
|
+
|
|
194
|
+
```python
|
|
195
|
+
from vexpay import VexPay
|
|
196
|
+
|
|
197
|
+
vexpay = VexPay()
|
|
198
|
+
|
|
199
|
+
page = vexpay.merchants.list({"limit": 100})
|
|
200
|
+
print(len(page.items), page.next_cursor)
|
|
201
|
+
|
|
202
|
+
for merchant in vexpay.merchants.list({"status": "verified", "isActive": "true"}):
|
|
203
|
+
print(merchant.merchantId, merchant.name)
|
|
204
|
+
|
|
205
|
+
recent = vexpay.payouts.list({"limit": 50}).to_list(limit=200)
|
|
206
|
+
print(len(recent))
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Async
|
|
210
|
+
|
|
211
|
+
`AsyncVexPay` has the same resources; await the calls, and use `async for` to paginate:
|
|
212
|
+
|
|
213
|
+
```python
|
|
214
|
+
import asyncio
|
|
215
|
+
|
|
216
|
+
from vexpay import AsyncVexPay
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
async def main() -> None:
|
|
220
|
+
async with AsyncVexPay() as vexpay:
|
|
221
|
+
banks = await vexpay.banks.list()
|
|
222
|
+
print(len(banks), "banks")
|
|
223
|
+
|
|
224
|
+
first_page = await vexpay.products.list({"limit": 10})
|
|
225
|
+
print(len(first_page.items))
|
|
226
|
+
|
|
227
|
+
async for payout in vexpay.payouts.list():
|
|
228
|
+
print(payout.payoutId, payout.status)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
asyncio.run(main())
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Configuration
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
from vexpay import VexPay
|
|
238
|
+
|
|
239
|
+
with VexPay(
|
|
240
|
+
api_key="sk_test_…", # default: VEXPAY_API_KEY env var
|
|
241
|
+
base_url="http://localhost:3010", # default: https://api.pay.vexwallet.co
|
|
242
|
+
timeout=30.0,
|
|
243
|
+
max_network_retries=2,
|
|
244
|
+
) as vexpay:
|
|
245
|
+
print(len(vexpay.banks.list()), "banks")
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
Pass `http_client=httpx.Client(...)` (or `httpx.AsyncClient`) to control proxies, connection pooling, or instrumentation.
|
|
249
|
+
|
|
250
|
+
## Resources
|
|
251
|
+
|
|
252
|
+
| Namespace | Methods |
|
|
253
|
+
|---|---|
|
|
254
|
+
| `banks` | `list` |
|
|
255
|
+
| `quotes` | `retrieve` |
|
|
256
|
+
| `balance` | `retrieve` |
|
|
257
|
+
| `payments` | `retrieve`, `retrieve_by_ref`, `reverse` |
|
|
258
|
+
| `payments.c2p` | `request`, `execute` |
|
|
259
|
+
| `payments.vpos` | `create` |
|
|
260
|
+
| `payments.pago_movil` | `verify` |
|
|
261
|
+
| `payments.debit` · `credit` · `operations` · `dispersals` · `change` | débito/crédito inmediato and disbursements (R4) |
|
|
262
|
+
| `checkout.sessions` | `create`, `retrieve` |
|
|
263
|
+
| `merchants` | `create`, `list`, `retrieve`, `retrieve_by_ref`, `update`, `delete`, `retrieve_balance`, `transfer`, `list_audit_events`, `start_verification`, `confirm_verification` |
|
|
264
|
+
| `merchants.payout_methods` | `list`, `create`, `set_default`, `delete`, `start_verification`, `confirm_verification` |
|
|
265
|
+
| `payouts` | `create`, `create_instant`, `create_batch`, `list`, `retrieve`, `retrieve_by_ref` |
|
|
266
|
+
| `products` | `create`, `list`, `retrieve`, `update`, `delete`, `create_link`, `list_links` |
|
|
267
|
+
| `payment_links` | `retrieve`, `update`, `delete` |
|
|
268
|
+
| `tenant_payout_account` | `retrieve`, `upsert`, `create`, `start_verification`, `confirm_verification` |
|
|
269
|
+
| `webhook_endpoints` | `create`, `list`, `update`, `delete`, `send_test` |
|
|
270
|
+
| `Webhook` / `client.webhooks` | `construct_event`, `generate_test_header` (offline) |
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
MIT
|
vexpay-0.1.0/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# VEXPay Python SDK
|
|
2
|
+
|
|
3
|
+
The official Python library for the [VEXPay](https://vexwallet.co/vexpay) API: accept Venezuelan payments (Pago Móvil C2P, cards, débito inmediato), pay out to merchants, create checkout sessions, and verify signed webhooks.
|
|
4
|
+
|
|
5
|
+
- Sync (`VexPay`) and async (`AsyncVexPay`) clients with the same methods
|
|
6
|
+
- Typed Pydantic v2 models generated from the VEXPay OpenAPI contract
|
|
7
|
+
- Safe retries: every `POST` carries an `Idempotency-Key`, so a retried charge never charges twice
|
|
8
|
+
- Auto-pagination
|
|
9
|
+
- Webhook signature verification with replay protection
|
|
10
|
+
- Python 3.9+
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pip install vexpay
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quickstart
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from vexpay import VexPay
|
|
22
|
+
|
|
23
|
+
vexpay = VexPay() # reads VEXPAY_API_KEY from the environment
|
|
24
|
+
|
|
25
|
+
quote = vexpay.quotes.retrieve({"usdAmount": 25})
|
|
26
|
+
print(f"$25 = Bs {quote.vesAmount} at BCV {quote.bcvRate}")
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Keep your API key on the server. Use your test-mode key while you build; it runs against the sandbox provider. Request bodies and query parameters use the API's field names (`usdAmount`, `debtorBankCode`, …) — pass a `dict` or one of the models in `vexpay._generated.models`.
|
|
30
|
+
|
|
31
|
+
## Collect a Pago Móvil C2P payment
|
|
32
|
+
|
|
33
|
+
C2P is two steps: create an intent (the payer's bank sends them a token by SMS), then charge with the token your customer types in.
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from vexpay import VexPay
|
|
37
|
+
|
|
38
|
+
vexpay = VexPay()
|
|
39
|
+
|
|
40
|
+
payer = {
|
|
41
|
+
"usdAmount": 25,
|
|
42
|
+
"debtorId": "V12345678",
|
|
43
|
+
"debtorCellPhone": "584141234567",
|
|
44
|
+
"debtorBankCode": 102,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
intent = vexpay.payments.c2p.request({**payer, "externalRef": "order-1042"})
|
|
48
|
+
|
|
49
|
+
token = input("Bank token: ") # the customer reads it from their bank SMS
|
|
50
|
+
|
|
51
|
+
payment = vexpay.payments.c2p.execute({**payer, "intentId": intent.intentId, "token": token})
|
|
52
|
+
print(payment.paymentId, payment.status) # "COMPLETED" or "PENDING" — confirm with the payment.* webhook
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Checkout sessions (hosted or embedded)
|
|
56
|
+
|
|
57
|
+
Let VEXPay collect the payment details. Redirect the buyer to `url`, or embed the checkout on your own site with [`@vexpay/js`](https://www.npmjs.com/package/@vexpay/js) and the one-time `clientSecret`.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from vexpay import VexPay
|
|
61
|
+
|
|
62
|
+
vexpay = VexPay()
|
|
63
|
+
|
|
64
|
+
session = vexpay.checkout.sessions.create(
|
|
65
|
+
{
|
|
66
|
+
"amountUsd": 25,
|
|
67
|
+
"reference": "order-1042",
|
|
68
|
+
"description": "Pedido #1042",
|
|
69
|
+
"successUrl": "https://shop.example/gracias",
|
|
70
|
+
"metadata": {"orderId": "1042"},
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
print(session.url) # redirect here, or send session.clientSecret to the browser (never log or store it)
|
|
74
|
+
|
|
75
|
+
# Later — fulfil only after checking on the server:
|
|
76
|
+
current = vexpay.checkout.sessions.retrieve(session.id)
|
|
77
|
+
if current.status == "paid":
|
|
78
|
+
print("ship order 1042")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Webhooks
|
|
82
|
+
|
|
83
|
+
VEXPay signs every delivery with a `VexPay-Signature` header. Verify it with the **raw** request body — parsing and re-serializing JSON changes the bytes and breaks the signature (Flask: `request.get_data()`, Django: `request.body`, FastAPI: `await request.body()`).
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
import os
|
|
87
|
+
from typing import Optional
|
|
88
|
+
|
|
89
|
+
from vexpay import PaymentEvent, SignatureVerificationError, Webhook
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def handle_webhook(raw_body: bytes, signature: Optional[str]) -> int:
|
|
93
|
+
"""Framework-agnostic handler: returns the HTTP status to answer with."""
|
|
94
|
+
try:
|
|
95
|
+
event = Webhook.construct_event(raw_body, signature, os.environ["VEXPAY_WEBHOOK_SECRET"])
|
|
96
|
+
except SignatureVerificationError:
|
|
97
|
+
return 400
|
|
98
|
+
|
|
99
|
+
if isinstance(event, PaymentEvent) and event.event == "payment.completed":
|
|
100
|
+
data = event.data
|
|
101
|
+
reference = data.externalRef or (data.checkoutSession.reference if data.checkoutSession else None)
|
|
102
|
+
print("paid", data.paymentId, reference)
|
|
103
|
+
return 204
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Deliveries older than 5 minutes are rejected as possible replays; pass `tolerance=` (seconds) to change that. Each delivery also carries a `VexPay-Event-Id` header you can use to deduplicate. In your own tests, sign fixtures with `Webhook.generate_test_header(payload, secret)`.
|
|
107
|
+
|
|
108
|
+
## Errors
|
|
109
|
+
|
|
110
|
+
Every error extends `VexPayError` and carries `status`, the API `code` (e.g. `insufficient_balance`), and the response `body`.
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from vexpay import ConflictError, InvalidRequestError, NotFoundError, VexPay, VexPayError
|
|
114
|
+
|
|
115
|
+
vexpay = VexPay()
|
|
116
|
+
|
|
117
|
+
try:
|
|
118
|
+
vexpay.payouts.create(
|
|
119
|
+
{
|
|
120
|
+
"merchantId": "4f0c6f1e-2b7d-4c1a-9e3f-5a6b7c8d9e0f",
|
|
121
|
+
"monto": "1523.40",
|
|
122
|
+
"concepto": "Liquidación semana 30",
|
|
123
|
+
"externalRef": "po_2026_30_maria",
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
except InvalidRequestError as error:
|
|
127
|
+
print("fix the request:", error.code, error.message)
|
|
128
|
+
except NotFoundError:
|
|
129
|
+
print("no such merchant")
|
|
130
|
+
except ConflictError as error:
|
|
131
|
+
print("externalRef reused with a different payload", error.body)
|
|
132
|
+
except VexPayError as error:
|
|
133
|
+
print(error.status, error.code, error.message)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
| Class | When |
|
|
137
|
+
|---|---|
|
|
138
|
+
| `AuthenticationError` | 401 — missing or invalid API key |
|
|
139
|
+
| `InvalidRequestError` | 400, 403, 410, 422 — fix the request |
|
|
140
|
+
| `NotFoundError` | 404 |
|
|
141
|
+
| `ConflictError` | 409 — e.g. `external_ref_conflict`, `idempotency_key_reused` |
|
|
142
|
+
| `RateLimitError` | 429, after retries |
|
|
143
|
+
| `APIError` | 5xx, after retries |
|
|
144
|
+
| `APIConnectionError` / `APITimeoutError` | no HTTP answer, after retries |
|
|
145
|
+
| `SignatureVerificationError` | a webhook did not verify |
|
|
146
|
+
|
|
147
|
+
## Retries and idempotency
|
|
148
|
+
|
|
149
|
+
The SDK retries connection errors, timeouts, `429`, `5xx`, and `409 idempotency_request_in_progress` up to `max_network_retries` times (default 2) with exponential backoff, honouring `Retry-After`. Every `POST` gets a random `Idempotency-Key` that stays the same across its retries. Supply your own to make retries safe across process restarts too:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from vexpay import VexPay
|
|
153
|
+
|
|
154
|
+
vexpay = VexPay(max_network_retries=3, timeout=20.0)
|
|
155
|
+
|
|
156
|
+
quote = vexpay.quotes.retrieve({"usdAmount": 10}, timeout=5.0)
|
|
157
|
+
session = vexpay.checkout.sessions.create(
|
|
158
|
+
{"amountUsd": 10, "reference": "order-1043"},
|
|
159
|
+
idempotency_key="order-1043-session",
|
|
160
|
+
)
|
|
161
|
+
print(quote.vesAmount, session.id)
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Pagination
|
|
165
|
+
|
|
166
|
+
`list()` on payouts, merchants, and products returns the first page; iterate it to walk every item across pages:
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from vexpay import VexPay
|
|
170
|
+
|
|
171
|
+
vexpay = VexPay()
|
|
172
|
+
|
|
173
|
+
page = vexpay.merchants.list({"limit": 100})
|
|
174
|
+
print(len(page.items), page.next_cursor)
|
|
175
|
+
|
|
176
|
+
for merchant in vexpay.merchants.list({"status": "verified", "isActive": "true"}):
|
|
177
|
+
print(merchant.merchantId, merchant.name)
|
|
178
|
+
|
|
179
|
+
recent = vexpay.payouts.list({"limit": 50}).to_list(limit=200)
|
|
180
|
+
print(len(recent))
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Async
|
|
184
|
+
|
|
185
|
+
`AsyncVexPay` has the same resources; await the calls, and use `async for` to paginate:
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
import asyncio
|
|
189
|
+
|
|
190
|
+
from vexpay import AsyncVexPay
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
async def main() -> None:
|
|
194
|
+
async with AsyncVexPay() as vexpay:
|
|
195
|
+
banks = await vexpay.banks.list()
|
|
196
|
+
print(len(banks), "banks")
|
|
197
|
+
|
|
198
|
+
first_page = await vexpay.products.list({"limit": 10})
|
|
199
|
+
print(len(first_page.items))
|
|
200
|
+
|
|
201
|
+
async for payout in vexpay.payouts.list():
|
|
202
|
+
print(payout.payoutId, payout.status)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
asyncio.run(main())
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Configuration
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from vexpay import VexPay
|
|
212
|
+
|
|
213
|
+
with VexPay(
|
|
214
|
+
api_key="sk_test_…", # default: VEXPAY_API_KEY env var
|
|
215
|
+
base_url="http://localhost:3010", # default: https://api.pay.vexwallet.co
|
|
216
|
+
timeout=30.0,
|
|
217
|
+
max_network_retries=2,
|
|
218
|
+
) as vexpay:
|
|
219
|
+
print(len(vexpay.banks.list()), "banks")
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Pass `http_client=httpx.Client(...)` (or `httpx.AsyncClient`) to control proxies, connection pooling, or instrumentation.
|
|
223
|
+
|
|
224
|
+
## Resources
|
|
225
|
+
|
|
226
|
+
| Namespace | Methods |
|
|
227
|
+
|---|---|
|
|
228
|
+
| `banks` | `list` |
|
|
229
|
+
| `quotes` | `retrieve` |
|
|
230
|
+
| `balance` | `retrieve` |
|
|
231
|
+
| `payments` | `retrieve`, `retrieve_by_ref`, `reverse` |
|
|
232
|
+
| `payments.c2p` | `request`, `execute` |
|
|
233
|
+
| `payments.vpos` | `create` |
|
|
234
|
+
| `payments.pago_movil` | `verify` |
|
|
235
|
+
| `payments.debit` · `credit` · `operations` · `dispersals` · `change` | débito/crédito inmediato and disbursements (R4) |
|
|
236
|
+
| `checkout.sessions` | `create`, `retrieve` |
|
|
237
|
+
| `merchants` | `create`, `list`, `retrieve`, `retrieve_by_ref`, `update`, `delete`, `retrieve_balance`, `transfer`, `list_audit_events`, `start_verification`, `confirm_verification` |
|
|
238
|
+
| `merchants.payout_methods` | `list`, `create`, `set_default`, `delete`, `start_verification`, `confirm_verification` |
|
|
239
|
+
| `payouts` | `create`, `create_instant`, `create_batch`, `list`, `retrieve`, `retrieve_by_ref` |
|
|
240
|
+
| `products` | `create`, `list`, `retrieve`, `update`, `delete`, `create_link`, `list_links` |
|
|
241
|
+
| `payment_links` | `retrieve`, `update`, `delete` |
|
|
242
|
+
| `tenant_payout_account` | `retrieve`, `upsert`, `create`, `start_verification`, `confirm_verification` |
|
|
243
|
+
| `webhook_endpoints` | `create`, `list`, `update`, `delete`, `send_test` |
|
|
244
|
+
| `Webhook` / `client.webhooks` | `construct_event`, `generate_test_header` (offline) |
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
MIT
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vexpay"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Official Python SDK for the VEXPay API — Venezuelan payments (Pago Móvil C2P, cards, débito inmediato), payouts, checkout sessions, and signed webhooks."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
authors = [{ name = "VEXPay" }]
|
|
14
|
+
keywords = ["vexpay", "venezuela", "payments", "pago movil", "c2p", "bolivares", "sdk"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Typing :: Typed",
|
|
26
|
+
]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"httpx>=0.25,<1",
|
|
29
|
+
"pydantic>=2.5,<3",
|
|
30
|
+
"typing-extensions>=4.7",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.urls]
|
|
34
|
+
Homepage = "https://github.com/chuventures/vexpay-python"
|
|
35
|
+
Issues = "https://github.com/chuventures/vexpay-python/issues"
|
|
36
|
+
|
|
37
|
+
[dependency-groups]
|
|
38
|
+
dev = [
|
|
39
|
+
"pytest>=8",
|
|
40
|
+
"pytest-asyncio>=0.23",
|
|
41
|
+
"mypy>=1.10",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.hatch.build.targets.wheel]
|
|
45
|
+
packages = ["src/vexpay"]
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.sdist]
|
|
48
|
+
include = ["src/vexpay", "README.md", "LICENSE", "pyproject.toml"]
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
testpaths = ["tests"]
|
|
52
|
+
asyncio_mode = "auto"
|
|
53
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
54
|
+
|
|
55
|
+
[tool.mypy]
|
|
56
|
+
strict = true
|
|
57
|
+
python_version = "3.9"
|
|
58
|
+
files = ["src/vexpay"]
|
|
59
|
+
plugins = ["pydantic.mypy"]
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Official Python SDK for the VEXPay API."""
|
|
2
|
+
|
|
3
|
+
from ._client import AsyncVexPay, VexPay
|
|
4
|
+
from ._core import DEFAULT_BASE_URL, RequestOptions
|
|
5
|
+
from ._pagination import AsyncPage, SyncPage
|
|
6
|
+
from ._errors import (
|
|
7
|
+
APIConnectionError,
|
|
8
|
+
APIError,
|
|
9
|
+
APITimeoutError,
|
|
10
|
+
AuthenticationError,
|
|
11
|
+
ConfigurationError,
|
|
12
|
+
ConflictError,
|
|
13
|
+
InvalidRequestError,
|
|
14
|
+
NotFoundError,
|
|
15
|
+
RateLimitError,
|
|
16
|
+
SignatureVerificationError,
|
|
17
|
+
VexPayError,
|
|
18
|
+
)
|
|
19
|
+
from ._version import __version__
|
|
20
|
+
from ._webhooks import (
|
|
21
|
+
DEFAULT_TOLERANCE,
|
|
22
|
+
SIGNATURE_HEADER,
|
|
23
|
+
WEBHOOK_EVENT_NAMES,
|
|
24
|
+
GenericEvent,
|
|
25
|
+
PaymentEvent,
|
|
26
|
+
PaymentWebhookData,
|
|
27
|
+
Webhook,
|
|
28
|
+
WebhookEvent,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
__all__ = [
|
|
32
|
+
"DEFAULT_TOLERANCE",
|
|
33
|
+
"GenericEvent",
|
|
34
|
+
"PaymentEvent",
|
|
35
|
+
"PaymentWebhookData",
|
|
36
|
+
"SIGNATURE_HEADER",
|
|
37
|
+
"WEBHOOK_EVENT_NAMES",
|
|
38
|
+
"Webhook",
|
|
39
|
+
"WebhookEvent",
|
|
40
|
+
"APIConnectionError",
|
|
41
|
+
"APIError",
|
|
42
|
+
"APITimeoutError",
|
|
43
|
+
"AsyncPage",
|
|
44
|
+
"AsyncVexPay",
|
|
45
|
+
"AuthenticationError",
|
|
46
|
+
"ConfigurationError",
|
|
47
|
+
"ConflictError",
|
|
48
|
+
"DEFAULT_BASE_URL",
|
|
49
|
+
"InvalidRequestError",
|
|
50
|
+
"NotFoundError",
|
|
51
|
+
"RateLimitError",
|
|
52
|
+
"RequestOptions",
|
|
53
|
+
"SignatureVerificationError",
|
|
54
|
+
"SyncPage",
|
|
55
|
+
"VexPay",
|
|
56
|
+
"VexPayError",
|
|
57
|
+
"__version__",
|
|
58
|
+
]
|