hexpay 0.0.1__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.
Files changed (41) hide show
  1. hexpay-0.0.1/.gitignore +22 -0
  2. hexpay-0.0.1/PKG-INFO +161 -0
  3. hexpay-0.0.1/README.md +135 -0
  4. hexpay-0.0.1/hexpay/__init__.py +8 -0
  5. hexpay-0.0.1/hexpay/api/__init__.py +1 -0
  6. hexpay-0.0.1/hexpay/api/payment_methods/__init__.py +1 -0
  7. hexpay-0.0.1/hexpay/api/payment_methods/list_payment_methods.py +166 -0
  8. hexpay-0.0.1/hexpay/api/payments/__init__.py +1 -0
  9. hexpay-0.0.1/hexpay/api/payments/cancel_payment.py +222 -0
  10. hexpay-0.0.1/hexpay/api/payments/create_payment.py +338 -0
  11. hexpay-0.0.1/hexpay/api/payments/get_payment.py +235 -0
  12. hexpay-0.0.1/hexpay/api/payments/get_payment_status.py +195 -0
  13. hexpay-0.0.1/hexpay/api/payments/list_payments.py +258 -0
  14. hexpay-0.0.1/hexpay/client.py +268 -0
  15. hexpay-0.0.1/hexpay/errors.py +16 -0
  16. hexpay-0.0.1/hexpay/models/__init__.py +49 -0
  17. hexpay-0.0.1/hexpay/models/chain_response.py +85 -0
  18. hexpay-0.0.1/hexpay/models/chain_response_symbol.py +8 -0
  19. hexpay-0.0.1/hexpay/models/coin_response.py +85 -0
  20. hexpay-0.0.1/hexpay/models/coin_response_symbol.py +17 -0
  21. hexpay-0.0.1/hexpay/models/create_payment_request.py +197 -0
  22. hexpay-0.0.1/hexpay/models/create_payment_request_metadata.py +57 -0
  23. hexpay-0.0.1/hexpay/models/error.py +105 -0
  24. hexpay-0.0.1/hexpay/models/error_response.py +79 -0
  25. hexpay-0.0.1/hexpay/models/error_type.py +12 -0
  26. hexpay-0.0.1/hexpay/models/method_filter.py +80 -0
  27. hexpay-0.0.1/hexpay/models/method_filter_chain.py +8 -0
  28. hexpay-0.0.1/hexpay/models/method_filter_coin.py +17 -0
  29. hexpay-0.0.1/hexpay/models/payment_cancel_response.py +77 -0
  30. hexpay-0.0.1/hexpay/models/payment_details.py +122 -0
  31. hexpay-0.0.1/hexpay/models/payment_list_response.py +95 -0
  32. hexpay-0.0.1/hexpay/models/payment_method_list_response.py +84 -0
  33. hexpay-0.0.1/hexpay/models/payment_method_response.py +97 -0
  34. hexpay-0.0.1/hexpay/models/payment_options.py +92 -0
  35. hexpay-0.0.1/hexpay/models/payment_response.py +177 -0
  36. hexpay-0.0.1/hexpay/models/payment_status.py +12 -0
  37. hexpay-0.0.1/hexpay/models/payment_status_response.py +80 -0
  38. hexpay-0.0.1/hexpay/models/payment_timer_response.py +98 -0
  39. hexpay-0.0.1/hexpay/py.typed +0 -0
  40. hexpay-0.0.1/hexpay/types.py +54 -0
  41. hexpay-0.0.1/pyproject.toml +56 -0
