vatly-fluent-python 0.1.0a2__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.
- vatly_fluent_python-0.1.0a2/.gitignore +9 -0
- vatly_fluent_python-0.1.0a2/CHANGELOG.md +23 -0
- vatly_fluent_python-0.1.0a2/LICENSE +21 -0
- vatly_fluent_python-0.1.0a2/PKG-INFO +119 -0
- vatly_fluent_python-0.1.0a2/PORTING.md +47 -0
- vatly_fluent_python-0.1.0a2/README.md +103 -0
- vatly_fluent_python-0.1.0a2/docs/Checkouts.md +27 -0
- vatly_fluent_python-0.1.0a2/docs/Configuration.md +33 -0
- vatly_fluent_python-0.1.0a2/docs/CoreConcepts.md +28 -0
- vatly_fluent_python-0.1.0a2/docs/CustomerPortal.md +12 -0
- vatly_fluent_python-0.1.0a2/docs/Customers.md +21 -0
- vatly_fluent_python-0.1.0a2/docs/Orders.md +13 -0
- vatly_fluent_python-0.1.0a2/docs/Porting.md +4 -0
- vatly_fluent_python-0.1.0a2/docs/README.md +23 -0
- vatly_fluent_python-0.1.0a2/docs/Subscriptions.md +52 -0
- vatly_fluent_python-0.1.0a2/docs/Testing.md +16 -0
- vatly_fluent_python-0.1.0a2/docs/Webhooks.md +39 -0
- vatly_fluent_python-0.1.0a2/examples/sqlite_driver.py +210 -0
- vatly_fluent_python-0.1.0a2/pyproject.toml +51 -0
- vatly_fluent_python-0.1.0a2/scripts/check_package.py +23 -0
- vatly_fluent_python-0.1.0a2/src/vatly_fluent/__init__.py +64 -0
- vatly_fluent_python-0.1.0a2/src/vatly_fluent/builders.py +139 -0
- vatly_fluent_python-0.1.0a2/src/vatly_fluent/client.py +170 -0
- vatly_fluent_python-0.1.0a2/src/vatly_fluent/contracts.py +202 -0
- vatly_fluent_python-0.1.0a2/src/vatly_fluent/customers.py +133 -0
- vatly_fluent_python-0.1.0a2/src/vatly_fluent/handles.py +176 -0
- vatly_fluent_python-0.1.0a2/src/vatly_fluent/linkage.py +44 -0
- vatly_fluent_python-0.1.0a2/src/vatly_fluent/py.typed +1 -0
- vatly_fluent_python-0.1.0a2/src/vatly_fluent/webhooks.py +154 -0
- vatly_fluent_python-0.1.0a2/tests/fixtures/resources.json +318 -0
- vatly_fluent_python-0.1.0a2/tests/test_fluent.py +521 -0
- vatly_fluent_python-0.1.0a2/vendor/README.md +16 -0
- vatly_fluent_python-0.1.0a2/vendor/SHA256SUMS +1 -0
- vatly_fluent_python-0.1.0a2/vendor/vatly_api_python-0.1.0a2-py3-none-any.whl +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0a2 — Unreleased
|
|
4
|
+
|
|
5
|
+
- Use distribution `vatly-fluent-python`; imports remain `vatly_fluent`.
|
|
6
|
+
- Depend on the renamed SDK distribution `vatly-api-python` (import `vatly`).
|
|
7
|
+
- Derive grace expiry from period/trial deadlines, not cancellation request time.
|
|
8
|
+
- Share lifecycle mapping across signed reactions, sync and Django reconciliation;
|
|
9
|
+
repair legacy expiry on sync and clear it after missed resume.
|
|
10
|
+
- Reject unknown grace expiry transactionally rather than guessing a deadline.
|
|
11
|
+
- Reject conflicting trial/cycle grace deadlines; the API omits core's trial flag.
|
|
12
|
+
- Require corrected SDK 0.1.0a2; refresh the unpublished bootstrap wheel.
|
|
13
|
+
|
|
14
|
+
## 0.1.0a1 — Unreleased
|
|
15
|
+
|
|
16
|
+
> Alpha — under active development. Every alpha release may include breaking changes. Pin exact versions during alpha.
|
|
17
|
+
|
|
18
|
+
- Initial async-first Fluent Python port: builders, handles, customer services,
|
|
19
|
+
pluggable storage, transactional webhook reactions and signed snapshots.
|
|
20
|
+
- Host-owned checkout/entity linkage, PR #2910-compatible subscription references,
|
|
21
|
+
bounded recovery, historical plan-line reporting, and no customerId ownership fallback.
|
|
22
|
+
- Typed package, SQLite transaction/outbox example, tests, guides, CI, trusted
|
|
23
|
+
publishing workflow and idempotent orb setup. No publication or tags.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vatly
|
|
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,119 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vatly-fluent-python
|
|
3
|
+
Version: 0.1.0a2
|
|
4
|
+
Summary: Framework-independent fluent billing integrations built on the Vatly Python SDK
|
|
5
|
+
Project-URL: Homepage, https://github.com/vatly/vatly-fluent-python
|
|
6
|
+
Project-URL: Documentation, https://docs.vatly.com
|
|
7
|
+
Project-URL: Issues, https://github.com/vatly/vatly-fluent-python/issues
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: vatly-api-python==0.1.0a2
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Vatly Fluent for Python
|
|
18
|
+
|
|
19
|
+
> **Alpha — under active development. Every alpha release may include breaking changes. Pin exact versions during alpha.**
|
|
20
|
+
|
|
21
|
+
Integrate Vatly billing without tying your application to a framework or database.
|
|
22
|
+
Fluent adds chainable checkout/subscription builders, customer and subscription
|
|
23
|
+
handles, pluggable persistence, and a signed webhook-to-domain-event pipeline on
|
|
24
|
+
top of `vatly-api-python`. Your application owns authentication, entitlements, storage,
|
|
25
|
+
transactions and jobs. Python 3.10+, fully typed, **async-first**.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
Once both packages are published:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install vatly-fluent-python==0.1.0a2 vatly-api-python==0.1.0a2
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Nothing is published yet. For development, run `.agents/setup` or `uv sync --locked`.
|
|
36
|
+
The versioned wheel under `vendor/` bootstraps the unpublished SDK for uv only;
|
|
37
|
+
normal package metadata depends on the exact SDK version from PyPI. It is not
|
|
38
|
+
copied into Fluent's wheel. See [provenance](vendor/README.md).
|
|
39
|
+
|
|
40
|
+
## First checkout
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from vatly import AsyncVatlyClient, RequestOptions
|
|
44
|
+
from vatly_fluent import Vatly, Wiring
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
async def start_subscription(plan_id: str, purchase_id: str):
|
|
48
|
+
async with AsyncVatlyClient() as api: # reads VATLY_API_KEY
|
|
49
|
+
vatly = Vatly(
|
|
50
|
+
Wiring(
|
|
51
|
+
api=api,
|
|
52
|
+
redirect_url_success="https://app.example.com/billing/return",
|
|
53
|
+
redirect_url_canceled="https://app.example.com/billing/canceled",
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
checkout = await (
|
|
57
|
+
vatly.subscribe()
|
|
58
|
+
.to_plan(plan_id)
|
|
59
|
+
.with_quantity(3)
|
|
60
|
+
.with_trial_days(14)
|
|
61
|
+
.with_metadata({"purchaseId": purchase_id})
|
|
62
|
+
.create(options=RequestOptions(idempotency_key=f"subscribe:{purchase_id}"))
|
|
63
|
+
)
|
|
64
|
+
return checkout.get_url()
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This creates a **checkout**, not a subscription. Confirm payment through signed
|
|
68
|
+
webhooks, not redirects. No API calls happen until `create()`. Use a new builder
|
|
69
|
+
per purchase and persist a stable operation ID before sending. SDK errors pass
|
|
70
|
+
through unchanged; `FluentError` means invalid local input or missing wiring.
|
|
71
|
+
|
|
72
|
+
## Connect your own entities and storage
|
|
73
|
+
|
|
74
|
+
Wire `CheckoutRecords`, `Repository[LocalSubscription]`, `Repository[Stored[Order]]`,
|
|
75
|
+
and `WebhookCalls` to your application's database. For entity-linked checkouts:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from vatly_fluent import EntityRef
|
|
79
|
+
|
|
80
|
+
# In an authorized handler, with vatly.wiring.checkouts configured:
|
|
81
|
+
builder = vatly.subscribe().to_plan(plan_id).for_entity(EntityRef("team", team_id))
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Ownership follows **your stored checkout → order → subscription links**. It never
|
|
85
|
+
falls back to `customerId`, which is only billing identity and may be shared or null.
|
|
86
|
+
Metadata is correlation data, not authorization. A signed webhook authenticates
|
|
87
|
+
Vatly's snapshot; it does not authorize a browser-provided entity ID.
|
|
88
|
+
|
|
89
|
+
Initial order lines may carry `productType="subscription"` and the intended
|
|
90
|
+
subscription ID (core PR #2910). Historical `subscription_plan` lines remain plan
|
|
91
|
+
references. Fluent never guesses a subscription from a plan or quantity.
|
|
92
|
+
`reconcile_checkout()` handles bounded 404 recovery and returns unresolved IDs;
|
|
93
|
+
an intended ID alone is not evidence of active service.
|
|
94
|
+
|
|
95
|
+
## Learn the integration
|
|
96
|
+
|
|
97
|
+
- [Getting started](docs/README.md) and [configuration](docs/Configuration.md)
|
|
98
|
+
- [Checkouts](docs/Checkouts.md), [customers](docs/Customers.md), [customer portal](docs/CustomerPortal.md)
|
|
99
|
+
- [Subscriptions](docs/Subscriptions.md) and [orders](docs/Orders.md)
|
|
100
|
+
- [Driver contracts](docs/CoreConcepts.md) and [transactional webhooks](docs/Webhooks.md)
|
|
101
|
+
- [Testing](docs/Testing.md), [porting decisions](PORTING.md), [release notes](CHANGELOG.md)
|
|
102
|
+
- [SQLite driver example](examples/sqlite_driver.py), with atomic dedup, rollback and outbox tests
|
|
103
|
+
|
|
104
|
+
## Develop
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
uv sync --locked
|
|
108
|
+
uv run ruff check .
|
|
109
|
+
uv run ruff format --check .
|
|
110
|
+
uv run mypy
|
|
111
|
+
uv run pytest
|
|
112
|
+
uv build
|
|
113
|
+
uv run twine check dist/*
|
|
114
|
+
uv run python scripts/check_package.py
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
CI runs these checks across Python 3.10–3.14. Release workflows are prepared but
|
|
118
|
+
require PyPI trusted-publisher configuration and an explicitly published GitHub
|
|
119
|
+
release. No release is triggered by pushing `main`.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Porting Vatly Fluent to Python
|
|
2
|
+
|
|
3
|
+
Primary: `vatly/vatly-fluent-js` at `81b80d9ba3dd621d7f66865166046272651836dc`,
|
|
4
|
+
including its `PORTING.md` and complete integration guides (read 2026-11-09).
|
|
5
|
+
Secondary: `vatly/vatly-fluent-php` at `db211e0cf8505017fcd2eea056628db2f19f5c8b`.
|
|
6
|
+
|
|
7
|
+
| JS responsibility | Python surface |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| Vatly / Wiring | `Vatly(Wiring(api=AsyncVatlyClient(...), ...))` |
|
|
10
|
+
| checkoutBuilder / subscribe | `checkout_builder` / `subscribe`, chainable builders |
|
|
11
|
+
| CustomerProfile | frozen `CustomerProfile` dataclass |
|
|
12
|
+
| checkout.getUrl | SDK-derived `CheckoutResult.get_url()` |
|
|
13
|
+
| CustomerService / CustomerHandle | `customers` / `customer(id)` |
|
|
14
|
+
| SubscriptionHandle / subscriptionState | `subscription(local)` / `subscription_state` |
|
|
15
|
+
| OrderHandle | `order(id)`, memoized full signed-compatible SDK resource |
|
|
16
|
+
| Reader/Writer/Repository | async `Repository[T]` protocol |
|
|
17
|
+
| Stored / LocalSubscription | Pydantic wrappers: `resource`, `entity`, optional `ends_at` |
|
|
18
|
+
| WebhookCalls / reactions / dispatcher | transactional async protocols |
|
|
19
|
+
| SDK testHelpers | guarded SDK delegation plus named convenience methods |
|
|
20
|
+
| Native SDK errors / FluentError | unchanged SDK errors, local `FluentError` |
|
|
21
|
+
|
|
22
|
+
Intentional differences: Python snake_case; async protocols rather than mixed sync/
|
|
23
|
+
async implementations; Decimal amounts instead of JS bigint minor units; wrappers
|
|
24
|
+
instead of intersecting SDK records with host fields. All remote wire keys remain
|
|
25
|
+
Vatly's camelCase. Dictionaries supplied to methods/overrides use wire keys.
|
|
26
|
+
|
|
27
|
+
Ownership deliberately follows host-owned **checkout records**, not the JS port's
|
|
28
|
+
customer-binding fallback. `EntityRef(kind, id)` supports teams/users/organizations.
|
|
29
|
+
`CheckoutRecords` maps checkout → order → subscription IDs. Customer bindings remain
|
|
30
|
+
billing identities and cannot establish entitlement ownership. Drivers enforce
|
|
31
|
+
immutable links and scope every lookup by tenant, storefront and API mode.
|
|
32
|
+
|
|
33
|
+
Pending core [PR #2910](https://github.com/sandervanhooft/vatlify/pull/2910) stamps
|
|
34
|
+
initial subscription order lines with intended subscription IDs. Historical
|
|
35
|
+
`subscription_plan` lines are preserved but never treated as subscription IDs.
|
|
36
|
+
Quantity does not multiply subscription IDs; two checkout plan lines can produce
|
|
37
|
+
distinct subscription IDs for the same plan. `reconcile_checkout` explicitly reads
|
|
38
|
+
checkout → order → subscriptions with bounded 404 retries. It returns pending IDs
|
|
39
|
+
(which may never resolve) and legacy plan IDs. It never grants access or selects a
|
|
40
|
+
subscription by customer/plan heuristics. Trial AUTH_REQUEST flows may have no
|
|
41
|
+
merchant order.paid event; reconcile the paid checkout's orderId explicitly.
|
|
42
|
+
|
|
43
|
+
Built-in webhooks preserve signed snapshots and make no API calls. Out-of-order
|
|
44
|
+
checkout/order/subscription events converge through persisted linkage; missing
|
|
45
|
+
snapshots require an explicit reconciliation job. Unknown events are retained and
|
|
46
|
+
dispatched. Optional reversal repositories gate storage, not dispatch. Hosts must
|
|
47
|
+
provide atomic dedup/audit/repository/outbox transactions and reconcile stale events.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Vatly Fluent for Python
|
|
2
|
+
|
|
3
|
+
> **Alpha — under active development. Every alpha release may include breaking changes. Pin exact versions during alpha.**
|
|
4
|
+
|
|
5
|
+
Integrate Vatly billing without tying your application to a framework or database.
|
|
6
|
+
Fluent adds chainable checkout/subscription builders, customer and subscription
|
|
7
|
+
handles, pluggable persistence, and a signed webhook-to-domain-event pipeline on
|
|
8
|
+
top of `vatly-api-python`. Your application owns authentication, entitlements, storage,
|
|
9
|
+
transactions and jobs. Python 3.10+, fully typed, **async-first**.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
Once both packages are published:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install vatly-fluent-python==0.1.0a2 vatly-api-python==0.1.0a2
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Nothing is published yet. For development, run `.agents/setup` or `uv sync --locked`.
|
|
20
|
+
The versioned wheel under `vendor/` bootstraps the unpublished SDK for uv only;
|
|
21
|
+
normal package metadata depends on the exact SDK version from PyPI. It is not
|
|
22
|
+
copied into Fluent's wheel. See [provenance](vendor/README.md).
|
|
23
|
+
|
|
24
|
+
## First checkout
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from vatly import AsyncVatlyClient, RequestOptions
|
|
28
|
+
from vatly_fluent import Vatly, Wiring
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
async def start_subscription(plan_id: str, purchase_id: str):
|
|
32
|
+
async with AsyncVatlyClient() as api: # reads VATLY_API_KEY
|
|
33
|
+
vatly = Vatly(
|
|
34
|
+
Wiring(
|
|
35
|
+
api=api,
|
|
36
|
+
redirect_url_success="https://app.example.com/billing/return",
|
|
37
|
+
redirect_url_canceled="https://app.example.com/billing/canceled",
|
|
38
|
+
)
|
|
39
|
+
)
|
|
40
|
+
checkout = await (
|
|
41
|
+
vatly.subscribe()
|
|
42
|
+
.to_plan(plan_id)
|
|
43
|
+
.with_quantity(3)
|
|
44
|
+
.with_trial_days(14)
|
|
45
|
+
.with_metadata({"purchaseId": purchase_id})
|
|
46
|
+
.create(options=RequestOptions(idempotency_key=f"subscribe:{purchase_id}"))
|
|
47
|
+
)
|
|
48
|
+
return checkout.get_url()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This creates a **checkout**, not a subscription. Confirm payment through signed
|
|
52
|
+
webhooks, not redirects. No API calls happen until `create()`. Use a new builder
|
|
53
|
+
per purchase and persist a stable operation ID before sending. SDK errors pass
|
|
54
|
+
through unchanged; `FluentError` means invalid local input or missing wiring.
|
|
55
|
+
|
|
56
|
+
## Connect your own entities and storage
|
|
57
|
+
|
|
58
|
+
Wire `CheckoutRecords`, `Repository[LocalSubscription]`, `Repository[Stored[Order]]`,
|
|
59
|
+
and `WebhookCalls` to your application's database. For entity-linked checkouts:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from vatly_fluent import EntityRef
|
|
63
|
+
|
|
64
|
+
# In an authorized handler, with vatly.wiring.checkouts configured:
|
|
65
|
+
builder = vatly.subscribe().to_plan(plan_id).for_entity(EntityRef("team", team_id))
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Ownership follows **your stored checkout → order → subscription links**. It never
|
|
69
|
+
falls back to `customerId`, which is only billing identity and may be shared or null.
|
|
70
|
+
Metadata is correlation data, not authorization. A signed webhook authenticates
|
|
71
|
+
Vatly's snapshot; it does not authorize a browser-provided entity ID.
|
|
72
|
+
|
|
73
|
+
Initial order lines may carry `productType="subscription"` and the intended
|
|
74
|
+
subscription ID (core PR #2910). Historical `subscription_plan` lines remain plan
|
|
75
|
+
references. Fluent never guesses a subscription from a plan or quantity.
|
|
76
|
+
`reconcile_checkout()` handles bounded 404 recovery and returns unresolved IDs;
|
|
77
|
+
an intended ID alone is not evidence of active service.
|
|
78
|
+
|
|
79
|
+
## Learn the integration
|
|
80
|
+
|
|
81
|
+
- [Getting started](docs/README.md) and [configuration](docs/Configuration.md)
|
|
82
|
+
- [Checkouts](docs/Checkouts.md), [customers](docs/Customers.md), [customer portal](docs/CustomerPortal.md)
|
|
83
|
+
- [Subscriptions](docs/Subscriptions.md) and [orders](docs/Orders.md)
|
|
84
|
+
- [Driver contracts](docs/CoreConcepts.md) and [transactional webhooks](docs/Webhooks.md)
|
|
85
|
+
- [Testing](docs/Testing.md), [porting decisions](PORTING.md), [release notes](CHANGELOG.md)
|
|
86
|
+
- [SQLite driver example](examples/sqlite_driver.py), with atomic dedup, rollback and outbox tests
|
|
87
|
+
|
|
88
|
+
## Develop
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
uv sync --locked
|
|
92
|
+
uv run ruff check .
|
|
93
|
+
uv run ruff format --check .
|
|
94
|
+
uv run mypy
|
|
95
|
+
uv run pytest
|
|
96
|
+
uv build
|
|
97
|
+
uv run twine check dist/*
|
|
98
|
+
uv run python scripts/check_package.py
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
CI runs these checks across Python 3.10–3.14. Release workflows are prepared but
|
|
102
|
+
require PyPI trusted-publisher configuration and an explicitly published GitHub
|
|
103
|
+
release. No release is triggered by pushing `main`.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Checkouts
|
|
2
|
+
|
|
3
|
+
`vatly.checkout_builder(profile)` handles one-off and mixed carts. Call
|
|
4
|
+
`.with_items([{"id": product_id, "quantity": 2}])`; repeated calls append detached
|
|
5
|
+
copies. `vatly.subscribe(profile).to_plan(plan_id).with_quantity(3)` creates a
|
|
6
|
+
single-plan checkout builder. Trial methods are `with_trial_days` and
|
|
7
|
+
`with_trial_ends_at(aware_datetime)`, rounded up to whole days. Quantity and trial
|
|
8
|
+
days must be positive integers. No request occurs until `await builder.create()`.
|
|
9
|
+
|
|
10
|
+
Both builders offer `with_redirect_url_success`, `with_redirect_url_canceled`,
|
|
11
|
+
`with_locale`, `with_metadata`, `with_billing_address`, `in_testmode`, and
|
|
12
|
+
`in_live_mode`. Mode methods assert the key's mode; they cannot change it.
|
|
13
|
+
`payload(overrides)` returns a deep detached wire-format dictionary.
|
|
14
|
+
`create(overrides, options=RequestOptions(...))` returns a full SDK Checkout plus
|
|
15
|
+
`get_url()`. Subscription builders replace rather than accumulate their plan item.
|
|
16
|
+
|
|
17
|
+
Use `.for_entity(EntityRef("team", authorized_team_id))` with `checkouts` wiring to
|
|
18
|
+
save ownership locally. A profile's `vatly_id` selects billing identity, not entity
|
|
19
|
+
ownership. Authorize all overrides on the server. Persist a purchase ID before
|
|
20
|
+
calling the API and reuse its idempotency key if the API or local save times out.
|
|
21
|
+
If local persistence fails after the API succeeds, retry with that **same key**.
|
|
22
|
+
Never blindly issue a second purchase. SDK auto-keys cover internal retries only.
|
|
23
|
+
|
|
24
|
+
Checkout redirects do not prove payment. Use signed events and reconciliation.
|
|
25
|
+
Checkout objects stay lean: read lines from checkout.order_id's Order, not from
|
|
26
|
+
invented checkout.products fields. [Subscriptions](Subscriptions.md) covers old
|
|
27
|
+
plan references and the pending core order-line change.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Configuration and lifecycle
|
|
2
|
+
|
|
3
|
+
Construct `Vatly(Wiring(api=api, ...))` with an `AsyncVatlyClient`. The caller owns
|
|
4
|
+
the SDK connection pool: use `async with AsyncVatlyClient()` and reuse it per
|
|
5
|
+
application/worker lifespan. Fluent creates no additional transport. Pass an
|
|
6
|
+
explicit key or use `VATLY_API_KEY`. Live/test share the same URL; keys select mode.
|
|
7
|
+
|
|
8
|
+
Only `api` and both redirect URLs are needed for anonymous API-only checkout
|
|
9
|
+
creation. Add `checkouts` to persist `.for_entity(EntityRef(...))`; add repositories,
|
|
10
|
+
`webhook_secret`, `webhook_calls` and `events` for a durable integration. Missing
|
|
11
|
+
wiring fails when used. `api` exposes all SDK resources, options, retries and errors.
|
|
12
|
+
|
|
13
|
+
Use `RequestOptions` for stable idempotency keys, headers and timeouts (seconds).
|
|
14
|
+
SDK errors propagate unchanged. Keep API/webhook secrets server-side and separate.
|
|
15
|
+
An email-only profile does not create a customer. Authorization is always the host's job.
|
|
16
|
+
|
|
17
|
+
## Development and future release
|
|
18
|
+
|
|
19
|
+
Run `.agents/setup` to provision uv 0.12.9, Python 3.12, locked dependencies and an
|
|
20
|
+
import sanity check. It is idempotent, has no service/database/secret requirements,
|
|
21
|
+
and becomes active for project orbs after reaching the default branch.
|
|
22
|
+
|
|
23
|
+
Before PyPI publication, uv uses the [pinned SDK wheel](../vendor/README.md).
|
|
24
|
+
Wheel metadata still declares the normal exact PyPI dependency. The PyPI JSON
|
|
25
|
+
API returned 404 for `vatly-fluent-python` on 2026-11-12; availability is not a reservation.
|
|
26
|
+
Publish the SDK first. Configure PyPI's pending trusted publisher for project
|
|
27
|
+
`vatly-fluent-python` with owner
|
|
28
|
+
`vatly`, repository `vatly-fluent-python`, workflow `release.yml`; leave the
|
|
29
|
+
environment field blank. No GitHub environment or API token is needed. Restrict
|
|
30
|
+
repository release access: there is no environment approval gate. Only publish a
|
|
31
|
+
GitHub release/tag after explicit authorization and green CI.
|
|
32
|
+
The tag must match `v` plus the package version. Pushing main does not publish.
|
|
33
|
+
PyPI artifacts are public even when the source GitHub repo is private.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Driver contracts and ownership
|
|
2
|
+
|
|
3
|
+
Fluent's async `Protocol`s adapt existing databases; there are no framework models
|
|
4
|
+
or containers. Implement synchronous storage inside async adapters deliberately,
|
|
5
|
+
using your framework's thread/transaction rules. The [SQLite example](../examples/sqlite_driver.py)
|
|
6
|
+
demonstrates the contract, not a production async database strategy.
|
|
7
|
+
|
|
8
|
+
`Stored[T]` wraps the untouched SDK `resource` with `entity: EntityRef | None`.
|
|
9
|
+
`LocalSubscription` also adds `ends_at`. Repository methods are
|
|
10
|
+
`find_by_vatly_id`, `store` and `update`. `store` may return None to decline saving;
|
|
11
|
+
then no local-created event is emitted. `update` takes wrapper field changes:
|
|
12
|
+
omitted keys stay unchanged; None explicitly clears. `resource` is a complete SDK
|
|
13
|
+
snapshot. `ReversalRepository` adds `list_for_order` and `list_for_customer`.
|
|
14
|
+
|
|
15
|
+
Scope all unique IDs and lookups by tenant, storefront and test/live mode.
|
|
16
|
+
`CheckoutRecords.record(CheckoutRecord(...))` stores an authorized host entity.
|
|
17
|
+
`find(checkout_id)` reads it; `link(checkout_id, resource_type, resource_id)` binds
|
|
18
|
+
orders/subscriptions; `find_for_resource` follows the link. Identical repeats are
|
|
19
|
+
idempotent; conflicting ownership must fail, never silently reassign.
|
|
20
|
+
|
|
21
|
+
`CustomerBindings` is separate billing identity: atomic `bind`, non-clearing
|
|
22
|
+
`record`, and lookups in both directions. Unique constraints on both sides protect
|
|
23
|
+
concurrent binding. These bindings **never determine resource ownership**.
|
|
24
|
+
|
|
25
|
+
`WebhookCalls.process(event, work)` must commit signed-ID dedup, audit, repository
|
|
26
|
+
writes, checkout links and the outbox together. Write external effects to the outbox
|
|
27
|
+
with `EventDispatcher.dispatch`; send them after commit. Driver concurrency must
|
|
28
|
+
not interleave transactions on a shared connection. See [webhooks](Webhooks.md).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Customer portal
|
|
2
|
+
|
|
3
|
+
After authorizing the customer ID, call
|
|
4
|
+
`await vatly.customer(id).portal_session({"returnUrl": "https://app.example.com/billing"})`
|
|
5
|
+
using the production API's request fields. An empty `{}` body is also supported.
|
|
6
|
+
Redirect to `session.url`. It is short-lived/single-use; never log it or use it as
|
|
7
|
+
a permanent account URL. Errors propagate from the SDK without wrapping.
|
|
8
|
+
|
|
9
|
+
Do not accept arbitrary Vatly customer IDs from the browser. Look up the customer's
|
|
10
|
+
binding for the authenticated billable and tenant/storefront/mode first.
|
|
11
|
+
For subscription invoice-address updates, `subscription(local).update_billing()`
|
|
12
|
+
returns a hosted URL with success/cancellation redirects.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Customers
|
|
2
|
+
|
|
3
|
+
Use `customers.create_for(host_id, CustomerProfile(email=..., name=...))` with
|
|
4
|
+
bindings, or `create_unattributed(profile)` to record billing identity without a
|
|
5
|
+
host binding. `attribute(vatly_id, host_id)` checks both sides and delegates atomic
|
|
6
|
+
uniqueness to the driver. It never reassigns identities. Reuse an explicit
|
|
7
|
+
idempotency key when retrying creation after a local binding failure.
|
|
8
|
+
|
|
9
|
+
Look up by `find_by_host_customer_id`, `find_by_vatly_customer_id`,
|
|
10
|
+
`find_one_by_email`, or iterate `find_by_email`. Email is storefront/mode scoped,
|
|
11
|
+
not a global customer key. All host/customer IDs require server authorization.
|
|
12
|
+
|
|
13
|
+
`vatly.customer(id)` memoizes its full SDK resource via `await handle.model()`.
|
|
14
|
+
`name`, `email` and `identity` share the cache; `sync()` refreshes it and `update`
|
|
15
|
+
refreshes from the mutation response. Updating name/email changes communication
|
|
16
|
+
identity, not invoice billing details. Use the hosted portal/billing flows instead.
|
|
17
|
+
|
|
18
|
+
`customer_id_from_checkout(id)` returns billing identity only.
|
|
19
|
+
`claim_customer_from_checkout(id, host_id)` requires host-verified checkout ownership
|
|
20
|
+
and only binds the customer; neither method assigns order/subscription entitlements.
|
|
21
|
+
Resource ownership follows the host's checkout records, never customerId.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Orders and reversals
|
|
2
|
+
|
|
3
|
+
`vatly.order(id).model()` lazily fetches one complete Order. `sync()` refreshes;
|
|
4
|
+
`lines()` shares the cached model; `invoice_url()` reads the invoice link.
|
|
5
|
+
`reversed_subtotal()`/`refundable_subtotal()` return exact `Decimal` currency-unit
|
|
6
|
+
amounts. `is_reversed`, `is_fully_reversed` and `is_partially_reversed` derive from
|
|
7
|
+
both totals. Do not use float arithmetic for money.
|
|
8
|
+
|
|
9
|
+
`refunds()` and `chargebacks()` read optional local repositories or return an empty
|
|
10
|
+
list. To mutate refunds or read any unsupported operation, use `vatly.api.orders`
|
|
11
|
+
and `vatly.api.refunds` directly. Signed reversal snapshots preserve taxes,
|
|
12
|
+
metadata, original-order references and mode. Their ownership follows the original
|
|
13
|
+
order's host checkout link; `entityType=order` does not make a chargeback an Order.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Getting started
|
|
2
|
+
|
|
3
|
+
> **Alpha — under active development. Every alpha release may include breaking changes. Pin exact versions during alpha.**
|
|
4
|
+
|
|
5
|
+
Use Fluent for a billing integration; use the raw SDK for direct API calls. Fluent
|
|
6
|
+
depends on `vatly-api-python==0.1.0a2` and Python 3.10+. Follow the [quick start](../README.md)
|
|
7
|
+
for your first hosted checkout, then add storage for signed events and ownership.
|
|
8
|
+
|
|
9
|
+
| Guide | Responsibility |
|
|
10
|
+
| --- | --- |
|
|
11
|
+
| [Configuration](Configuration.md) | Keys, lifecycle, dependency bootstrap, release |
|
|
12
|
+
| [Core concepts](CoreConcepts.md) | Driver contracts, entities, scope and transactions |
|
|
13
|
+
| [Checkouts](Checkouts.md) | One-off/mixed/subscription builders and retries |
|
|
14
|
+
| [Customers](Customers.md) | Billing identity and immutable bindings |
|
|
15
|
+
| [Customer portal](CustomerPortal.md) | Short-lived hosted portal sessions |
|
|
16
|
+
| [Subscriptions](Subscriptions.md) | Swaps, cancellation, state, reconciliation |
|
|
17
|
+
| [Orders](Orders.md) | Lines, money and reversals |
|
|
18
|
+
| [Webhooks](Webhooks.md) | Signed snapshots, atomic processing and outbox |
|
|
19
|
+
| [Testing](Testing.md) | SQLite example, mock transport and local checks |
|
|
20
|
+
| [Porting](Porting.md) | Source provenance and intentional differences |
|
|
21
|
+
|
|
22
|
+
These standalone Markdown guides mirror the JS docs layout for future vatly-docs
|
|
23
|
+
sync. No docs-site changes or synchronization jobs have been installed here.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Subscriptions
|
|
2
|
+
|
|
3
|
+
Authorize a `LocalSubscription` from your repository, then call
|
|
4
|
+
`vatly.subscription(local)`. `swap(plan_id, body)` defaults to scheduled changes;
|
|
5
|
+
`swap_and_invoice` forces immediate application/invoicing; `swap_without_charge`
|
|
6
|
+
forces immediate application and disables the proration charge. Local data follows
|
|
7
|
+
the API response, so a scheduled swap does not prematurely replace the active plan.
|
|
8
|
+
|
|
9
|
+
`cancel(immediately=True)` sends the API mutation and waits for signed events to
|
|
10
|
+
update local cancellation state. `resume()` clears local `ends_at` after API success.
|
|
11
|
+
`sync()` saves the complete snapshot and derives expiry through `subscription_ends_at`.
|
|
12
|
+
Grace expiry uses the next renewal, renewed-until or trial end (in that order),
|
|
13
|
+
excluding historical dates at/before cancellation, then a previously known valid
|
|
14
|
+
expiry. Conflicting usable trial and cycle deadlines raise `FluentError` rather
|
|
15
|
+
than guessing whether the subscription was on trial; the API omits that flag.
|
|
16
|
+
Equal instants are not conflicting, even with different timezone offsets.
|
|
17
|
+
`canceled_at` is the request time, never a grace deadline. If no deadline
|
|
18
|
+
is available, processing also raises `FluentError` and rolls back; monitor failures and
|
|
19
|
+
reconcile instead of assuming a new expiry. The prior committed state remains
|
|
20
|
+
until recovery, so hosts must apply their own stale-state entitlement policy.
|
|
21
|
+
Terminal cancellation uses `ended_at` or `canceled_at`; an active snapshot clears
|
|
22
|
+
stale expiry after a missed resume. Webhooks and Django reconciliation use the same
|
|
23
|
+
mapping. Core's internal `ends_at` is not currently exposed; `next_renewal_at` alone
|
|
24
|
+
must not be assumed universally present after cancellation.
|
|
25
|
+
`scheduled_update`, `has_scheduled_update`, and `cancellation_reason` read remotely.
|
|
26
|
+
`update_billing(body)` returns a hosted URL; both redirect defaults/overrides are required.
|
|
27
|
+
|
|
28
|
+
`model()` is local. `state()`/`subscription_state(ends_at, now)` implements PHP's
|
|
29
|
+
endsAt predicates: active/valid through grace period, recurring before cancellation,
|
|
30
|
+
ended at or beyond the end time. **Check Vatly status separately before granting
|
|
31
|
+
access**; these convenience predicates do not account for paused/unpaid states.
|
|
32
|
+
|
|
33
|
+
## Initial subscription linking and PR #2910
|
|
34
|
+
|
|
35
|
+
The core PR is not merged at implementation time. Before it, an initial order may
|
|
36
|
+
have `subscription_plan` plus plan ID; there is no deterministic subscription ID
|
|
37
|
+
in that line. Fluent reports `legacy_plan_ids` and does not guess using customerId,
|
|
38
|
+
plan matching or quantity. A trial AUTH_REQUEST order may emit no merchant
|
|
39
|
+
order.paid event; explicitly reconcile the paid checkout's orderId.
|
|
40
|
+
|
|
41
|
+
After the change, initial lines have `subscription` plus intended subscription ID,
|
|
42
|
+
like renewal/update lines. `await vatly.reconcile_checkout(checkout_id)` follows
|
|
43
|
+
host records → checkout → order → distinct subscription IDs, retries each 404 up
|
|
44
|
+
to three times (configurable 1–10), and returns `CheckoutResolution` with resolved
|
|
45
|
+
resources, `pending_subscription_ids`, and legacy IDs. Two lines for the same plan
|
|
46
|
+
can identify different subscriptions; quantity never multiplies IDs.
|
|
47
|
+
|
|
48
|
+
An intended subscription may temporarily be unprojected or never exist for a
|
|
49
|
+
skipped start. Return pending state, enqueue bounded recovery, inspect status,
|
|
50
|
+
and do not grant access from an ID alone. The caller authorizes the checkout and
|
|
51
|
+
wraps local reconciliation writes in its driver transaction. Built-in webhook
|
|
52
|
+
reactions do not make API reads. Historical lines are not backfilled by core.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Testing
|
|
2
|
+
|
|
3
|
+
Run the README quality commands and `.agents/setup` twice for warm setup. Tests
|
|
4
|
+
use `httpx.MockTransport` through the real SDK; no remote mutations or fake parallel
|
|
5
|
+
API implementation. Static fixtures are synthesized from the SDK's pinned
|
|
6
|
+
production OpenAPI examples, not customer-account data.
|
|
7
|
+
|
|
8
|
+
The SQLite driver demonstrates persisted uniqueness, full snapshot storage,
|
|
9
|
+
mode/tenant scoping, immutable checkout links, deduplication, transaction rollback,
|
|
10
|
+
concurrent duplicate delivery and an outbox. It uses one connection/lock per driver
|
|
11
|
+
and is intentionally a small example, not a production multi-worker async adapter.
|
|
12
|
+
|
|
13
|
+
`test_helpers()` delegates test-only API mutations and includes `advance_renewal`,
|
|
14
|
+
`force_renewal_paid/failed` and `force_order_payment_paid/failed`. These helpers
|
|
15
|
+
change Vatly data. Use only with explicit test intent and a test key; the SDK
|
|
16
|
+
blocks live keys. CI and orb setup never use real credentials.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Transactional webhooks
|
|
2
|
+
|
|
3
|
+
Call `await vatly.webhook_processor().handle(raw_bytes, signature_header)` in your
|
|
4
|
+
framework route. Signature/HMAC freshness checks happen before storage, using the
|
|
5
|
+
SDK. Missing/invalid signatures raise `VatlyInvalidSignatureError`. Keep the default
|
|
6
|
+
300-second tolerance; arrays of secrets support rotation. Unknown signed events
|
|
7
|
+
are retained and dispatched, not applied to known repositories.
|
|
8
|
+
|
|
9
|
+
Implement `WebhookCalls.process(event, work)` in **one transaction** shared by all
|
|
10
|
+
drivers. Lock/claim the signed event.id, skip committed duplicates, retain the
|
|
11
|
+
envelope, await work, mark processed and commit. Roll back every write on failure
|
|
12
|
+
so delivery retries can finish. Concurrency requires DB uniqueness/locking, not a
|
|
13
|
+
check-then-insert in memory. Scope every key by tenant/storefront/mode. An unsigned
|
|
14
|
+
Vatly-Event-Id header is not a dedup authority. Mode mismatches fail before storage.
|
|
15
|
+
|
|
16
|
+
| Event | Built-in behavior |
|
|
17
|
+
| --- | --- |
|
|
18
|
+
| subscription.started | Upsert; newly saved row emits local.subscription_created |
|
|
19
|
+
| subscription.updated / billing_updated | Update existing resource; null mandate preserves local value |
|
|
20
|
+
| subscription.resumed | Update existing row; clear ends_at |
|
|
21
|
+
| cancellation / grace-period completion | Update existing row and ends_at |
|
|
22
|
+
| order.paid / payment_failed | Upsert signed snapshot; new paid row emits local.order_created |
|
|
23
|
+
| order.canceled | Update existing snapshot only |
|
|
24
|
+
| refund.* / order.chargeback_* | Optional reversal upsert |
|
|
25
|
+
| checkout.paid | Link own checkout record to order; link subscription IDs from an already stored order |
|
|
26
|
+
| scheduled updates / catalogue / setup / unknown | Dispatch without built-in resource writes |
|
|
27
|
+
|
|
28
|
+
Missing repositories skip persistence, not dispatch. Local-created events fire
|
|
29
|
+
only when a row is first saved, not on every payment status transition. Custom
|
|
30
|
+
`additional_webhook_reactions` run after built-ins and before final dispatch,
|
|
31
|
+
inside the same transaction. Write transactional outbox rows in `events.dispatch`,
|
|
32
|
+
then send external effects after commit. Throw on processing failure; respond 5xx,
|
|
33
|
+
not 2xx, so Vatly retries. A duplicate committed event may respond 200.
|
|
34
|
+
|
|
35
|
+
No implicit API reads occur. All six checkout/order/subscription delivery orders
|
|
36
|
+
are tested to converge using host records and stored snapshots. Missing snapshots,
|
|
37
|
+
AUTH_REQUEST trials and legacy plan references need explicit reconciliation jobs.
|
|
38
|
+
Delayed stale events can still overwrite newer snapshots: dedup is not ordering;
|
|
39
|
+
reconcile conflicts with the API. Never infer ownership from customerId or metadata.
|