vatly-fluent-python 0.1.0a3__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.0a3 → vatly_fluent_python-0.1.0a5}/CHANGELOG.md +29 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/PKG-INFO +13 -6
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/README.md +11 -4
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/Checkouts.md +32 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/Customers.md +2 -1
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/Orders.md +1 -1
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/README.md +5 -4
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/pyproject.toml +2 -2
- {vatly_fluent_python-0.1.0a3 → 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.0a3 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/builders.py +45 -1
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/client.py +5 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/tests/test_fluent.py +68 -2
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/.gitignore +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/LICENSE +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/PORTING.md +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/Configuration.md +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/CoreConcepts.md +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/CustomerPortal.md +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/Development.md +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/Porting.md +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/Subscriptions.md +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/Testing.md +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/docs/Webhooks.md +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/examples/sqlite_driver.py +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/scripts/check_package.py +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/contracts.py +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/customers.py +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/handles.py +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/linkage.py +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/py.typed +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/src/vatly_fluent/webhooks.py +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/tests/fixtures/resources.json +0 -0
- {vatly_fluent_python-0.1.0a3 → vatly_fluent_python-0.1.0a5}/tests/test_docs.py +0 -0
|
@@ -1,5 +1,34 @@
|
|
|
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
|
+
|
|
18
|
+
## 0.1.0a4 — 2026-11-25
|
|
19
|
+
|
|
20
|
+
- Require `vatly-api-python==0.1.0a4`.
|
|
21
|
+
- Stored refunds and refund webhook snapshots carry `Refund.metadata` (None when
|
|
22
|
+
the refund was created without metadata).
|
|
23
|
+
- Checkout builders reject invalid metadata (non-string values, more than 50 keys,
|
|
24
|
+
keys over 40 or values over 500 characters) and `trialDays` below 1 with
|
|
25
|
+
`FluentError("Invalid checkout request")` before calling Vatly, instead of the
|
|
26
|
+
API's `VatlyValidationError`.
|
|
27
|
+
- Behaviour change from the SDK: dictionary bodies passed to customer and
|
|
28
|
+
subscription calls are validated before sending, so invalid input raises Pydantic's
|
|
29
|
+
`ValidationError` instead of `VatlyValidationError`. Fields the API schema does not
|
|
30
|
+
define are dropped, and `None` is sent only on nullable fields.
|
|
31
|
+
|
|
3
32
|
## 0.1.0a3 — 2026-11-13
|
|
4
33
|
|
|
5
34
|
- Link initial orders to their subscriptions through
|
|
@@ -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,12 +12,12 @@ 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
|
|
19
19
|
|
|
20
|
-
> **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.**
|
|
21
21
|
|
|
22
22
|
Integrate billing with Vatly, the European Merchant of Record for AI, software and
|
|
23
23
|
digital products, without tying your application to a framework or database.
|
|
@@ -29,11 +29,18 @@ transactions and jobs. Python 3.10+, fully typed, **async-first**.
|
|
|
29
29
|
## Install
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
pip install vatly-fluent-python
|
|
32
|
+
pip install --pre vatly-fluent-python
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
`--pre` installs the latest alpha, including the matching `vatly-api-python` alpha.
|
|
36
|
+
|
|
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`.
|
|
37
44
|
|
|
38
45
|
## First checkout
|
|
39
46
|
|
|
@@ -1,6 +1,6 @@
|
|
|
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
5
|
Integrate billing with Vatly, the European Merchant of Record for AI, software and
|
|
6
6
|
digital products, without tying your application to a framework or database.
|
|
@@ -12,11 +12,18 @@ transactions and jobs. Python 3.10+, fully typed, **async-first**.
|
|
|
12
12
|
## Install
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
|
-
pip install vatly-fluent-python
|
|
15
|
+
pip install --pre vatly-fluent-python
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
`--pre` installs the latest alpha, including the matching `vatly-api-python` alpha.
|
|
19
|
+
|
|
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`.
|
|
20
27
|
|
|
21
28
|
## First checkout
|
|
22
29
|
|
|
@@ -30,6 +30,11 @@ async def example(vatly: Vatly):
|
|
|
30
30
|
The customer and entity must already be authorized. Omit the profile for a guest
|
|
31
31
|
checkout. `.for_entity()` needs the checkout-record driver.
|
|
32
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
|
+
|
|
33
38
|
## Start a subscription with a trial
|
|
34
39
|
|
|
35
40
|
```python
|
|
@@ -52,6 +57,32 @@ async def example(vatly: Vatly):
|
|
|
52
57
|
Use the general builder for mixed carts. Reusing a subscription builder replaces
|
|
53
58
|
its plan item rather than appending another.
|
|
54
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
|
+
|
|
55
86
|
| Builder method | Purpose |
|
|
56
87
|
| --- | --- |
|
|
57
88
|
| `with_items` | Append detached cart items |
|
|
@@ -59,6 +90,7 @@ its plan item rather than appending another.
|
|
|
59
90
|
| `with_trial_days`, `with_trial_ends_at` | Trial length or aware deadline, rounded up to whole days |
|
|
60
91
|
| `with_redirect_url_success`, `with_redirect_url_canceled` | Override default redirects |
|
|
61
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 |
|
|
62
94
|
| `payload` | Inspect a detached wire-format dictionary without a request |
|
|
63
95
|
| `in_testmode`, `in_live_mode` | Assert the existing key's mode |
|
|
64
96
|
|
|
@@ -48,7 +48,8 @@ async def example(vatly: Vatly):
|
|
|
48
48
|
|
|
49
49
|
`model()`, `name()`, `email()` and `identity()` share a cached snapshot. `sync()`
|
|
50
50
|
and `update()` refresh it. Name/email are not invoice address fields; use the
|
|
51
|
-
[portal](CustomerPortal.md) for hosted billing management.
|
|
51
|
+
[portal](CustomerPortal.md) for hosted billing management. The SDK checks customer
|
|
52
|
+
bodies before sending; an invalid one raises Pydantic's `ValidationError`.
|
|
52
53
|
|
|
53
54
|
| Lookup | Return |
|
|
54
55
|
| --- | --- |
|
|
@@ -26,7 +26,7 @@ async def example(vatly: Vatly):
|
|
|
26
26
|
| `lines` | OrderLine models |
|
|
27
27
|
| `reversed_subtotal`, `refundable_subtotal` | `Decimal` in currency units |
|
|
28
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 |
|
|
29
|
+
| `refunds`, `chargebacks` | Local stored records, or an empty list without repositories; a refund keeps the `metadata` it was created with, or None |
|
|
30
30
|
|
|
31
31
|
`model()` and the derived fields share one lazy read; `sync()` refreshes it. Do not
|
|
32
32
|
convert financial values to floats. Preserve each amount's currency from the SDK
|
|
@@ -4,15 +4,16 @@ Build checkout, customer and subscription flows without tying billing to a web
|
|
|
4
4
|
framework. Fluent composes the async SDK and your storage driver. Vatly is the
|
|
5
5
|
European Merchant of Record for AI, software and digital products.
|
|
6
6
|
|
|
7
|
-
**Alpha — under active development. Every alpha release may include breaking changes.
|
|
7
|
+
**Alpha — under active development. Every alpha release may include breaking changes. Lock the version you install and review the release notes before upgrading.**
|
|
8
8
|
|
|
9
9
|
## Install and create a checkout
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
python -m pip install vatly-fluent-python
|
|
12
|
+
python -m pip install --pre vatly-fluent-python
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Python 3.10+ is required.
|
|
15
|
+
Python 3.10+ is required. `--pre` installs the latest alpha, including the
|
|
16
|
+
matching `vatly-api-python` alpha. Set
|
|
16
17
|
`VATLY_API_KEY` on the server, then run this async function with your event loop.
|
|
17
18
|
|
|
18
19
|
```python
|
|
@@ -66,5 +67,5 @@ lifespan. IDs and billable entities must be authorized by your application.
|
|
|
66
67
|
| [Development](Development.md) | Set up, test and build the package |
|
|
67
68
|
|
|
68
69
|
[API reference](https://docs.vatly.com/api-reference) documents the underlying
|
|
69
|
-
requests. These examples are executed with published
|
|
70
|
+
requests. These examples are executed with the published packages and local
|
|
70
71
|
fixtures; no real payments or account changes occur in documentation tests.
|
|
@@ -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.0a3"
|
|
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]:
|
|
@@ -132,6 +169,18 @@ async def test_validation_fails_before_remote_call(harness):
|
|
|
132
169
|
vatly.subscribe().in_live_mode()
|
|
133
170
|
with pytest.raises(FluentError):
|
|
134
171
|
await vatly.subscribe().create()
|
|
172
|
+
plan = {"id": "subscription_plan_a"}
|
|
173
|
+
for metadata in [
|
|
174
|
+
{"n": 1},
|
|
175
|
+
{f"k{i}": "v" for i in range(51)},
|
|
176
|
+
{"k" * 41: "v"},
|
|
177
|
+
{"k": "v" * 501},
|
|
178
|
+
]:
|
|
179
|
+
with pytest.raises(FluentError, match="Invalid checkout request"):
|
|
180
|
+
await vatly.checkout_builder().with_items([plan]).with_metadata(metadata).create()
|
|
181
|
+
for item in [{**plan, "trialDays": 0}, {**plan, "metadata": {"n": 1}}]:
|
|
182
|
+
with pytest.raises(FluentError, match="Invalid checkout request"):
|
|
183
|
+
await vatly.checkout_builder().with_items([item]).create()
|
|
135
184
|
vatly.wiring.checkouts = None
|
|
136
185
|
with pytest.raises(FluentError):
|
|
137
186
|
await vatly.subscribe().to_plan("subscription_plan_a").for_entity(TEAM).create()
|
|
@@ -161,6 +210,17 @@ async def test_customer_cache_bindings_portal_and_conflicts(harness):
|
|
|
161
210
|
assert portal.url == "https://portal.test/one-use"
|
|
162
211
|
|
|
163
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
|
+
|
|
164
224
|
async def test_errors_are_preserved(harness):
|
|
165
225
|
vatly, db, calls, responses = harness
|
|
166
226
|
responses.append(httpx.Response(403, json={"message": "not allowed"}))
|
|
@@ -284,12 +344,18 @@ async def test_financial_reversal_snapshots_persist_and_dispatch(harness, name,
|
|
|
284
344
|
vatly, db, calls, responses = harness
|
|
285
345
|
await db.checkouts.record(CheckoutRecord("checkout_a", TEAM, True))
|
|
286
346
|
await db.checkouts.link("checkout_a", "order", "order_a")
|
|
287
|
-
|
|
347
|
+
extra = {"metadata": {"ticket": "T-1"}} if fixture == "Refund" else {}
|
|
348
|
+
obj = resource(fixture, originalOrderId="order_a", **extra)
|
|
288
349
|
assert await deliver(vatly, name, obj)
|
|
289
350
|
repo = db.refunds if fixture == "Refund" else db.chargebacks
|
|
290
351
|
saved = await repo.find_by_vatly_id(obj["id"])
|
|
291
352
|
assert saved.entity == TEAM
|
|
292
353
|
assert saved.resource.tax_summary
|
|
354
|
+
if fixture == "Refund":
|
|
355
|
+
assert saved.resource.metadata.root == {"ticket": "T-1"}
|
|
356
|
+
await deliver(vatly, name, {**obj, "metadata": {"ticket": "T-2"}}, id="event_again")
|
|
357
|
+
[updated] = await repo.list_for_order("order_a")
|
|
358
|
+
assert updated.resource.metadata.root == {"ticket": "T-2"}
|
|
293
359
|
assert len(await repo.list_for_order("order_a")) == 1
|
|
294
360
|
assert not calls
|
|
295
361
|
|
|
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
|