vatly-fluent-python 0.1.0a2__tar.gz → 0.1.0a4__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 → vatly_fluent_python-0.1.0a4}/.gitignore +3 -0
- vatly_fluent_python-0.1.0a4/CHANGELOG.md +48 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/PKG-INFO +19 -16
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/PORTING.md +5 -2
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/README.md +16 -14
- vatly_fluent_python-0.1.0a4/docs/Checkouts.md +74 -0
- vatly_fluent_python-0.1.0a4/docs/Configuration.md +74 -0
- vatly_fluent_python-0.1.0a4/docs/CoreConcepts.md +51 -0
- vatly_fluent_python-0.1.0a4/docs/CustomerPortal.md +38 -0
- vatly_fluent_python-0.1.0a4/docs/Customers.md +64 -0
- vatly_fluent_python-0.1.0a4/docs/Development.md +84 -0
- vatly_fluent_python-0.1.0a4/docs/Orders.md +54 -0
- vatly_fluent_python-0.1.0a4/docs/Porting.md +34 -0
- vatly_fluent_python-0.1.0a4/docs/README.md +71 -0
- vatly_fluent_python-0.1.0a4/docs/Subscriptions.md +99 -0
- vatly_fluent_python-0.1.0a4/docs/Testing.md +79 -0
- vatly_fluent_python-0.1.0a4/docs/Webhooks.md +51 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/pyproject.toml +20 -7
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/scripts/check_package.py +2 -3
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/src/vatly_fluent/__init__.py +1 -1
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/src/vatly_fluent/client.py +15 -9
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/src/vatly_fluent/linkage.py +21 -7
- vatly_fluent_python-0.1.0a4/tests/test_docs.py +172 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/tests/test_fluent.py +149 -11
- vatly_fluent_python-0.1.0a2/CHANGELOG.md +0 -23
- vatly_fluent_python-0.1.0a2/docs/Checkouts.md +0 -27
- vatly_fluent_python-0.1.0a2/docs/Configuration.md +0 -33
- vatly_fluent_python-0.1.0a2/docs/CoreConcepts.md +0 -28
- vatly_fluent_python-0.1.0a2/docs/CustomerPortal.md +0 -12
- vatly_fluent_python-0.1.0a2/docs/Customers.md +0 -21
- vatly_fluent_python-0.1.0a2/docs/Orders.md +0 -13
- vatly_fluent_python-0.1.0a2/docs/Porting.md +0 -4
- vatly_fluent_python-0.1.0a2/docs/README.md +0 -23
- vatly_fluent_python-0.1.0a2/docs/Subscriptions.md +0 -52
- vatly_fluent_python-0.1.0a2/docs/Testing.md +0 -16
- vatly_fluent_python-0.1.0a2/docs/Webhooks.md +0 -39
- vatly_fluent_python-0.1.0a2/vendor/README.md +0 -16
- vatly_fluent_python-0.1.0a2/vendor/SHA256SUMS +0 -1
- vatly_fluent_python-0.1.0a2/vendor/vatly_api_python-0.1.0a2-py3-none-any.whl +0 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/LICENSE +0 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/examples/sqlite_driver.py +0 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/src/vatly_fluent/builders.py +0 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/src/vatly_fluent/contracts.py +0 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/src/vatly_fluent/customers.py +0 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/src/vatly_fluent/handles.py +0 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/src/vatly_fluent/py.typed +0 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/src/vatly_fluent/webhooks.py +0 -0
- {vatly_fluent_python-0.1.0a2 → vatly_fluent_python-0.1.0a4}/tests/fixtures/resources.json +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0a4 — 2026-11-25
|
|
4
|
+
|
|
5
|
+
- Require `vatly-api-python==0.1.0a4`.
|
|
6
|
+
- Stored refunds and refund webhook snapshots carry `Refund.metadata` (None when
|
|
7
|
+
the refund was created without metadata).
|
|
8
|
+
- Checkout builders reject invalid metadata (non-string values, more than 50 keys,
|
|
9
|
+
keys over 40 or values over 500 characters) and `trialDays` below 1 with
|
|
10
|
+
`FluentError("Invalid checkout request")` before calling Vatly, instead of the
|
|
11
|
+
API's `VatlyValidationError`.
|
|
12
|
+
- Behaviour change from the SDK: dictionary bodies passed to customer and
|
|
13
|
+
subscription calls are validated before sending, so invalid input raises Pydantic's
|
|
14
|
+
`ValidationError` instead of `VatlyValidationError`. Fields the API schema does not
|
|
15
|
+
define are dropped, and `None` is sent only on nullable fields.
|
|
16
|
+
|
|
17
|
+
## 0.1.0a3 — 2026-11-13
|
|
18
|
+
|
|
19
|
+
- Link initial orders to their subscriptions through
|
|
20
|
+
`lines[].relatedResources.subscriptionId` in `order.paid`/`checkout.paid` reactions
|
|
21
|
+
and `reconcile_checkout`.
|
|
22
|
+
- `reconcile_checkout` reports signup lines with a still-null `subscriptionId` as
|
|
23
|
+
`unresolved_line_ids`; `legacy_plan_ids` now lists only plan lines without
|
|
24
|
+
`relatedResources` (historical orders).
|
|
25
|
+
- Require `vatly-api-python==0.1.0a3` from PyPI; drop the vendored SDK wheel.
|
|
26
|
+
- Refresh installation, European positioning and published-package documentation.
|
|
27
|
+
|
|
28
|
+
## 0.1.0a2 — 2026-11-12
|
|
29
|
+
|
|
30
|
+
- Use distribution `vatly-fluent-python`; imports remain `vatly_fluent`.
|
|
31
|
+
- Depend on the renamed SDK distribution `vatly-api-python` (import `vatly`).
|
|
32
|
+
- Derive grace expiry from period/trial deadlines, not cancellation request time.
|
|
33
|
+
- Share lifecycle mapping across signed reactions, sync and Django reconciliation;
|
|
34
|
+
repair legacy expiry on sync and clear it after missed resume.
|
|
35
|
+
- Reject unknown grace expiry transactionally rather than guessing a deadline.
|
|
36
|
+
- Reject conflicting trial/cycle grace deadlines; the API omits core's trial flag.
|
|
37
|
+
- Require corrected SDK 0.1.0a2; refresh the unpublished bootstrap wheel.
|
|
38
|
+
|
|
39
|
+
## 0.1.0a1 — Unpublished development snapshot
|
|
40
|
+
|
|
41
|
+
> Alpha — under active development. Every alpha release may include breaking changes. Pin exact versions during alpha.
|
|
42
|
+
|
|
43
|
+
- Initial async-first Fluent Python port: builders, handles, customer services,
|
|
44
|
+
pluggable storage, transactional webhook reactions and signed snapshots.
|
|
45
|
+
- Host-owned checkout/entity linkage, PR #2910-compatible subscription references,
|
|
46
|
+
bounded recovery, historical plan-line reporting, and no customerId ownership fallback.
|
|
47
|
+
- Typed package, SQLite transaction/outbox example, tests, guides, CI, trusted
|
|
48
|
+
publishing workflow and idempotent orb setup.
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vatly-fluent-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.0a4
|
|
4
4
|
Summary: Framework-independent fluent billing integrations built on the Vatly Python SDK
|
|
5
5
|
Project-URL: Homepage, https://github.com/vatly/vatly-fluent-python
|
|
6
6
|
Project-URL: Documentation, https://docs.vatly.com
|
|
7
7
|
Project-URL: Issues, https://github.com/vatly/vatly-fluent-python/issues
|
|
8
8
|
License-Expression: MIT
|
|
9
9
|
License-File: LICENSE
|
|
10
|
+
Keywords: ai,billing,merchant-of-record,payments,subscriptions,vat,vatly
|
|
10
11
|
Classifier: Development Status :: 3 - Alpha
|
|
11
12
|
Classifier: Programming Language :: Python :: 3
|
|
12
13
|
Classifier: Typing :: Typed
|
|
13
14
|
Requires-Python: >=3.10
|
|
14
|
-
Requires-Dist: vatly-api-python==0.1.
|
|
15
|
+
Requires-Dist: vatly-api-python==0.1.0a4
|
|
15
16
|
Description-Content-Type: text/markdown
|
|
16
17
|
|
|
17
18
|
# Vatly Fluent for Python
|
|
18
19
|
|
|
19
|
-
> **Alpha — under active development. Every alpha release may include breaking changes.
|
|
20
|
+
> **Alpha — under active development. Every alpha release may include breaking changes. Lock the version you install and review the release notes before upgrading.**
|
|
20
21
|
|
|
21
|
-
Integrate Vatly
|
|
22
|
+
Integrate billing with Vatly, the European Merchant of Record for AI, software and
|
|
23
|
+
digital products, without tying your application to a framework or database.
|
|
22
24
|
Fluent adds chainable checkout/subscription builders, customer and subscription
|
|
23
25
|
handles, pluggable persistence, and a signed webhook-to-domain-event pipeline on
|
|
24
26
|
top of `vatly-api-python`. Your application owns authentication, entitlements, storage,
|
|
@@ -26,16 +28,14 @@ transactions and jobs. Python 3.10+, fully typed, **async-first**.
|
|
|
26
28
|
|
|
27
29
|
## Install
|
|
28
30
|
|
|
29
|
-
Once both packages are published:
|
|
30
|
-
|
|
31
31
|
```bash
|
|
32
|
-
pip install vatly-fluent-python
|
|
32
|
+
pip install --pre vatly-fluent-python
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
`--pre` installs the latest alpha, including the matching `vatly-api-python` alpha.
|
|
36
|
+
|
|
37
|
+
For development, run `.agents/setup` or `uv sync --locked`. Both development and
|
|
38
|
+
package metadata use the exact SDK version from PyPI.
|
|
39
39
|
|
|
40
40
|
## First checkout
|
|
41
41
|
|
|
@@ -86,11 +86,12 @@ falls back to `customerId`, which is only billing identity and may be shared or
|
|
|
86
86
|
Metadata is correlation data, not authorization. A signed webhook authenticates
|
|
87
87
|
Vatly's snapshot; it does not authorize a browser-provided entity ID.
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
subscription
|
|
91
|
-
|
|
92
|
-
`
|
|
93
|
-
|
|
89
|
+
Linkage follows each order line's `relatedResources.subscriptionId`, which names
|
|
90
|
+
the signup's subscription on the initial order, and `productType="subscription"`
|
|
91
|
+
renewal lines. `subscription_plan` product IDs remain plan references. A signed
|
|
92
|
+
`order.paid` snapshot can carry a null `subscriptionId`; reconcile the checkout to
|
|
93
|
+
read the current order. See [Subscriptions](docs/Subscriptions.md).
|
|
94
|
+
Fluent never guesses a subscription from a customer, plan or quantity.
|
|
94
95
|
|
|
95
96
|
## Learn the integration
|
|
96
97
|
|
|
@@ -103,6 +104,8 @@ an intended ID alone is not evidence of active service.
|
|
|
103
104
|
|
|
104
105
|
## Develop
|
|
105
106
|
|
|
107
|
+
See the [development guide](docs/Development.md) for setup and contributor checks.
|
|
108
|
+
|
|
106
109
|
```bash
|
|
107
110
|
uv sync --locked
|
|
108
111
|
uv run ruff check .
|
|
@@ -30,8 +30,11 @@ customer-binding fallback. `EntityRef(kind, id)` supports teams/users/organizati
|
|
|
30
30
|
billing identities and cannot establish entitlement ownership. Drivers enforce
|
|
31
31
|
immutable links and scope every lookup by tenant, storefront and API mode.
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
Core [PR #2910](https://github.com/sandervanhooft/vatlify/pull/2910) adds nullable
|
|
34
|
+
`lines[].relatedResources.subscriptionId` and preserves `productType`/`productId`.
|
|
35
|
+
Linkage reads that field (and `subscription` renewal product IDs) to link a checkout's
|
|
36
|
+
order to its subscriptions. A null `subscriptionId` on a signup line means core has
|
|
37
|
+
not resolved it yet; frozen webhook snapshots keep the original value.
|
|
35
38
|
`subscription_plan` lines are preserved but never treated as subscription IDs.
|
|
36
39
|
Quantity does not multiply subscription IDs; two checkout plan lines can produce
|
|
37
40
|
distinct subscription IDs for the same plan. `reconcile_checkout` explicitly reads
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# Vatly Fluent for Python
|
|
2
2
|
|
|
3
|
-
> **Alpha — under active development. Every alpha release may include breaking changes.
|
|
3
|
+
> **Alpha — under active development. Every alpha release may include breaking changes. Lock the version you install and review the release notes before upgrading.**
|
|
4
4
|
|
|
5
|
-
Integrate Vatly
|
|
5
|
+
Integrate billing with Vatly, the European Merchant of Record for AI, software and
|
|
6
|
+
digital products, without tying your application to a framework or database.
|
|
6
7
|
Fluent adds chainable checkout/subscription builders, customer and subscription
|
|
7
8
|
handles, pluggable persistence, and a signed webhook-to-domain-event pipeline on
|
|
8
9
|
top of `vatly-api-python`. Your application owns authentication, entitlements, storage,
|
|
@@ -10,16 +11,14 @@ transactions and jobs. Python 3.10+, fully typed, **async-first**.
|
|
|
10
11
|
|
|
11
12
|
## Install
|
|
12
13
|
|
|
13
|
-
Once both packages are published:
|
|
14
|
-
|
|
15
14
|
```bash
|
|
16
|
-
pip install vatly-fluent-python
|
|
15
|
+
pip install --pre vatly-fluent-python
|
|
17
16
|
```
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
`--pre` installs the latest alpha, including the matching `vatly-api-python` alpha.
|
|
19
|
+
|
|
20
|
+
For development, run `.agents/setup` or `uv sync --locked`. Both development and
|
|
21
|
+
package metadata use the exact SDK version from PyPI.
|
|
23
22
|
|
|
24
23
|
## First checkout
|
|
25
24
|
|
|
@@ -70,11 +69,12 @@ falls back to `customerId`, which is only billing identity and may be shared or
|
|
|
70
69
|
Metadata is correlation data, not authorization. A signed webhook authenticates
|
|
71
70
|
Vatly's snapshot; it does not authorize a browser-provided entity ID.
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
subscription
|
|
75
|
-
|
|
76
|
-
`
|
|
77
|
-
|
|
72
|
+
Linkage follows each order line's `relatedResources.subscriptionId`, which names
|
|
73
|
+
the signup's subscription on the initial order, and `productType="subscription"`
|
|
74
|
+
renewal lines. `subscription_plan` product IDs remain plan references. A signed
|
|
75
|
+
`order.paid` snapshot can carry a null `subscriptionId`; reconcile the checkout to
|
|
76
|
+
read the current order. See [Subscriptions](docs/Subscriptions.md).
|
|
77
|
+
Fluent never guesses a subscription from a customer, plan or quantity.
|
|
78
78
|
|
|
79
79
|
## Learn the integration
|
|
80
80
|
|
|
@@ -87,6 +87,8 @@ an intended ID alone is not evidence of active service.
|
|
|
87
87
|
|
|
88
88
|
## Develop
|
|
89
89
|
|
|
90
|
+
See the [development guide](docs/Development.md) for setup and contributor checks.
|
|
91
|
+
|
|
90
92
|
```bash
|
|
91
93
|
uv sync --locked
|
|
92
94
|
uv run ruff check .
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Create hosted checkouts
|
|
2
|
+
|
|
3
|
+
Build a cart, then call `create()` to make the API request. The result is a full
|
|
4
|
+
SDK Checkout with Fluent's `get_url()` convenience. Pass the configured
|
|
5
|
+
`vatly` from [Configuration](Configuration.md) to these functions.
|
|
6
|
+
|
|
7
|
+
## Sell a one-off or mixed cart
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from vatly import RequestOptions
|
|
11
|
+
from vatly_fluent import CustomerProfile, EntityRef, Vatly
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def example(vatly: Vatly):
|
|
15
|
+
checkout = (
|
|
16
|
+
await vatly.checkout_builder(CustomerProfile(vatly_id="customer_example"))
|
|
17
|
+
.with_items(
|
|
18
|
+
[
|
|
19
|
+
{"id": "one_off_product_example", "quantity": 2},
|
|
20
|
+
{"id": "subscription_plan_example", "quantity": 1},
|
|
21
|
+
]
|
|
22
|
+
)
|
|
23
|
+
.with_metadata({"purchaseId": "42"})
|
|
24
|
+
.for_entity(EntityRef("team", "42"))
|
|
25
|
+
.create(options=RequestOptions(idempotency_key="purchase:42"))
|
|
26
|
+
)
|
|
27
|
+
return checkout.id, checkout.get_url()
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The customer and entity must already be authorized. Omit the profile for a guest
|
|
31
|
+
checkout. `.for_entity()` needs the checkout-record driver.
|
|
32
|
+
|
|
33
|
+
Metadata values must be strings, with at most 50 keys, keys up to 40 characters
|
|
34
|
+
and values up to 500. `create()` checks the request against the API schema and
|
|
35
|
+
raises `FluentError` before sending when it does not match. Fields the schema
|
|
36
|
+
does not define are dropped.
|
|
37
|
+
|
|
38
|
+
## Start a subscription with a trial
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from vatly import RequestOptions
|
|
42
|
+
from vatly_fluent import Vatly
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def example(vatly: Vatly):
|
|
46
|
+
return (
|
|
47
|
+
await vatly.subscribe()
|
|
48
|
+
.to_plan("subscription_plan_example")
|
|
49
|
+
.with_quantity(3)
|
|
50
|
+
.with_trial_days(14)
|
|
51
|
+
.in_testmode()
|
|
52
|
+
.create(options=RequestOptions(idempotency_key="trial:42"))
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`subscribe().create()` creates a **checkout**, not an immediate subscription.
|
|
57
|
+
Use the general builder for mixed carts. Reusing a subscription builder replaces
|
|
58
|
+
its plan item rather than appending another.
|
|
59
|
+
|
|
60
|
+
| Builder method | Purpose |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `with_items` | Append detached cart items |
|
|
63
|
+
| `to_plan`, `with_quantity` | Select one plan and a positive integer quantity |
|
|
64
|
+
| `with_trial_days`, `with_trial_ends_at` | Trial length or aware deadline, rounded up to whole days |
|
|
65
|
+
| `with_redirect_url_success`, `with_redirect_url_canceled` | Override default redirects |
|
|
66
|
+
| `with_locale`, `with_metadata`, `with_billing_address` | Add checkout details |
|
|
67
|
+
| `payload` | Inspect a detached wire-format dictionary without a request |
|
|
68
|
+
| `in_testmode`, `in_live_mode` | Assert the existing key's mode |
|
|
69
|
+
|
|
70
|
+
Store the purchase key before the API call and reuse it after ambiguous failures,
|
|
71
|
+
including a local-save failure after remote success. The redirect does not prove
|
|
72
|
+
payment; use [webhooks](Webhooks.md). Read lines through `checkout.order_id`'s Order.
|
|
73
|
+
|
|
74
|
+
[Checkout API reference](https://docs.vatly.com/api-reference/checkouts)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Configure Fluent
|
|
2
|
+
|
|
3
|
+
Keep the SDK client open for your application or worker lifespan. Fluent reuses
|
|
4
|
+
it; the caller remains responsible for closing it. See [installation](README.md).
|
|
5
|
+
|
|
6
|
+
## Add your storage driver
|
|
7
|
+
|
|
8
|
+
The `driver` below is your implementation of the [storage contracts](CoreConcepts.md).
|
|
9
|
+
Use one scope per tenant, storefront and test/live mode. Django users can use
|
|
10
|
+
`vatly-django` instead of implementing this adapter.
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
from vatly import AsyncVatlyClient
|
|
14
|
+
from vatly_fluent import Vatly, Wiring
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def example(api: AsyncVatlyClient, driver):
|
|
18
|
+
return Vatly(
|
|
19
|
+
Wiring(
|
|
20
|
+
api=api,
|
|
21
|
+
redirect_url_success="https://app.example.com/billing/success",
|
|
22
|
+
redirect_url_canceled="https://app.example.com/billing/canceled",
|
|
23
|
+
webhook_secret="replace-with-your-endpoint-secret",
|
|
24
|
+
checkouts=driver.checkouts,
|
|
25
|
+
bindings=driver.bindings,
|
|
26
|
+
orders=driver.orders,
|
|
27
|
+
subscriptions=driver.subscriptions,
|
|
28
|
+
refunds=driver.refunds,
|
|
29
|
+
chargebacks=driver.chargebacks,
|
|
30
|
+
webhook_calls=driver,
|
|
31
|
+
events=driver,
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Load the endpoint secret from your secret manager rather than a source-code literal.
|
|
37
|
+
The sample value is only a placeholder.
|
|
38
|
+
|
|
39
|
+
| Wiring field | Required for |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `api`, both redirect URLs | Hosted checkout creation |
|
|
42
|
+
| `checkouts` | `.for_entity(...)` and resource ownership links |
|
|
43
|
+
| `bindings` | Customer-to-host identity mapping |
|
|
44
|
+
| `orders`, `subscriptions` | Local signed snapshots and lifecycle helpers |
|
|
45
|
+
| `refunds`, `chargebacks` | Optional local reversal records |
|
|
46
|
+
| `webhook_secret`, `webhook_calls`, `events` | Verified, transactional delivery and outbox |
|
|
47
|
+
|
|
48
|
+
Missing wiring fails when its feature is used. API-only checkout creation does not
|
|
49
|
+
require repositories. A customer email in a profile does not create a remote customer.
|
|
50
|
+
|
|
51
|
+
## Retry the same business operation
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from vatly import RequestOptions
|
|
55
|
+
from vatly_fluent import Vatly
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
async def example(vatly: Vatly):
|
|
59
|
+
return (
|
|
60
|
+
await vatly.checkout_builder()
|
|
61
|
+
.with_items(
|
|
62
|
+
[
|
|
63
|
+
{"id": "one_off_product_example", "quantity": 1},
|
|
64
|
+
]
|
|
65
|
+
)
|
|
66
|
+
.create(options=RequestOptions(idempotency_key="purchase:42", timeout=10))
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Persist that key before calling. Reuse it after a network or local-save failure;
|
|
71
|
+
do not generate a second purchase key on retry. SDK errors propagate unchanged.
|
|
72
|
+
Live/test keys share a host; `.in_testmode()` checks the key, not switches it.
|
|
73
|
+
|
|
74
|
+
[API reference](https://docs.vatly.com/api-reference)
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Store ownership safely
|
|
2
|
+
|
|
3
|
+
Your application decides which user, team or organization owns a purchase. Fluent
|
|
4
|
+
stores that decision as an `EntityRef` on your checkout record. A customer binding
|
|
5
|
+
is billing identity only; it never grants access to another entity's resources.
|
|
6
|
+
|
|
7
|
+
## Attach an authorized entity
|
|
8
|
+
|
|
9
|
+
```python
|
|
10
|
+
from vatly import RequestOptions
|
|
11
|
+
from vatly_fluent import EntityRef, Vatly
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def example(vatly: Vatly):
|
|
15
|
+
# The host must authorize team 42 before running this function.
|
|
16
|
+
return (
|
|
17
|
+
await vatly.subscribe()
|
|
18
|
+
.to_plan("subscription_plan_example")
|
|
19
|
+
.for_entity(EntityRef("team", "42"))
|
|
20
|
+
.create(options=RequestOptions(idempotency_key="team-42:purchase-1"))
|
|
21
|
+
)
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Save the checkout record durably. Signed checkout/order/subscription snapshots
|
|
25
|
+
then follow those links; never infer ownership from email, customerId or metadata.
|
|
26
|
+
|
|
27
|
+
## Implement the storage contracts
|
|
28
|
+
|
|
29
|
+
| Contract | Methods or responsibility |
|
|
30
|
+
| --- | --- |
|
|
31
|
+
| `CheckoutRecords` | `record`, `find`, `link`, `find_for_resource`; reject conflicting ownership |
|
|
32
|
+
| `CustomerBindings` | `bind`, `record`, lookups both ways; unique on both identities |
|
|
33
|
+
| `Repository` | `find_by_vatly_id`, `store`, `update` complete wrapper records |
|
|
34
|
+
| `ReversalRepository` | Repository plus `list_for_order`, `list_for_customer` |
|
|
35
|
+
| `WebhookCalls` | `process(event, work)` claims signed ID, runs work and commits atomically |
|
|
36
|
+
| `EventDispatcher` | `dispatch(event)` writes a transactional outbox entry |
|
|
37
|
+
|
|
38
|
+
All methods are async. `Stored[T]` contains `resource` and optional `entity`;
|
|
39
|
+
`LocalSubscription` also contains `ends_at`. Updates omit unchanged fields; None
|
|
40
|
+
explicitly clears a field. A repository may decline a new save by returning None.
|
|
41
|
+
|
|
42
|
+
Scope every unique key and lookup by tenant, storefront and mode. Use database
|
|
43
|
+
constraints and locks, not an in-memory check followed by an insert. Webhook audit,
|
|
44
|
+
deduplication, links, snapshots and outbox must share one transaction.
|
|
45
|
+
|
|
46
|
+
The repository's `examples/sqlite_driver.py` is a runnable reference, not an installed
|
|
47
|
+
production driver. It uses one connection and lock per instance. Use an async-native
|
|
48
|
+
database driver or your framework's thread/transaction adapter for production.
|
|
49
|
+
For Django, use its supplied ORMDriver. See [webhook processing](Webhooks.md).
|
|
50
|
+
|
|
51
|
+
[API reference](https://docs.vatly.com/api-reference)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Open the customer portal
|
|
2
|
+
|
|
3
|
+
Send an authenticated buyer to Vatly's hosted portal to manage subscriptions,
|
|
4
|
+
invoices and billing details. Create a new session for each visit.
|
|
5
|
+
|
|
6
|
+
```python
|
|
7
|
+
from vatly_fluent import FluentError, Vatly
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
async def example(vatly: Vatly):
|
|
11
|
+
# The host authorizes user-42 before this lookup.
|
|
12
|
+
customer = await vatly.customers.find_by_host_customer_id("user-42")
|
|
13
|
+
if customer is None:
|
|
14
|
+
raise FluentError("No billing customer is bound to this user")
|
|
15
|
+
session = await vatly.customer(customer.id).portal_session(
|
|
16
|
+
{
|
|
17
|
+
"returnUrl": "https://app.example.com/account/billing",
|
|
18
|
+
}
|
|
19
|
+
)
|
|
20
|
+
return session.url
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Pass the configured `vatly` from [Configuration](Configuration.md). The key selects
|
|
24
|
+
the storefront and mode; the portal does not show a storefront picker.
|
|
25
|
+
|
|
26
|
+
| Field | Meaning |
|
|
27
|
+
| --- | --- |
|
|
28
|
+
| Input `returnUrl` | Optional HTTPS return link; `{}` omits it |
|
|
29
|
+
| Response `url` | Short-lived, single-use credential-bearing entry URL |
|
|
30
|
+
| Response `expires_at` | Expiry of that entry link |
|
|
31
|
+
|
|
32
|
+
Redirect the browser to `session.url`. Do not log, cache, email as a permanent link,
|
|
33
|
+
or expose a portal session for an unverified customer ID. SDK errors propagate.
|
|
34
|
+
|
|
35
|
+
For one subscription's invoice-address change, use its
|
|
36
|
+
`update_billing()` helper in [Subscriptions](Subscriptions.md).
|
|
37
|
+
|
|
38
|
+
[Portal API reference](https://docs.vatly.com/api-reference/customers)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Create and find customers
|
|
2
|
+
|
|
3
|
+
Bind a host user to a Vatly billing identity once, then reuse it. Bindings require
|
|
4
|
+
the configured storage driver; examples accept `vatly` from [Configuration](Configuration.md).
|
|
5
|
+
|
|
6
|
+
## Create a customer for a host user
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
from vatly import RequestOptions
|
|
10
|
+
from vatly_fluent import CustomerProfile, Vatly
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
async def example(vatly: Vatly):
|
|
14
|
+
return await vatly.customers.create_for(
|
|
15
|
+
"user-42",
|
|
16
|
+
CustomerProfile(email="buyer@example.com", name="Alex"),
|
|
17
|
+
options=RequestOptions(idempotency_key="signup:user-42"),
|
|
18
|
+
)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`create_for` rejects an already-bound host. To reuse an existing customer, authorize
|
|
22
|
+
its ID then call `await vatly.customers.attribute(customer_id, host_id)` instead.
|
|
23
|
+
Conflicting bindings fail rather than silently moving customers between users.
|
|
24
|
+
|
|
25
|
+
| Profile field | Meaning |
|
|
26
|
+
| --- | --- |
|
|
27
|
+
| `vatly_id` | Existing authorized customer, used by checkout builders |
|
|
28
|
+
| `email` | Required when creating a new customer |
|
|
29
|
+
| `name` | Optional communication name |
|
|
30
|
+
|
|
31
|
+
An email-only checkout profile does not create a customer. Explicitly create it
|
|
32
|
+
first if you need a durable binding. Bindings do not assign order ownership.
|
|
33
|
+
|
|
34
|
+
## Look up and refresh identity
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from vatly_fluent import Vatly
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
async def example(vatly: Vatly):
|
|
41
|
+
found = await vatly.customers.find_one_by_email("buyer@example.com")
|
|
42
|
+
handle = vatly.customer("customer_example")
|
|
43
|
+
identity = await handle.identity()
|
|
44
|
+
await handle.update({"name": "Alex Morgan"})
|
|
45
|
+
await handle.sync()
|
|
46
|
+
return found, identity, await handle.email()
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`model()`, `name()`, `email()` and `identity()` share a cached snapshot. `sync()`
|
|
50
|
+
and `update()` refresh it. Name/email are not invoice address fields; use the
|
|
51
|
+
[portal](CustomerPortal.md) for hosted billing management. The SDK checks customer
|
|
52
|
+
bodies before sending; an invalid one raises Pydantic's `ValidationError`.
|
|
53
|
+
|
|
54
|
+
| Lookup | Return |
|
|
55
|
+
| --- | --- |
|
|
56
|
+
| `find_by_host_customer_id` | Customer or None |
|
|
57
|
+
| `find_by_vatly_customer_id` | Customer, or the SDK's not-found error |
|
|
58
|
+
| `find_by_email` | Async iterator of matching customers |
|
|
59
|
+
| `find_one_by_email` | First match or None, not a global identity assertion |
|
|
60
|
+
|
|
61
|
+
`claim_customer_from_checkout` is only for an already host-authorized checkout;
|
|
62
|
+
it binds billing identity, not entitlements. Never accept arbitrary buyer-supplied IDs.
|
|
63
|
+
|
|
64
|
+
[Customer API reference](https://docs.vatly.com/api-reference/customers)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Development and release
|
|
3
|
+
description: Set up the repository, test billing integrations and build the Fluent package locally.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Development and release
|
|
7
|
+
|
|
8
|
+
## Set up the repository
|
|
9
|
+
|
|
10
|
+
Run commands from the repository root. On Linux or in an Amp orb:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
.agents/setup
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Setup installs uv 0.12.9 and Python 3.12, restores locked dependencies and checks
|
|
17
|
+
imports. It needs no API credentials and makes no Vatly calls.
|
|
18
|
+
|
|
19
|
+
## Run tests
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
uv run pytest --cov
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Tests use the real SDK with local HTTP and signed webhook fixtures. The SQLite
|
|
26
|
+
driver tests cover storage, ownership, duplicate delivery, rollback and the outbox.
|
|
27
|
+
No test changes a Vatly account. See [offline examples](Testing.md) for host tests.
|
|
28
|
+
|
|
29
|
+
## Check formatting and types
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
uv run ruff check .
|
|
33
|
+
uv run ruff format --check .
|
|
34
|
+
uv run mypy
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
CI runs tests and these checks on Python 3.10–3.14. Type checks also include the
|
|
38
|
+
example storage driver.
|
|
39
|
+
|
|
40
|
+
## Build and check the package
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
uv build
|
|
44
|
+
uv run twine check dist/*
|
|
45
|
+
uv run python scripts/check_package.py
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The last command installs the built wheel in a fresh environment and checks
|
|
49
|
+
imports and `py.typed`. These commands do not publish anything.
|
|
50
|
+
|
|
51
|
+
## Pinned SDK dependency
|
|
52
|
+
|
|
53
|
+
Fluent pins one exact `vatly-api-python` version from PyPI in `pyproject.toml`;
|
|
54
|
+
`uv.lock` records its hashes. To move to a new SDK version, change the pin, run
|
|
55
|
+
`uv lock`, and run the full checks. Use a new Fluent alpha version when dependency
|
|
56
|
+
behavior changes.
|
|
57
|
+
|
|
58
|
+
## Documentation sync
|
|
59
|
+
|
|
60
|
+
Keep guides directly under `docs/` and link each page from [the overview](README.md).
|
|
61
|
+
Pushes to `main` affecting `docs/**` notify `vatly/vatly-docs`. The notifier needs
|
|
62
|
+
`VATLY_DOCS_DISPATCH_TOKEN` with Contents: write access to that repository.
|
|
63
|
+
The sync uses an explicit frontmatter description when present, otherwise the
|
|
64
|
+
page's introductory sentence.
|
|
65
|
+
|
|
66
|
+
## Prepare a release
|
|
67
|
+
|
|
68
|
+
The published package is [vatly-fluent-python](https://pypi.org/project/vatly-fluent-python/);
|
|
69
|
+
the import name is `vatly_fluent`. Publish the matching SDK version first, then
|
|
70
|
+
Fluent, then Django, only after review and approval.
|
|
71
|
+
|
|
72
|
+
| PyPI trusted publisher field | Value |
|
|
73
|
+
| --- | --- |
|
|
74
|
+
| Owner | `vatly` |
|
|
75
|
+
| Repository | `vatly-fluent-python` |
|
|
76
|
+
| Workflow | `release.yml` |
|
|
77
|
+
| Environment | Leave blank |
|
|
78
|
+
|
|
79
|
+
The workflow publishes only from a published GitHub release whose tag matches
|
|
80
|
+
`v` plus the package version. Mark alphas as pre-releases. Pushing `main` does not
|
|
81
|
+
publish. Restrict release access: trusted publishing needs no environment approval
|
|
82
|
+
or PyPI token, and PyPI artifacts are public.
|
|
83
|
+
|
|
84
|
+
[Storage contracts](CoreConcepts.md) · [Porting notes](Porting.md)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Read orders and reversals
|
|
2
|
+
|
|
3
|
+
Use an order handle to read purchased lines, an invoice link and exact reversal
|
|
4
|
+
amounts. Authorize the order in your application first. Examples accept the
|
|
5
|
+
configured `vatly` from [Configuration](Configuration.md).
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from vatly_fluent import Vatly
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
async def example(vatly: Vatly):
|
|
12
|
+
order = vatly.order("order_example")
|
|
13
|
+
return {
|
|
14
|
+
"invoice_url": await order.invoice_url(),
|
|
15
|
+
"lines": await order.lines(),
|
|
16
|
+
"refundable": await order.refundable_subtotal(),
|
|
17
|
+
"partially_reversed": await order.is_partially_reversed(),
|
|
18
|
+
"refunds": await order.refunds(),
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
| Method | Return |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| `model`, `sync` | Cached SDK Order; refresh the handle |
|
|
25
|
+
| `invoice_url` | Customer invoice URL or None |
|
|
26
|
+
| `lines` | OrderLine models |
|
|
27
|
+
| `reversed_subtotal`, `refundable_subtotal` | `Decimal` in currency units |
|
|
28
|
+
| `is_reversed`, `is_fully_reversed`, `is_partially_reversed` | Predicates derived from both totals |
|
|
29
|
+
| `refunds`, `chargebacks` | Local stored records, or an empty list without repositories; a refund keeps the `metadata` it was created with, or None |
|
|
30
|
+
|
|
31
|
+
`model()` and the derived fields share one lazy read; `sync()` refreshes it. Do not
|
|
32
|
+
convert financial values to floats. Preserve each amount's currency from the SDK
|
|
33
|
+
resource when combining totals.
|
|
34
|
+
|
|
35
|
+
## Request a full refund
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from vatly import RequestOptions
|
|
39
|
+
from vatly_fluent import Vatly
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
async def example(vatly: Vatly):
|
|
43
|
+
return await vatly.api.orders.create_full_refund(
|
|
44
|
+
"order_example",
|
|
45
|
+
{},
|
|
46
|
+
options=RequestOptions(idempotency_key="refund:42"),
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Fluent exposes the raw SDK as `vatly.api` for operations without a convenience
|
|
51
|
+
handle. A timeout is ambiguous; reuse the same refund key instead of issuing a
|
|
52
|
+
second refund. Signed reversal events update optional local repositories.
|
|
53
|
+
|
|
54
|
+
[Order API reference](https://docs.vatly.com/api-reference/orders) · [Refund reference](https://docs.vatly.com/api-reference/refunds)
|