whollycrypto 1.0.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.
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ venv/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ .coverage
12
+ htmlcov/
13
+ .env
14
+ .env.*
15
+ .pypirc
16
+ *.api.txt
17
+ *.log
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 - 2026-09-13
4
+
5
+ - Initial Python 3.10+ SDK for all 17 merchant API v1 endpoints, tested against merchant 3.5.0.
6
+ - Exact decimal strings/Decimal support, preserved response envelopes and large integers.
7
+ - Explicit invoice idempotency, deterministic body encoding and bounded opt-in safe retries.
8
+ - HTTPS connection reuse, certificate verification, bounded responses and quota headers.
9
+ - Separate token-free public checkout reader, preserving Lightning and chain payment fields.
10
+ - IPN/webhook verification, replay-aware durable SQLite inbox example and typed exceptions.
11
+ - MIT license, type information and no third-party runtime dependencies.
12
+ - 31 isolated tests pass on Python 3.10, 3.12 and 3.14; all public API contract fixtures match.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wholly Crypto
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.
@@ -0,0 +1,322 @@
1
+ Metadata-Version: 2.5
2
+ Name: whollycrypto
3
+ Version: 1.0.0
4
+ Summary: Lightweight Python SDK for the Wholly Crypto self-hosted merchant API.
5
+ Project-URL: Homepage, https://www.whollycrypto.com
6
+ Project-URL: Documentation, https://github.com/whollycrypto-com/whollycrypto-python-sdk#readme
7
+ Project-URL: Source, https://github.com/whollycrypto-com/whollycrypto-python-sdk
8
+ Project-URL: Issues, https://github.com/whollycrypto-com/whollycrypto-python-sdk/issues
9
+ Project-URL: Changelog, https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/CHANGELOG.md
10
+ Author: Wholly Crypto
11
+ License-Expression: MIT
12
+ License-File: LICENSE
13
+ Keywords: bitcoin,crypto,lightning,merchant,payments,sdk,whollycrypto
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+
27
+ # Wholly Crypto Python SDK
28
+
29
+ The official Python client for your **self-hosted Wholly Crypto merchant API**.
30
+ Create invoices, check payments, manage accepted assets and verify IPN/webhooks.
31
+
32
+ Python **3.10+**. Standard library only, with **no runtime dependencies**.
33
+ SDK **1.0.0** targets API **v1**, tested against merchant **3.5.0**.
34
+ SDK and merchant versions are independent.
35
+
36
+ ## Install
37
+
38
+ ```bash
39
+ python -m pip install whollycrypto
40
+ ```
41
+
42
+ Use a virtual environment for your application. Import the package as `whollycrypto`.
43
+
44
+ ## Create an invoice
45
+
46
+ Use **your installation's API domain**, not its merchant-console or checkout domain.
47
+ Create a credential in **Settings → API access** with read/write access to the project.
48
+
49
+ Find both UUIDs under **Project → Stores → select store → Basic → API IDs**.
50
+ Copy **Project API ID** and **Store API ID**, not the readable project/store identifiers.
51
+ Projects and stores are created in the console; the public API does not list or create them.
52
+
53
+ ```python
54
+ import os
55
+ from whollycrypto import Client
56
+
57
+ # Persist this key AND the exact payload with your order before the request.
58
+ # Reuse the same key, credential and payload if the response is lost.
59
+ idempotency_key = "order-1042-payment-attempt-1"
60
+
61
+ with Client("https://api.your-domain.com", os.environ["WHOLLY_API_TOKEN"]) as client:
62
+ result = client.create_invoice(
63
+ "11111111-1111-4111-8111-111111111111", # Your Project API ID
64
+ "22222222-2222-4222-8222-222222222222", # Your Store API ID
65
+ {
66
+ "amount": "49.90", # A string, never a float
67
+ "currency": "EUR",
68
+ "order_id": "order-1042",
69
+ "email": "customer@example.com",
70
+ "description": "Annual plan",
71
+ "ipn_url": "https://your-shop.com/wholly/ipn",
72
+ "redirect_url": "https://your-shop.com/orders/1042",
73
+ "cancel_url": "https://your-shop.com/cart",
74
+ },
75
+ idempotency_key=idempotency_key,
76
+ )
77
+
78
+ public_invoice_id = result["data"]["public_id"]
79
+ checkout_url = result["links"]["checkout"]
80
+ ```
81
+
82
+ The UUIDs above are placeholders. Return `checkout_url` to your customer, or redirect
83
+ from your server. Never put an API token in browser JavaScript, HTML, checkout URLs
84
+ or source control. A return/success URL is **not proof of payment**.
85
+
86
+ Every API method returns the **complete response envelope**. Fields such as `data`,
87
+ `links`, `pagination` and reconciliation's separate top-level fields are preserved.
88
+ The SDK does not rename fields or round amounts. JSON fractional numbers decode as
89
+ `decimal.Decimal`; monetary strings and arbitrarily large JSON integers stay exact.
90
+
91
+ ## Check and list payments
92
+
93
+ Reuse one client per worker/request context, then close it. The default transport
94
+ reuses its HTTPS connection. Calls are synchronous; run them outside an async event
95
+ loop or in a thread worker. Do not share a client across concurrent workers, because
96
+ `last_response` describes its most recent call.
97
+
98
+ ```python
99
+ invoice = client.get_invoice(project_id, public_invoice_id)["data"]
100
+ if invoice["status"] == "settled":
101
+ # Match the stored order, amount/currency and project/store first.
102
+ # Fulfil exactly once using your database's transaction/idempotency mechanism.
103
+ pass
104
+
105
+ page = client.list_invoices(project_id, {
106
+ "store_id": store_id, "status": "settled", "search": "order-1042",
107
+ "limit": 50, "offset": 0,
108
+ })
109
+
110
+ for invoice in client.iter_invoices(project_id, {"status": "settled"}):
111
+ # Each next page is requested only when needed.
112
+ pass
113
+ ```
114
+
115
+ These snippets use an open `client`. Invoice paths use `public_id`, **not** internal
116
+ `id` or `order_id`. `processing` is not `settled`. Pages are separate snapshots, so
117
+ deduplicate by public invoice ID if exporting while new invoices are arriving.
118
+
119
+ ## Amounts and invoice options
120
+
121
+ Amount, spread, tolerance and fixed token prices accept plain decimal strings or
122
+ `Decimal`. Floats are rejected for these fields. `Decimal` values are encoded as
123
+ plain strings without exponent notation. Other request values use normal JSON types.
124
+
125
+ ```python
126
+ from decimal import Decimal
127
+
128
+ payload = {
129
+ "amount": Decimal("25.00"),
130
+ "currency": "USD",
131
+ "exchange_rate_spread_percent": "0.5",
132
+ "underpayment_tolerance_percent": "1",
133
+ "expires_in_seconds": 900,
134
+ "language": "de",
135
+ "metadata": {
136
+ "firstname": "Ada", "lastname": "Lovelace",
137
+ "street": "12 Example Street", "street2": "Suite 2", "zip": "10115",
138
+ "city": "Berlin", "country": "Germany", "countryiso2": "DE",
139
+ "company": "Example GmbH", "vatid": "DE123456789",
140
+ },
141
+ "checkout_appearance": {
142
+ "title": "Complete your order", "intro": "Thanks for choosing us.",
143
+ "outro": "Questions? https://your-shop.com/help",
144
+ "intro_font_size": 18, "outro_font_size": 16,
145
+ "theme": "light", "accent_color": "#1768CE",
146
+ },
147
+ }
148
+ ```
149
+
150
+ Omitted options inherit store settings. Use `{}` for objects, not `[]`.
151
+ An empty `checkout_appearance` object freezes the resolved store design for that
152
+ invoice; omitting it keeps normal store appearance behavior. Appearance accepts
153
+ structured settings, not arbitrary HTML, JavaScript or CSS. The server remains
154
+ authoritative for currencies, allowed assets, confirmation policy and validation.
155
+
156
+ Request object keys are sorted for deterministic bytes. List order, strings and
157
+ decimal precision are preserved. Never switch SDKs/encodings during an invoice retry:
158
+ the server binds idempotency to the original credential and **exact raw JSON bytes**.
159
+ `Client.new_idempotency_key()` generates a key; you must persist it before use.
160
+
161
+ ## Merchant API methods
162
+
163
+ | Method | Purpose |
164
+ | --- | --- |
165
+ | `service_info()` / `health()` | Public service/health; no token sent |
166
+ | `create_invoice(project, store, payload, idempotency_key)` | Create or safely replay an invoice |
167
+ | `get_invoice(project, public_id)` | Private invoice detail and current checkout link |
168
+ | `list_invoices(project, filters)` / `iter_invoices(project, filters)` | Search and paginate invoices |
169
+ | `list_project_payment_assets(project)` | Native/token policies and readiness |
170
+ | `update_project_payment_asset(project, asset, policy)` | Update a project asset policy |
171
+ | `list_token_candidates(project, chain_slug, filters)` | Search catalog tokens with `q` and `limit` |
172
+ | `register_token_asset(project, token)` | Verify/register a catalog token |
173
+ | `discover_custom_dex_pools(project, chain_slug, contract)` | Discover supported DEX pricing candidates |
174
+ | `register_custom_token(project, token)` | Verify/register a custom contract or mint |
175
+ | `list_store_payment_assets(project, store)` | Accepted on-chain assets and separate Lightning readiness |
176
+ | `update_store_payment_assets(project, store, assets)` | **Replace** the entire on-chain selection |
177
+ | `update_store_confirmation_policy(project, store, asset, policy)` | Inherit or override confirmations |
178
+ | `list_project_wallets(project)` | Public addresses and balances; no keys |
179
+ | `list_reconciliation(project, filters)` | Needs-attention queue, fixed 25 cases per page |
180
+ | `get_reconciliation(project, public_id, page=1)` | Detail and paginated decision history |
181
+
182
+ IDs accept strings or `uuid.UUID`. See the
183
+ [full API reference](https://www.whollycrypto.com/api/) and
184
+ [payment-method examples](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/docs/payment-methods.md).
185
+
186
+ `update_store_payment_assets()` receives the list itself, not an `assets` wrapper.
187
+ `[]` removes **all on-chain selections**. It does not configure Lightning.
188
+ Refunds, sends, reconciliation decisions, accounts, exchange credentials and Lightning
189
+ configuration are console-only; the SDK does not invent public routes for them.
190
+
191
+ ## Verify IPN and webhooks
192
+
193
+ Both use the same signature format. Use the **IPN/webhook signing secret** from
194
+ the store configuration, not an API token. Pass the exact raw body as `bytes`.
195
+
196
+ ```python
197
+ from whollycrypto import InvalidSignatureError, parse_notification
198
+
199
+ try:
200
+ notice = parse_notification(raw_body, request_headers, signing_secret)
201
+ except InvalidSignatureError:
202
+ # Return HTTP 400 without logging secrets or the customer's payload.
203
+ raise
204
+
205
+ # Durably enqueue before returning 2xx. Failed storage must not be acknowledged.
206
+ # Persist (configured_project_id, notice.invoice_id, notice.sequence) for deduplication.
207
+ # Your worker re-fetches the invoice through the authenticated client before fulfilment.
208
+ ```
209
+
210
+ Verification uses HMAC-SHA256 and a constant-time comparison, with a five-minute
211
+ past/future clock window. Keep your server clock synchronized. `verify_signature()`
212
+ is also available for signature-only checks. `parse_notification()` additionally
213
+ validates UUIDs, status and sequence, then returns a readonly `Notification` payload.
214
+ `notice.invoice_id` is the **public** invoice UUID.
215
+
216
+ Signatures cover the timestamp and raw body, **not** event/delivery ID headers.
217
+ Do not deduplicate using event ID alone: changing it must not let an attacker
218
+ bypass replay protection, and a forged collision must not suppress a different
219
+ signed invoice. Use the signed invoice ID and sequence, scoped to your configured
220
+ project. Keep invoice state monotonic and re-check the authenticated invoice.
221
+ Event names are not sent in the payload or headers.
222
+
223
+ The [WSGI inbox example](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/examples/webhook_wsgi.py)
224
+ verifies before storage, queues durably in private SQLite, handles duplicates and
225
+ does not acknowledge failed writes. It does **not** fulfil orders or start a web
226
+ server. Mount it behind your application's HTTPS server and implement an idempotent
227
+ worker. The example's private filesystem checks target Linux/POSIX deployments.
228
+
229
+ ## Errors, timeouts and retries
230
+
231
+ ```python
232
+ from whollycrypto import APIError, Client, Options, TransportError
233
+
234
+ client = Client("https://api.your-domain.com", token, options=Options(
235
+ timeout_seconds=20, connect_timeout_seconds=5,
236
+ max_retries=1, max_retry_delay_seconds=30,
237
+ ))
238
+ try:
239
+ result = client.get_invoice(project_id, public_invoice_id)
240
+ except APIError as error:
241
+ status = error.status_code
242
+ code = error.error_code
243
+ retry_after = error.retry_after # Seconds or None
244
+ # error.api_message / error.response.body are opt-in private details, not log text.
245
+ except TransportError:
246
+ # A timeout does NOT prove invoice creation failed.
247
+ # Retry its original payload with the same stored key and credential.
248
+ pass
249
+ finally:
250
+ client.close()
251
+ ```
252
+
253
+ Retries are **off by default**. With retries enabled, only GETs and invoice creation
254
+ with its explicit key can retry transient connections or HTTP 429/502/503/504.
255
+ Other writes never retry automatically. Retries reuse the immutable request and
256
+ honor `Retry-After` seconds or a standard HTTP date. Invalid headers or waits longer
257
+ than the configured limit are surfaced to your queue, never retried early.
258
+ At most three retries can be enabled. Include attempts/backoff in your worker budget;
259
+ network timeouts depend on the operating system's DNS/socket behavior.
260
+
261
+ `client.last_response.rate_limit()` returns `limit`, `remaining` and `reset` headers
262
+ when present. `last_response` is `None` if the most recent attempted request has no
263
+ HTTP response. The default limit is 8 MiB per response and 32 KiB per merchant request.
264
+
265
+ TLS verification is always enabled. No automatic redirects, cookie storage, proxy
266
+ environment discovery or `.netrc` lookup. `Options(ca_file="/path/to/ca.pem")` can
267
+ trust your private CA without disabling hostname verification. A custom transport
268
+ receives credentials and must be trusted. Closing a client closes its default
269
+ transport; injected/shared transports remain caller-owned.
270
+
271
+ Repr and normal SDK exception messages omit credentials and response bodies.
272
+ Python debuggers can still inspect private attributes and frame locals: disable
273
+ local-variable/body capture in production error monitoring and never pickle clients.
274
+
275
+ ## Public checkout and Lightning
276
+
277
+ ```python
278
+ from whollycrypto import CheckoutClient
279
+
280
+ with CheckoutClient("https://pay.your-domain.com") as checkout:
281
+ view = checkout.get_invoice(public_invoice_id)
282
+ url = checkout.invoice_url(public_invoice_id)
283
+ ```
284
+
285
+ This separate reader never holds or sends a merchant API token. It also exposes
286
+ `get_preview(project, store=None)` and `preview_url(project, store=None, state="waiting")`.
287
+ Preview states are illustrative, not evidence of payment. Use the QR and image URLs
288
+ returned by checkout JSON instead of reconstructing them.
289
+
290
+ Preserve `payment_rail`, `asset_decimals`, destination tags/memos, `payment_uri` and
291
+ `payable`. Lightning BTC uses **11 atomic decimals (millisatoshis)**; on-chain BTC
292
+ uses 8. Its payment hash is not an on-chain address. Use the BOLT11/payment URI.
293
+ The SDK never signs or sends funds.
294
+
295
+ ## Development
296
+
297
+ ```bash
298
+ python -m pip install -e .
299
+ python -m unittest discover -s tests -t . -v
300
+ python -m pip install build twine
301
+ python -m build
302
+ python -m twine check dist/*
303
+ ```
304
+
305
+ Tests cover all 17 merchant endpoints, validation, precision, retry identity, HTTP
306
+ connection reuse, TLS rejection, signature verification and the durable receiver.
307
+ They use only mocks/disposable loopback servers and SQLite, never live payments.
308
+ Tests require OpenSSL CLI, SSL and SQLite support. Plain HTTP is available only for
309
+ explicit `Options(allow_insecure_localhost=True)` tests on localhost/127.0.0.1/::1;
310
+ this never disables HTTPS certificate verification.
311
+
312
+ An optional Python 3.10–3.14 CI template is provided in
313
+ [ci/github-actions.yml](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/ci/github-actions.yml).
314
+ Enabling it requires a maintainer with workflow-write permission. See
315
+ [maintenance notes](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/docs/maintaining.md)
316
+ for API drift checks and release verification.
317
+
318
+ ## License
319
+
320
+ [MIT](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/LICENSE),
321
+ for this client SDK only. The merchant application and other Wholly Crypto software
322
+ have their own licenses. No server implementation or private-service code is included.
@@ -0,0 +1,296 @@
1
+ # Wholly Crypto Python SDK
2
+
3
+ The official Python client for your **self-hosted Wholly Crypto merchant API**.
4
+ Create invoices, check payments, manage accepted assets and verify IPN/webhooks.
5
+
6
+ Python **3.10+**. Standard library only, with **no runtime dependencies**.
7
+ SDK **1.0.0** targets API **v1**, tested against merchant **3.5.0**.
8
+ SDK and merchant versions are independent.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ python -m pip install whollycrypto
14
+ ```
15
+
16
+ Use a virtual environment for your application. Import the package as `whollycrypto`.
17
+
18
+ ## Create an invoice
19
+
20
+ Use **your installation's API domain**, not its merchant-console or checkout domain.
21
+ Create a credential in **Settings → API access** with read/write access to the project.
22
+
23
+ Find both UUIDs under **Project → Stores → select store → Basic → API IDs**.
24
+ Copy **Project API ID** and **Store API ID**, not the readable project/store identifiers.
25
+ Projects and stores are created in the console; the public API does not list or create them.
26
+
27
+ ```python
28
+ import os
29
+ from whollycrypto import Client
30
+
31
+ # Persist this key AND the exact payload with your order before the request.
32
+ # Reuse the same key, credential and payload if the response is lost.
33
+ idempotency_key = "order-1042-payment-attempt-1"
34
+
35
+ with Client("https://api.your-domain.com", os.environ["WHOLLY_API_TOKEN"]) as client:
36
+ result = client.create_invoice(
37
+ "11111111-1111-4111-8111-111111111111", # Your Project API ID
38
+ "22222222-2222-4222-8222-222222222222", # Your Store API ID
39
+ {
40
+ "amount": "49.90", # A string, never a float
41
+ "currency": "EUR",
42
+ "order_id": "order-1042",
43
+ "email": "customer@example.com",
44
+ "description": "Annual plan",
45
+ "ipn_url": "https://your-shop.com/wholly/ipn",
46
+ "redirect_url": "https://your-shop.com/orders/1042",
47
+ "cancel_url": "https://your-shop.com/cart",
48
+ },
49
+ idempotency_key=idempotency_key,
50
+ )
51
+
52
+ public_invoice_id = result["data"]["public_id"]
53
+ checkout_url = result["links"]["checkout"]
54
+ ```
55
+
56
+ The UUIDs above are placeholders. Return `checkout_url` to your customer, or redirect
57
+ from your server. Never put an API token in browser JavaScript, HTML, checkout URLs
58
+ or source control. A return/success URL is **not proof of payment**.
59
+
60
+ Every API method returns the **complete response envelope**. Fields such as `data`,
61
+ `links`, `pagination` and reconciliation's separate top-level fields are preserved.
62
+ The SDK does not rename fields or round amounts. JSON fractional numbers decode as
63
+ `decimal.Decimal`; monetary strings and arbitrarily large JSON integers stay exact.
64
+
65
+ ## Check and list payments
66
+
67
+ Reuse one client per worker/request context, then close it. The default transport
68
+ reuses its HTTPS connection. Calls are synchronous; run them outside an async event
69
+ loop or in a thread worker. Do not share a client across concurrent workers, because
70
+ `last_response` describes its most recent call.
71
+
72
+ ```python
73
+ invoice = client.get_invoice(project_id, public_invoice_id)["data"]
74
+ if invoice["status"] == "settled":
75
+ # Match the stored order, amount/currency and project/store first.
76
+ # Fulfil exactly once using your database's transaction/idempotency mechanism.
77
+ pass
78
+
79
+ page = client.list_invoices(project_id, {
80
+ "store_id": store_id, "status": "settled", "search": "order-1042",
81
+ "limit": 50, "offset": 0,
82
+ })
83
+
84
+ for invoice in client.iter_invoices(project_id, {"status": "settled"}):
85
+ # Each next page is requested only when needed.
86
+ pass
87
+ ```
88
+
89
+ These snippets use an open `client`. Invoice paths use `public_id`, **not** internal
90
+ `id` or `order_id`. `processing` is not `settled`. Pages are separate snapshots, so
91
+ deduplicate by public invoice ID if exporting while new invoices are arriving.
92
+
93
+ ## Amounts and invoice options
94
+
95
+ Amount, spread, tolerance and fixed token prices accept plain decimal strings or
96
+ `Decimal`. Floats are rejected for these fields. `Decimal` values are encoded as
97
+ plain strings without exponent notation. Other request values use normal JSON types.
98
+
99
+ ```python
100
+ from decimal import Decimal
101
+
102
+ payload = {
103
+ "amount": Decimal("25.00"),
104
+ "currency": "USD",
105
+ "exchange_rate_spread_percent": "0.5",
106
+ "underpayment_tolerance_percent": "1",
107
+ "expires_in_seconds": 900,
108
+ "language": "de",
109
+ "metadata": {
110
+ "firstname": "Ada", "lastname": "Lovelace",
111
+ "street": "12 Example Street", "street2": "Suite 2", "zip": "10115",
112
+ "city": "Berlin", "country": "Germany", "countryiso2": "DE",
113
+ "company": "Example GmbH", "vatid": "DE123456789",
114
+ },
115
+ "checkout_appearance": {
116
+ "title": "Complete your order", "intro": "Thanks for choosing us.",
117
+ "outro": "Questions? https://your-shop.com/help",
118
+ "intro_font_size": 18, "outro_font_size": 16,
119
+ "theme": "light", "accent_color": "#1768CE",
120
+ },
121
+ }
122
+ ```
123
+
124
+ Omitted options inherit store settings. Use `{}` for objects, not `[]`.
125
+ An empty `checkout_appearance` object freezes the resolved store design for that
126
+ invoice; omitting it keeps normal store appearance behavior. Appearance accepts
127
+ structured settings, not arbitrary HTML, JavaScript or CSS. The server remains
128
+ authoritative for currencies, allowed assets, confirmation policy and validation.
129
+
130
+ Request object keys are sorted for deterministic bytes. List order, strings and
131
+ decimal precision are preserved. Never switch SDKs/encodings during an invoice retry:
132
+ the server binds idempotency to the original credential and **exact raw JSON bytes**.
133
+ `Client.new_idempotency_key()` generates a key; you must persist it before use.
134
+
135
+ ## Merchant API methods
136
+
137
+ | Method | Purpose |
138
+ | --- | --- |
139
+ | `service_info()` / `health()` | Public service/health; no token sent |
140
+ | `create_invoice(project, store, payload, idempotency_key)` | Create or safely replay an invoice |
141
+ | `get_invoice(project, public_id)` | Private invoice detail and current checkout link |
142
+ | `list_invoices(project, filters)` / `iter_invoices(project, filters)` | Search and paginate invoices |
143
+ | `list_project_payment_assets(project)` | Native/token policies and readiness |
144
+ | `update_project_payment_asset(project, asset, policy)` | Update a project asset policy |
145
+ | `list_token_candidates(project, chain_slug, filters)` | Search catalog tokens with `q` and `limit` |
146
+ | `register_token_asset(project, token)` | Verify/register a catalog token |
147
+ | `discover_custom_dex_pools(project, chain_slug, contract)` | Discover supported DEX pricing candidates |
148
+ | `register_custom_token(project, token)` | Verify/register a custom contract or mint |
149
+ | `list_store_payment_assets(project, store)` | Accepted on-chain assets and separate Lightning readiness |
150
+ | `update_store_payment_assets(project, store, assets)` | **Replace** the entire on-chain selection |
151
+ | `update_store_confirmation_policy(project, store, asset, policy)` | Inherit or override confirmations |
152
+ | `list_project_wallets(project)` | Public addresses and balances; no keys |
153
+ | `list_reconciliation(project, filters)` | Needs-attention queue, fixed 25 cases per page |
154
+ | `get_reconciliation(project, public_id, page=1)` | Detail and paginated decision history |
155
+
156
+ IDs accept strings or `uuid.UUID`. See the
157
+ [full API reference](https://www.whollycrypto.com/api/) and
158
+ [payment-method examples](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/docs/payment-methods.md).
159
+
160
+ `update_store_payment_assets()` receives the list itself, not an `assets` wrapper.
161
+ `[]` removes **all on-chain selections**. It does not configure Lightning.
162
+ Refunds, sends, reconciliation decisions, accounts, exchange credentials and Lightning
163
+ configuration are console-only; the SDK does not invent public routes for them.
164
+
165
+ ## Verify IPN and webhooks
166
+
167
+ Both use the same signature format. Use the **IPN/webhook signing secret** from
168
+ the store configuration, not an API token. Pass the exact raw body as `bytes`.
169
+
170
+ ```python
171
+ from whollycrypto import InvalidSignatureError, parse_notification
172
+
173
+ try:
174
+ notice = parse_notification(raw_body, request_headers, signing_secret)
175
+ except InvalidSignatureError:
176
+ # Return HTTP 400 without logging secrets or the customer's payload.
177
+ raise
178
+
179
+ # Durably enqueue before returning 2xx. Failed storage must not be acknowledged.
180
+ # Persist (configured_project_id, notice.invoice_id, notice.sequence) for deduplication.
181
+ # Your worker re-fetches the invoice through the authenticated client before fulfilment.
182
+ ```
183
+
184
+ Verification uses HMAC-SHA256 and a constant-time comparison, with a five-minute
185
+ past/future clock window. Keep your server clock synchronized. `verify_signature()`
186
+ is also available for signature-only checks. `parse_notification()` additionally
187
+ validates UUIDs, status and sequence, then returns a readonly `Notification` payload.
188
+ `notice.invoice_id` is the **public** invoice UUID.
189
+
190
+ Signatures cover the timestamp and raw body, **not** event/delivery ID headers.
191
+ Do not deduplicate using event ID alone: changing it must not let an attacker
192
+ bypass replay protection, and a forged collision must not suppress a different
193
+ signed invoice. Use the signed invoice ID and sequence, scoped to your configured
194
+ project. Keep invoice state monotonic and re-check the authenticated invoice.
195
+ Event names are not sent in the payload or headers.
196
+
197
+ The [WSGI inbox example](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/examples/webhook_wsgi.py)
198
+ verifies before storage, queues durably in private SQLite, handles duplicates and
199
+ does not acknowledge failed writes. It does **not** fulfil orders or start a web
200
+ server. Mount it behind your application's HTTPS server and implement an idempotent
201
+ worker. The example's private filesystem checks target Linux/POSIX deployments.
202
+
203
+ ## Errors, timeouts and retries
204
+
205
+ ```python
206
+ from whollycrypto import APIError, Client, Options, TransportError
207
+
208
+ client = Client("https://api.your-domain.com", token, options=Options(
209
+ timeout_seconds=20, connect_timeout_seconds=5,
210
+ max_retries=1, max_retry_delay_seconds=30,
211
+ ))
212
+ try:
213
+ result = client.get_invoice(project_id, public_invoice_id)
214
+ except APIError as error:
215
+ status = error.status_code
216
+ code = error.error_code
217
+ retry_after = error.retry_after # Seconds or None
218
+ # error.api_message / error.response.body are opt-in private details, not log text.
219
+ except TransportError:
220
+ # A timeout does NOT prove invoice creation failed.
221
+ # Retry its original payload with the same stored key and credential.
222
+ pass
223
+ finally:
224
+ client.close()
225
+ ```
226
+
227
+ Retries are **off by default**. With retries enabled, only GETs and invoice creation
228
+ with its explicit key can retry transient connections or HTTP 429/502/503/504.
229
+ Other writes never retry automatically. Retries reuse the immutable request and
230
+ honor `Retry-After` seconds or a standard HTTP date. Invalid headers or waits longer
231
+ than the configured limit are surfaced to your queue, never retried early.
232
+ At most three retries can be enabled. Include attempts/backoff in your worker budget;
233
+ network timeouts depend on the operating system's DNS/socket behavior.
234
+
235
+ `client.last_response.rate_limit()` returns `limit`, `remaining` and `reset` headers
236
+ when present. `last_response` is `None` if the most recent attempted request has no
237
+ HTTP response. The default limit is 8 MiB per response and 32 KiB per merchant request.
238
+
239
+ TLS verification is always enabled. No automatic redirects, cookie storage, proxy
240
+ environment discovery or `.netrc` lookup. `Options(ca_file="/path/to/ca.pem")` can
241
+ trust your private CA without disabling hostname verification. A custom transport
242
+ receives credentials and must be trusted. Closing a client closes its default
243
+ transport; injected/shared transports remain caller-owned.
244
+
245
+ Repr and normal SDK exception messages omit credentials and response bodies.
246
+ Python debuggers can still inspect private attributes and frame locals: disable
247
+ local-variable/body capture in production error monitoring and never pickle clients.
248
+
249
+ ## Public checkout and Lightning
250
+
251
+ ```python
252
+ from whollycrypto import CheckoutClient
253
+
254
+ with CheckoutClient("https://pay.your-domain.com") as checkout:
255
+ view = checkout.get_invoice(public_invoice_id)
256
+ url = checkout.invoice_url(public_invoice_id)
257
+ ```
258
+
259
+ This separate reader never holds or sends a merchant API token. It also exposes
260
+ `get_preview(project, store=None)` and `preview_url(project, store=None, state="waiting")`.
261
+ Preview states are illustrative, not evidence of payment. Use the QR and image URLs
262
+ returned by checkout JSON instead of reconstructing them.
263
+
264
+ Preserve `payment_rail`, `asset_decimals`, destination tags/memos, `payment_uri` and
265
+ `payable`. Lightning BTC uses **11 atomic decimals (millisatoshis)**; on-chain BTC
266
+ uses 8. Its payment hash is not an on-chain address. Use the BOLT11/payment URI.
267
+ The SDK never signs or sends funds.
268
+
269
+ ## Development
270
+
271
+ ```bash
272
+ python -m pip install -e .
273
+ python -m unittest discover -s tests -t . -v
274
+ python -m pip install build twine
275
+ python -m build
276
+ python -m twine check dist/*
277
+ ```
278
+
279
+ Tests cover all 17 merchant endpoints, validation, precision, retry identity, HTTP
280
+ connection reuse, TLS rejection, signature verification and the durable receiver.
281
+ They use only mocks/disposable loopback servers and SQLite, never live payments.
282
+ Tests require OpenSSL CLI, SSL and SQLite support. Plain HTTP is available only for
283
+ explicit `Options(allow_insecure_localhost=True)` tests on localhost/127.0.0.1/::1;
284
+ this never disables HTTPS certificate verification.
285
+
286
+ An optional Python 3.10–3.14 CI template is provided in
287
+ [ci/github-actions.yml](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/ci/github-actions.yml).
288
+ Enabling it requires a maintainer with workflow-write permission. See
289
+ [maintenance notes](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/docs/maintaining.md)
290
+ for API drift checks and release verification.
291
+
292
+ ## License
293
+
294
+ [MIT](https://github.com/whollycrypto-com/whollycrypto-python-sdk/blob/main/LICENSE),
295
+ for this client SDK only. The merchant application and other Wholly Crypto software
296
+ have their own licenses. No server implementation or private-service code is included.