vatly-fluent-python 0.1.0a4__tar.gz → 0.1.0a5__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.0a4 → vatly_fluent_python-0.1.0a5}/CHANGELOG.md +15 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/PKG-INFO +9 -4
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/README.md +7 -2
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/Checkouts.md +27 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/pyproject.toml +2 -2
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/__init__.py +1 -2
- vatly_fluent_python-0.1.0a5/src/vatly_fluent/_version.py +1 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/builders.py +45 -1
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/client.py +5 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/tests/test_fluent.py +49 -1
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/.gitignore +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/LICENSE +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/PORTING.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/Configuration.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/CoreConcepts.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/CustomerPortal.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/Customers.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/Development.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/Orders.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/Porting.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/README.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/Subscriptions.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/Testing.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/docs/Webhooks.md +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/examples/sqlite_driver.py +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/scripts/check_package.py +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/contracts.py +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/customers.py +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/handles.py +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/linkage.py +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/py.typed +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/webhooks.py +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/tests/fixtures/resources.json +0 -0
- {vatly_fluent_python-0.1.0a4 → vatly_fluent_python-0.1.0a5}/tests/test_docs.py +0 -0
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.1.0a5 — 2026-11-30
|
|
6
|
+
|
|
7
|
+
- Require `vatly-api-python==0.1.0a5`, which adds checkout and order discounts and
|
|
8
|
+
`add_version_string`, so Fluent's `User-Agent` token is now sent.
|
|
9
|
+
- `with_percentage_discount()` and `with_amount_discount()` on the checkout and
|
|
10
|
+
subscription builders add a checkout discount: a percentage, or a fixed EUR
|
|
11
|
+
amount on the products' tax basis, with an optional description. It reduces each
|
|
12
|
+
product's first payment, after the trial for a subscription on trial. Each call
|
|
13
|
+
adds one; Vatly takes one per checkout for now.
|
|
14
|
+
- `Vatly(...)` appends `vatly/vatly-fluent-python/<version>` to the SDK client's
|
|
15
|
+
`User-Agent`, once per client, using the SDK's `add_version_string`
|
|
16
|
+
(vatly/vatly-api-python#5). With an SDK that lacks it, nothing changes.
|
|
17
|
+
|
|
3
18
|
## 0.1.0a4 — 2026-11-25
|
|
4
19
|
|
|
5
20
|
- Require `vatly-api-python==0.1.0a4`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vatly-fluent-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.0a5
|
|
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
|
|
@@ -12,7 +12,7 @@ Classifier: Development Status :: 3 - Alpha
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
13
13
|
Classifier: Typing :: Typed
|
|
14
14
|
Requires-Python: >=3.10
|
|
15
|
-
Requires-Dist: vatly-api-python==0.1.
|
|
15
|
+
Requires-Dist: vatly-api-python==0.1.0a5
|
|
16
16
|
Description-Content-Type: text/markdown
|
|
17
17
|
|
|
18
18
|
# Vatly Fluent for Python
|
|
@@ -34,8 +34,13 @@ pip install --pre vatly-fluent-python
|
|
|
34
34
|
|
|
35
35
|
`--pre` installs the latest alpha, including the matching `vatly-api-python` alpha.
|
|
36
36
|
|
|
37
|
-
For development, run `.agents/setup` or `uv sync --locked`.
|
|
38
|
-
|
|
37
|
+
For development, run `.agents/setup` or `uv sync --locked`. Package metadata pins the
|
|
38
|
+
exact SDK version from PyPI; development temporarily uses the SDK branch from
|
|
39
|
+
`[tool.uv.sources]` in `pyproject.toml` (see [Development](docs/Development.md)).
|
|
40
|
+
|
|
41
|
+
`Vatly(...)` appends `vatly/vatly-fluent-python/<version>` to the SDK client's
|
|
42
|
+
`User-Agent`, after the SDK's own tokens, once per client. SDK versions without
|
|
43
|
+
`add_version_string` keep their own `User-Agent`.
|
|
39
44
|
|
|
40
45
|
## First checkout
|
|
41
46
|
|
|
@@ -17,8 +17,13 @@ pip install --pre vatly-fluent-python
|
|
|
17
17
|
|
|
18
18
|
`--pre` installs the latest alpha, including the matching `vatly-api-python` alpha.
|
|
19
19
|
|
|
20
|
-
For development, run `.agents/setup` or `uv sync --locked`.
|
|
21
|
-
|
|
20
|
+
For development, run `.agents/setup` or `uv sync --locked`. Package metadata pins the
|
|
21
|
+
exact SDK version from PyPI; development temporarily uses the SDK branch from
|
|
22
|
+
`[tool.uv.sources]` in `pyproject.toml` (see [Development](docs/Development.md)).
|
|
23
|
+
|
|
24
|
+
`Vatly(...)` appends `vatly/vatly-fluent-python/<version>` to the SDK client's
|
|
25
|
+
`User-Agent`, after the SDK's own tokens, once per client. SDK versions without
|
|
26
|
+
`add_version_string` keep their own `User-Agent`.
|
|
22
27
|
|
|
23
28
|
## First checkout
|
|
24
29
|
|
|
@@ -57,6 +57,32 @@ async def example(vatly: Vatly):
|
|
|
57
57
|
Use the general builder for mixed carts. Reusing a subscription builder replaces
|
|
58
58
|
its plan item rather than appending another.
|
|
59
59
|
|
|
60
|
+
## Add a discount
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from vatly_fluent import Vatly
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
async def example(vatly: Vatly):
|
|
67
|
+
return (
|
|
68
|
+
await vatly.subscribe()
|
|
69
|
+
.to_plan("subscription_plan_example")
|
|
70
|
+
.with_trial_days(14)
|
|
71
|
+
.with_percentage_discount(20, "Launch offer")
|
|
72
|
+
.create()
|
|
73
|
+
)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
For a fixed amount, call `.with_amount_discount("10.00", "Welcome")` instead. It
|
|
77
|
+
takes a decimal string in EUR or an `EurMoney`. The discount reduces each
|
|
78
|
+
product's first payment, and renewals are charged the full price. For a
|
|
79
|
+
subscription on trial, that is its first payment after the trial. A fixed amount
|
|
80
|
+
is on the products' tax basis: excluding taxes on tax-exclusive prices, including
|
|
81
|
+
them on tax-inclusive ones. The description, up to 255 characters, is shown on the
|
|
82
|
+
checkout, the receipt and the invoice. Vatly takes one discount per checkout for
|
|
83
|
+
now; each call adds one, so a second raises `FluentError` before sending. See the
|
|
84
|
+
[Discounts guide](https://docs.vatly.com/guides/discounts).
|
|
85
|
+
|
|
60
86
|
| Builder method | Purpose |
|
|
61
87
|
| --- | --- |
|
|
62
88
|
| `with_items` | Append detached cart items |
|
|
@@ -64,6 +90,7 @@ its plan item rather than appending another.
|
|
|
64
90
|
| `with_trial_days`, `with_trial_ends_at` | Trial length or aware deadline, rounded up to whole days |
|
|
65
91
|
| `with_redirect_url_success`, `with_redirect_url_canceled` | Override default redirects |
|
|
66
92
|
| `with_locale`, `with_metadata`, `with_billing_address` | Add checkout details |
|
|
93
|
+
| `with_percentage_discount`, `with_amount_discount` | Take a discount off the first payments |
|
|
67
94
|
| `payload` | Inspect a detached wire-format dictionary without a request |
|
|
68
95
|
| `in_testmode`, `in_live_mode` | Assert the existing key's mode |
|
|
69
96
|
|
|
@@ -4,13 +4,13 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "vatly-fluent-python"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.0a5"
|
|
8
8
|
description = "Framework-independent fluent billing integrations built on the Vatly Python SDK"
|
|
9
9
|
keywords = ["vatly", "merchant-of-record", "billing", "payments", "subscriptions", "vat", "ai"]
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
readme = "README.md"
|
|
12
12
|
license = "MIT"
|
|
13
|
-
dependencies = ["vatly-api-python==0.1.
|
|
13
|
+
dependencies = ["vatly-api-python==0.1.0a5"]
|
|
14
14
|
classifiers = ["Development Status :: 3 - Alpha", "Typing :: Typed", "Programming Language :: Python :: 3"]
|
|
15
15
|
|
|
16
16
|
[project.urls]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Vatly Fluent: builders, handles, driver contracts and signed webhook reactions."""
|
|
2
2
|
|
|
3
|
+
from ._version import __version__
|
|
3
4
|
from .builders import CheckoutBuilder, CheckoutResult, SubscriptionBuilder
|
|
4
5
|
from .client import CheckoutResolution, TestHelpers, Vatly
|
|
5
6
|
from .contracts import (
|
|
@@ -27,8 +28,6 @@ from .customers import CustomerHandle, CustomerService
|
|
|
27
28
|
from .handles import OrderHandle, SubscriptionHandle
|
|
28
29
|
from .webhooks import WebhookProcessor
|
|
29
30
|
|
|
30
|
-
__version__ = "0.1.0a4"
|
|
31
|
-
|
|
32
31
|
__all__ = [
|
|
33
32
|
"Vatly",
|
|
34
33
|
"Wiring",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0a5"
|
|
@@ -4,12 +4,20 @@ import math
|
|
|
4
4
|
from collections.abc import Sequence
|
|
5
5
|
from copy import deepcopy
|
|
6
6
|
from datetime import datetime, timezone
|
|
7
|
+
from decimal import Decimal
|
|
7
8
|
from typing import Any
|
|
8
9
|
|
|
9
10
|
from pydantic import ValidationError
|
|
10
11
|
from typing_extensions import Self
|
|
11
12
|
from vatly import RequestOptions
|
|
12
|
-
from vatly.models import
|
|
13
|
+
from vatly.models import (
|
|
14
|
+
BillingAddress,
|
|
15
|
+
Checkout,
|
|
16
|
+
CheckoutProduct,
|
|
17
|
+
CreateCheckoutRequest,
|
|
18
|
+
EurMoney,
|
|
19
|
+
Metadata,
|
|
20
|
+
)
|
|
13
21
|
|
|
14
22
|
from .contracts import CheckoutRecord, CustomerProfile, EntityRef, FluentError, Wiring, required
|
|
15
23
|
|
|
@@ -64,6 +72,42 @@ class CheckoutBuilder:
|
|
|
64
72
|
)
|
|
65
73
|
return self
|
|
66
74
|
|
|
75
|
+
def with_percentage_discount(
|
|
76
|
+
self, percentage: int | float | str | Decimal, description: str | None = None
|
|
77
|
+
) -> Self:
|
|
78
|
+
"""Take a percentage off each product's first payment.
|
|
79
|
+
|
|
80
|
+
Renewals are charged the full price; for a subscription on trial the
|
|
81
|
+
discount comes off its first payment after the trial. The percentage must
|
|
82
|
+
be above 0 and below 100, with at most three decimals. Each call adds a
|
|
83
|
+
discount: Vatly takes one per checkout for now, so a second fails
|
|
84
|
+
validation before the request is sent.
|
|
85
|
+
"""
|
|
86
|
+
value = str(percentage) if isinstance(percentage, Decimal) else percentage
|
|
87
|
+
return self._add_discount({"percentage": value}, description)
|
|
88
|
+
|
|
89
|
+
def with_amount_discount(self, amount: EurMoney | str, description: str | None = None) -> Self:
|
|
90
|
+
"""Take a fixed EUR amount, such as ``"10.00"``, off the products' first payments.
|
|
91
|
+
|
|
92
|
+
The amount is on the products' tax basis: excluding taxes on tax-exclusive
|
|
93
|
+
prices, including them on tax-inclusive ones, also at the first payment
|
|
94
|
+
after a trial. It must be below the subtotal it discounts. Each call adds
|
|
95
|
+
a discount: Vatly takes one per checkout for now, so a second fails
|
|
96
|
+
validation before the request is sent.
|
|
97
|
+
"""
|
|
98
|
+
money = (
|
|
99
|
+
{"value": amount, "currency": "EUR"}
|
|
100
|
+
if isinstance(amount, str)
|
|
101
|
+
else amount.model_dump(mode="json", by_alias=True, exclude_unset=True)
|
|
102
|
+
)
|
|
103
|
+
return self._add_discount({"amount": money}, description)
|
|
104
|
+
|
|
105
|
+
def _add_discount(self, discount: dict[str, Any], description: str | None) -> Self:
|
|
106
|
+
if description is not None:
|
|
107
|
+
discount = {"description": description, **discount}
|
|
108
|
+
self._data.setdefault("discounts", []).append(discount)
|
|
109
|
+
return self
|
|
110
|
+
|
|
67
111
|
def with_items(self, items: Sequence[CheckoutProduct | dict[str, Any]]) -> Self:
|
|
68
112
|
self._data["products"].extend(
|
|
69
113
|
item.model_dump(mode="json", by_alias=True, exclude_unset=True)
|
|
@@ -8,6 +8,7 @@ from vatly import RequestOptions, VatlyNotFoundError
|
|
|
8
8
|
from vatly.models import Order, Subscription
|
|
9
9
|
from vatly.resources import AsyncOneOffProducts, AsyncSubscriptionPlans, AsyncTestHelpers
|
|
10
10
|
|
|
11
|
+
from ._version import __version__
|
|
11
12
|
from .builders import CheckoutBuilder, SubscriptionBuilder
|
|
12
13
|
from .contracts import CustomerProfile, FluentError, LocalSubscription, Wiring, required
|
|
13
14
|
from .customers import CustomerHandle, CustomerService
|
|
@@ -77,6 +78,10 @@ class Vatly:
|
|
|
77
78
|
def __init__(self, wiring: Wiring) -> None:
|
|
78
79
|
self.wiring = wiring
|
|
79
80
|
self.api = wiring.api
|
|
81
|
+
# Older SDKs have no add_version_string; they keep their own User-Agent.
|
|
82
|
+
add = getattr(self.api, "add_version_string", None)
|
|
83
|
+
if add is not None:
|
|
84
|
+
add(f"vatly/vatly-fluent-python/{__version__}")
|
|
80
85
|
self.customers = CustomerService(wiring)
|
|
81
86
|
|
|
82
87
|
def one_off_products(self) -> AsyncOneOffProducts:
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
import itertools
|
|
3
3
|
import json
|
|
4
|
+
import platform
|
|
4
5
|
from copy import deepcopy
|
|
5
6
|
from datetime import datetime, timedelta, timezone
|
|
7
|
+
from decimal import Decimal
|
|
6
8
|
from pathlib import Path
|
|
7
9
|
|
|
8
10
|
import httpx
|
|
9
11
|
import pytest
|
|
12
|
+
import vatly as vatly_sdk
|
|
10
13
|
from vatly import AsyncVatlyClient, RequestOptions, VatlyForbiddenError, VatlyInvalidSignatureError
|
|
11
|
-
from vatly.models import Subscription
|
|
14
|
+
from vatly.models import EurMoney, Subscription
|
|
12
15
|
from vatly.webhooks import compute_signature_v1
|
|
13
16
|
|
|
17
|
+
import vatly_fluent
|
|
14
18
|
from examples.sqlite_driver import SQLiteDriver
|
|
15
19
|
from vatly_fluent import (
|
|
16
20
|
CheckoutRecord,
|
|
@@ -121,6 +125,39 @@ async def test_builders_reuse_detached_payload_and_record_entity(harness):
|
|
|
121
125
|
assert (await db.checkouts.find(a.id)).entity == TEAM
|
|
122
126
|
|
|
123
127
|
|
|
128
|
+
async def test_discount_helpers_send_one_checkout_discount(harness):
|
|
129
|
+
vatly, db, calls, responses = harness
|
|
130
|
+
responses.extend([resource("Checkout", id="checkout_a"), resource("Checkout", id="checkout_b")])
|
|
131
|
+
await (
|
|
132
|
+
vatly.subscribe()
|
|
133
|
+
.to_plan("subscription_plan_a")
|
|
134
|
+
.with_trial_days(14)
|
|
135
|
+
.with_amount_discount("10.00", "Launch")
|
|
136
|
+
.create()
|
|
137
|
+
)
|
|
138
|
+
await (
|
|
139
|
+
vatly.checkout_builder()
|
|
140
|
+
.with_items([{"id": "one_off_product_a"}])
|
|
141
|
+
.with_percentage_discount(Decimal("12.5"))
|
|
142
|
+
.create()
|
|
143
|
+
)
|
|
144
|
+
first, second = (json.loads(call.content) for call in calls)
|
|
145
|
+
assert first["discounts"] == [
|
|
146
|
+
{"description": "Launch", "amount": {"value": "10.00", "currency": "EUR"}}
|
|
147
|
+
]
|
|
148
|
+
assert first["products"] == [{"id": "subscription_plan_a", "quantity": 1, "trialDays": 14}]
|
|
149
|
+
assert second["discounts"] == [{"percentage": "12.5"}]
|
|
150
|
+
assert "discounts" not in vatly.checkout_builder().payload()
|
|
151
|
+
|
|
152
|
+
# Each call appends; Vatly takes one discount for now, so two fail before sending.
|
|
153
|
+
two = vatly.checkout_builder().with_items([{"id": "one_off_product_a"}])
|
|
154
|
+
two.with_percentage_discount(10).with_amount_discount(EurMoney(value="5.00", currency="EUR"))
|
|
155
|
+
assert len(two.payload()["discounts"]) == 2
|
|
156
|
+
with pytest.raises(FluentError, match="Invalid checkout request"):
|
|
157
|
+
await two.create()
|
|
158
|
+
assert len(calls) == 2
|
|
159
|
+
|
|
160
|
+
|
|
124
161
|
async def test_validation_fails_before_remote_call(harness):
|
|
125
162
|
vatly, db, calls, responses = harness
|
|
126
163
|
for value in [0, -1, True, 1.5]:
|
|
@@ -173,6 +210,17 @@ async def test_customer_cache_bindings_portal_and_conflicts(harness):
|
|
|
173
210
|
assert portal.url == "https://portal.test/one-use"
|
|
174
211
|
|
|
175
212
|
|
|
213
|
+
async def test_user_agent_names_fluent_once(harness):
|
|
214
|
+
vatly, db, calls, responses = harness
|
|
215
|
+
Vatly(vatly.wiring) # A second facade on the same client adds no second token.
|
|
216
|
+
responses.append(resource("Customer", id="customer_a"))
|
|
217
|
+
await vatly.customer("customer_a").model()
|
|
218
|
+
tokens = calls[0].headers["User-Agent"].split(" ")
|
|
219
|
+
assert tokens[0] == f"vatly/vatly-api-python/{vatly_sdk.__version__}"
|
|
220
|
+
assert tokens[1:3] == [f"Python/{platform.python_version()}", f"httpx/{httpx.__version__}"]
|
|
221
|
+
assert tokens[3:] == [f"vatly/vatly-fluent-python/{vatly_fluent.__version__}"]
|
|
222
|
+
|
|
223
|
+
|
|
176
224
|
async def test_errors_are_preserved(harness):
|
|
177
225
|
vatly, db, calls, responses = harness
|
|
178
226
|
responses.append(httpx.Response(403, json={"message": "not allowed"}))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|