@@ -0,0 +1,22 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .venv/
9
+ venv/
10
+ .mypy_cache/
11
+ .ruff_cache/
12
+ .pytest_cache/
13
+
14
+ # Editors
15
+ .idea/
16
+ .vscode/
17
+ *.swp
18
+ .DS_Store
19
+
20
+ # Local env
21
+ .env
22
+ .env.local
hexpay-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,161 @@
1
+ Metadata-Version: 2.4
2
+ Name: hexpay
3
+ Version: 0.0.1
4
+ Summary: Official Python SDK for the HexPay Merchant API (TON cryptocurrency payments).
5
+ Project-URL: Homepage, https://hexpay.io
6
+ Project-URL: Documentation, https://docs.hexpay.io
7
+ Project-URL: Repository, https://github.com/hexpay-io/hexpay-python
8
+ Project-URL: Issues, https://github.com/hexpay-io/hexpay-python/issues
9
+ Author: HexPay
10
+ License: Proprietary
11
+ Keywords: api,crypto,cryptocurrency,hexpay,payments,sdk,ton
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Office/Business :: Financial
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.9
22
+ Requires-Dist: attrs>=22.2.0
23
+ Requires-Dist: httpx<0.29.0,>=0.23.0
24
+ Requires-Dist: python-dateutil>=2.8.0
25
+ Description-Content-Type: text/markdown
26
+
27
+ # HexPay Python SDK
28
+
29
+ Official Python client for the [HexPay Merchant API](https://hexpay.io) — TON-blockchain
30
+ cryptocurrency payments.
31
+
32
+ The client in [`hexpay/`](hexpay/) is **fully auto-generated** from the OpenAPI spec at
33
+ [`oapi/api.yaml`](oapi/api.yaml). Do not edit it by hand — your changes will be
34
+ overwritten on the next regeneration.
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ pip install "git+https://github.com/hexpay/hexpay-python.git"
40
+ ```
41
+
42
+ Or pin to a release tag:
43
+
44
+ ```bash
45
+ pip install "git+https://github.com/hexpay/hexpay-python.git@v0.0.1"
46
+ ```
47
+
48
+ ## Quickstart
49
+
50
+ ```python
51
+ import os
52
+ import uuid
53
+
54
+ from hexpay import AuthenticatedClient
55
+ from hexpay.api.payments import create_payment
56
+ from hexpay.models import CreatePaymentRequest
57
+
58
+ client = AuthenticatedClient(
59
+ base_url="https://api.hexpay.io",
60
+ token=os.environ["HEXPAY_TOKEN"],
61
+ )
62
+
63
+ payment = create_payment.sync(
64
+ client=client,
65
+ body=CreatePaymentRequest(amount="100.00", currency="USD"),
66
+ x_idempotency_key=str(uuid.uuid4()),
67
+ )
68
+
69
+ print(payment.id, payment.checkout_url)
70
+ ```
71
+
72
+ ## Authentication
73
+
74
+ All endpoints require a JWT obtained from the HexPay merchant dashboard. Pass it as
75
+ the `token` argument to `AuthenticatedClient`. Never hard-code tokens — load them
76
+ from environment variables, a secrets manager, or your config layer.
77
+
78
+ ## Idempotency
79
+
80
+ Every `POST` request requires a UUID v4 `X-Idempotency-Key`. The SDK exposes it as
81
+ the `x_idempotency_key` argument on every mutating operation.
82
+
83
+ **Reuse the same key when retrying** a failed request — the server returns the
84
+ cached response from the first attempt instead of creating a duplicate payment.
85
+ **Generate a fresh key for each new logical operation.**
86
+
87
+ See [`examples/idempotency_retry.py`](examples/idempotency_retry.py) for a complete
88
+ retry loop that gets this right.
89
+
90
+ ## Async
91
+
92
+ Every endpoint exposes both `sync` and `asyncio` entry points:
93
+
94
+ ```python
95
+ import asyncio
96
+ from hexpay.api.payments import list_payments
97
+
98
+ async def main():
99
+ page = await list_payments.asyncio(client=client, limit=20)
100
+ for p in page.payments:
101
+ print(p.id, p.status)
102
+
103
+ asyncio.run(main())
104
+ ```
105
+
106
+ ## Examples
107
+
108
+ Runnable scripts under [`examples/`](examples/) — each is self-contained and reads
109
+ `HEXPAY_TOKEN` (and optionally `HEXPAY_BASE_URL`) from the environment:
110
+
111
+ | File | What it shows |
112
+ |-----------------------------------------------------------------------------------|------------------------------------------------|
113
+ | [`create_payment_customer_choice.py`](examples/create_payment_customer_choice.py) | Customer-Choice mode — checkout picks the method |
114
+ | [`create_payment_preselected.py`](examples/create_payment_preselected.py) | Preselected USDT/TON — `pending` immediately |
115
+ | [`retrieve_payment.py`](examples/retrieve_payment.py) | Fetch full payment details |
116
+ | [`poll_payment_status.py`](examples/poll_payment_status.py) | Lightweight status polling loop |
117
+ | [`list_payments.py`](examples/list_payments.py) | Cursor-based pagination |
118
+ | [`cancel_payment.py`](examples/cancel_payment.py) | Cancel an active payment |
119
+ | [`list_payment_methods.py`](examples/list_payment_methods.py) | Discover store-enabled coin/chain combos |
120
+ | [`error_handling.py`](examples/error_handling.py) | Pattern for inspecting structured errors |
121
+ | [`idempotency_retry.py`](examples/idempotency_retry.py) | Safe retry loop preserving the idempotency key |
122
+
123
+ Run them with:
124
+
125
+ ```bash
126
+ make gen install # generate client + install into .venv/
127
+ export HEXPAY_TOKEN="<your-jwt>"
128
+ .venv/bin/python examples/create_payment_customer_choice.py
129
+ ```
130
+
131
+ Or activate the venv once and use plain `python`:
132
+
133
+ ```bash
134
+ source .venv/bin/activate
135
+ python examples/create_payment_customer_choice.py
136
+ ```
137
+
138
+ ## Regeneration
139
+
140
+ ```bash
141
+ make gen # rebuild hexpay/ from oapi/api.yaml — runs in Docker
142
+ make install # editable install into a local venv
143
+ make lint # ruff check
144
+ ```
145
+
146
+ `make gen` builds a small image from [`gen.Dockerfile`](gen.Dockerfile)
147
+ (based on `python:3.12-slim` with
148
+ [`openapi-python-client`](https://github.com/openapi-generators/openapi-python-client)
149
+ preinstalled) and runs it against the spec — no host Python required. The
150
+ generator version is pinned by `OPENAPI_PYTHON_CLIENT_VERSION` in the
151
+ Dockerfile.
152
+
153
+ CI ([`.github/workflows/generate.yml`](.github/workflows/generate.yml)) runs the
154
+ same `make gen` on every push to a non-`main` branch and commits the regenerated
155
+ client back to the branch.
156
+
157
+ ## Compatibility
158
+
159
+ - Python ≥ 3.9
160
+ - httpx ≥ 0.23, < 0.29
161
+ - Type hints throughout (`py.typed`)
hexpay-0.0.1/README.md ADDED
@@ -0,0 +1,135 @@
1
+ # HexPay Python SDK
2
+
3
+ Official Python client for the [HexPay Merchant API](https://hexpay.io) — TON-blockchain
4
+ cryptocurrency payments.
5
+
6
+ The client in [`hexpay/`](hexpay/) is **fully auto-generated** from the OpenAPI spec at
7
+ [`oapi/api.yaml`](oapi/api.yaml). Do not edit it by hand — your changes will be
8
+ overwritten on the next regeneration.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pip install "git+https://github.com/hexpay/hexpay-python.git"
14
+ ```
15
+
16
+ Or pin to a release tag:
17
+
18
+ ```bash
19
+ pip install "git+https://github.com/hexpay/hexpay-python.git@v0.0.1"
20
+ ```
21
+
22
+ ## Quickstart
23
+
24
+ ```python
25
+ import os
26
+ import uuid
27
+
28
+ from hexpay import AuthenticatedClient
29
+ from hexpay.api.payments import create_payment
30
+ from hexpay.models import CreatePaymentRequest
31
+
32
+ client = AuthenticatedClient(
33
+ base_url="https://api.hexpay.io",
34
+ token=os.environ["HEXPAY_TOKEN"],
35
+ )
36
+
37
+ payment = create_payment.sync(
38
+ client=client,
39
+ body=CreatePaymentRequest(amount="100.00", currency="USD"),
40
+ x_idempotency_key=str(uuid.uuid4()),
41
+ )
42
+
43
+ print(payment.id, payment.checkout_url)
44
+ ```
45
+
46
+ ## Authentication
47
+
48
+ All endpoints require a JWT obtained from the HexPay merchant dashboard. Pass it as
49
+ the `token` argument to `AuthenticatedClient`. Never hard-code tokens — load them
50
+ from environment variables, a secrets manager, or your config layer.
51
+
52
+ ## Idempotency
53
+
54
+ Every `POST` request requires a UUID v4 `X-Idempotency-Key`. The SDK exposes it as
55
+ the `x_idempotency_key` argument on every mutating operation.
56
+
57
+ **Reuse the same key when retrying** a failed request — the server returns the
58
+ cached response from the first attempt instead of creating a duplicate payment.
59
+ **Generate a fresh key for each new logical operation.**
60
+
61
+ See [`examples/idempotency_retry.py`](examples/idempotency_retry.py) for a complete
62
+ retry loop that gets this right.
63
+
64
+ ## Async
65
+
66
+ Every endpoint exposes both `sync` and `asyncio` entry points:
67
+
68
+ ```python
69
+ import asyncio
70
+ from hexpay.api.payments import list_payments
71
+
72
+ async def main():
73
+ page = await list_payments.asyncio(client=client, limit=20)
74
+ for p in page.payments:
75
+ print(p.id, p.status)
76
+
77
+ asyncio.run(main())
78
+ ```
79
+
80
+ ## Examples
81
+
82
+ Runnable scripts under [`examples/`](examples/) — each is self-contained and reads
83
+ `HEXPAY_TOKEN` (and optionally `HEXPAY_BASE_URL`) from the environment:
84
+
85
+ | File | What it shows |
86
+ |-----------------------------------------------------------------------------------|------------------------------------------------|
87
+ | [`create_payment_customer_choice.py`](examples/create_payment_customer_choice.py) | Customer-Choice mode — checkout picks the method |
88
+ | [`create_payment_preselected.py`](examples/create_payment_preselected.py) | Preselected USDT/TON — `pending` immediately |
89
+ | [`retrieve_payment.py`](examples/retrieve_payment.py) | Fetch full payment details |
90
+ | [`poll_payment_status.py`](examples/poll_payment_status.py) | Lightweight status polling loop |
91
+ | [`list_payments.py`](examples/list_payments.py) | Cursor-based pagination |
92
+ | [`cancel_payment.py`](examples/cancel_payment.py) | Cancel an active payment |
93
+ | [`list_payment_methods.py`](examples/list_payment_methods.py) | Discover store-enabled coin/chain combos |
94
+ | [`error_handling.py`](examples/error_handling.py) | Pattern for inspecting structured errors |
95
+ | [`idempotency_retry.py`](examples/idempotency_retry.py) | Safe retry loop preserving the idempotency key |
96
+
97
+ Run them with:
98
+
99
+ ```bash
100
+ make gen install # generate client + install into .venv/
101
+ export HEXPAY_TOKEN="<your-jwt>"
102
+ .venv/bin/python examples/create_payment_customer_choice.py
103
+ ```
104
+
105
+ Or activate the venv once and use plain `python`:
106
+
107
+ ```bash
108
+ source .venv/bin/activate
109
+ python examples/create_payment_customer_choice.py
110
+ ```
111
+
112
+ ## Regeneration
113
+
114
+ ```bash
115
+ make gen # rebuild hexpay/ from oapi/api.yaml — runs in Docker
116
+ make install # editable install into a local venv
117
+ make lint # ruff check
118
+ ```
119
+
120
+ `make gen` builds a small image from [`gen.Dockerfile`](gen.Dockerfile)
121
+ (based on `python:3.12-slim` with
122
+ [`openapi-python-client`](https://github.com/openapi-generators/openapi-python-client)
123
+ preinstalled) and runs it against the spec — no host Python required. The
124
+ generator version is pinned by `OPENAPI_PYTHON_CLIENT_VERSION` in the
125
+ Dockerfile.
126
+
127
+ CI ([`.github/workflows/generate.yml`](.github/workflows/generate.yml)) runs the
128
+ same `make gen` on every push to a non-`main` branch and commits the regenerated
129
+ client back to the branch.
130
+
131
+ ## Compatibility
132
+
133
+ - Python ≥ 3.9
134
+ - httpx ≥ 0.23, < 0.29
135
+ - Type hints throughout (`py.typed`)
@@ -0,0 +1,8 @@
1
+ """A client library for accessing HexPay Merchant API"""
2
+
3
+ from .client import AuthenticatedClient, Client
4
+
5
+ __all__ = (
6
+ "AuthenticatedClient",
7
+ "Client",
8
+ )
@@ -0,0 +1 @@
1
+ """Contains methods for accessing the API"""
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,166 @@
1
+ from http import HTTPStatus
2
+ from typing import Any, cast
3
+ from urllib.parse import quote
4
+
5
+ import httpx
6
+
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...types import Response, UNSET
9
+ from ... import errors
10
+
11
+ from ...models.error_response import ErrorResponse
12
+ from ...models.payment_method_list_response import PaymentMethodListResponse
13
+ from typing import cast
14
+
15
+
16
+ def _get_kwargs() -> dict[str, Any]:
17
+
18
+ _kwargs: dict[str, Any] = {
19
+ "method": "get",
20
+ "url": "/v1/payment-methods",
21
+ }
22
+
23
+ return _kwargs
24
+
25
+
26
+ def _parse_response(
27
+ *, client: AuthenticatedClient | Client, response: httpx.Response
28
+ ) -> ErrorResponse | PaymentMethodListResponse | None:
29
+ if response.status_code == 200:
30
+ response_200 = PaymentMethodListResponse.from_dict(response.json())
31
+
32
+ return response_200
33
+
34
+ if response.status_code == 401:
35
+ response_401 = ErrorResponse.from_dict(response.json())
36
+
37
+ return response_401
38
+
39
+ if response.status_code == 500:
40
+ response_500 = ErrorResponse.from_dict(response.json())
41
+
42
+ return response_500
43
+
44
+ if client.raise_on_unexpected_status:
45
+ raise errors.UnexpectedStatus(response.status_code, response.content)
46
+ else:
47
+ return None
48
+
49
+
50
+ def _build_response(
51
+ *, client: AuthenticatedClient | Client, response: httpx.Response
52
+ ) -> Response[ErrorResponse | PaymentMethodListResponse]:
53
+ return Response(
54
+ status_code=HTTPStatus(response.status_code),
55
+ content=response.content,
56
+ headers=response.headers,
57
+ parsed=_parse_response(client=client, response=response),
58
+ )
59
+
60
+
61
+ def sync_detailed(
62
+ *,
63
+ client: AuthenticatedClient | Client,
64
+ ) -> Response[ErrorResponse | PaymentMethodListResponse]:
65
+ """List payment methods
66
+
67
+ Retrieves all payment methods enabled for your store. Each entry represents
68
+ a unique coin + chain combination that your store accepts.
69
+
70
+ Use `coin.symbol` and `chain.symbol` values from this response as inputs for
71
+ the `coin` and `chain` fields in `payment_options.methods` when creating a payment.
72
+
73
+ Raises:
74
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
75
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
76
+
77
+ Returns:
78
+ Response[ErrorResponse | PaymentMethodListResponse]
79
+ """
80
+
81
+ kwargs = _get_kwargs()
82
+
83
+ response = client.get_httpx_client().request(
84
+ **kwargs,
85
+ )
86
+
87
+ return _build_response(client=client, response=response)
88
+
89
+
90
+ def sync(
91
+ *,
92
+ client: AuthenticatedClient | Client,
93
+ ) -> ErrorResponse | PaymentMethodListResponse | None:
94
+ """List payment methods
95
+
96
+ Retrieves all payment methods enabled for your store. Each entry represents
97
+ a unique coin + chain combination that your store accepts.
98
+
99
+ Use `coin.symbol` and `chain.symbol` values from this response as inputs for
100
+ the `coin` and `chain` fields in `payment_options.methods` when creating a payment.
101
+
102
+ Raises:
103
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
104
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
105
+
106
+ Returns:
107
+ ErrorResponse | PaymentMethodListResponse
108
+ """
109
+
110
+ return sync_detailed(
111
+ client=client,
112
+ ).parsed
113
+
114
+
115
+ async def asyncio_detailed(
116
+ *,
117
+ client: AuthenticatedClient | Client,
118
+ ) -> Response[ErrorResponse | PaymentMethodListResponse]:
119
+ """List payment methods
120
+
121
+ Retrieves all payment methods enabled for your store. Each entry represents
122
+ a unique coin + chain combination that your store accepts.
123
+
124
+ Use `coin.symbol` and `chain.symbol` values from this response as inputs for
125
+ the `coin` and `chain` fields in `payment_options.methods` when creating a payment.
126
+
127
+ Raises:
128
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
129
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
130
+
131
+ Returns:
132
+ Response[ErrorResponse | PaymentMethodListResponse]
133
+ """
134
+
135
+ kwargs = _get_kwargs()
136
+
137
+ response = await client.get_async_httpx_client().request(**kwargs)
138
+
139
+ return _build_response(client=client, response=response)
140
+
141
+
142
+ async def asyncio(
143
+ *,
144
+ client: AuthenticatedClient | Client,
145
+ ) -> ErrorResponse | PaymentMethodListResponse | None:
146
+ """List payment methods
147
+
148
+ Retrieves all payment methods enabled for your store. Each entry represents
149
+ a unique coin + chain combination that your store accepts.
150
+
151
+ Use `coin.symbol` and `chain.symbol` values from this response as inputs for
152
+ the `coin` and `chain` fields in `payment_options.methods` when creating a payment.
153
+
154
+ Raises:
155
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
156
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
157
+
158
+ Returns:
159
+ ErrorResponse | PaymentMethodListResponse
160
+ """
161
+
162
+ return (
163
+ await asyncio_detailed(
164
+ client=client,
165
+ )
166
+ ).parsed
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""