vatly-django 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_django-0.1.0a2/.gitignore +9 -0
- vatly_django-0.1.0a2/CHANGELOG.md +18 -0
- vatly_django-0.1.0a2/LICENSE +21 -0
- vatly_django-0.1.0a2/PKG-INFO +73 -0
- vatly_django-0.1.0a2/README.md +55 -0
- vatly_django-0.1.0a2/docs/Billing.md +55 -0
- vatly_django-0.1.0a2/docs/Configuration.md +35 -0
- vatly_django-0.1.0a2/docs/Development.md +23 -0
- vatly_django-0.1.0a2/docs/README.md +10 -0
- vatly_django-0.1.0a2/docs/Webhooks.md +43 -0
- vatly_django-0.1.0a2/pyproject.toml +51 -0
- vatly_django-0.1.0a2/scripts/check_package.py +32 -0
- vatly_django-0.1.0a2/src/vatly_django/__init__.py +3 -0
- vatly_django-0.1.0a2/src/vatly_django/admin.py +58 -0
- vatly_django-0.1.0a2/src/vatly_django/apps.py +7 -0
- vatly_django-0.1.0a2/src/vatly_django/billing.py +221 -0
- vatly_django-0.1.0a2/src/vatly_django/migrations/0001_initial.py +226 -0
- vatly_django-0.1.0a2/src/vatly_django/migrations/__init__.py +0 -0
- vatly_django-0.1.0a2/src/vatly_django/mixins.py +51 -0
- vatly_django-0.1.0a2/src/vatly_django/models.py +102 -0
- vatly_django-0.1.0a2/src/vatly_django/py.typed +1 -0
- vatly_django-0.1.0a2/src/vatly_django/storage.py +258 -0
- vatly_django-0.1.0a2/src/vatly_django/urls.py +10 -0
- vatly_django-0.1.0a2/src/vatly_django/views.py +67 -0
- vatly_django-0.1.0a2/tests/__init__.py +1 -0
- vatly_django-0.1.0a2/tests/fixtures/resources.json +318 -0
- vatly_django-0.1.0a2/tests/settings.py +51 -0
- vatly_django-0.1.0a2/tests/test_billing.py +371 -0
- vatly_django-0.1.0a2/vendor/README.md +10 -0
- vatly_django-0.1.0a2/vendor/SHA256SUMS +2 -0
- vatly_django-0.1.0a2/vendor/vatly_api_python-0.1.0a2-py3-none-any.whl +0 -0
- vatly_django-0.1.0a2/vendor/vatly_fluent_python-0.1.0a2-py3-none-any.whl +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0a2 — Unreleased
|
|
4
|
+
|
|
5
|
+
- Depend on `vatly-api-python` and `vatly-fluent-python`; imports are unchanged.
|
|
6
|
+
- Preserve access through cancellation grace periods using Fluent's shared expiry
|
|
7
|
+
mapping in signed webhooks and explicit reconciliation.
|
|
8
|
+
- Refresh pinned SDK/Fluent 0.1.0a2 bootstrap wheels and regression coverage.
|
|
9
|
+
|
|
10
|
+
## 0.1.0a1 — Unreleased
|
|
11
|
+
|
|
12
|
+
Alpha — under active development. Every alpha release may include breaking changes. Pin exact versions during alpha.
|
|
13
|
+
|
|
14
|
+
- Initial Cashier-style abstract billable model, ORM storage, migrations, checkout
|
|
15
|
+
and portal POST views, signed transactional webhook processing, audit and outbox.
|
|
16
|
+
- Host-owned checkout/entity links with PR #2910-compatible explicit reconciliation.
|
|
17
|
+
- Read-only admin, Django 5.2/6.0/6.1 tests and PostgreSQL concurrency CI.
|
|
18
|
+
- Versioned dependency bootstrap, fast orb setup and prepared trusted publishing.
|
|
@@ -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,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vatly-django
|
|
3
|
+
Version: 0.1.0a2
|
|
4
|
+
Summary: Cashier-style Django billing on Vatly Fluent
|
|
5
|
+
Project-URL: Homepage, https://github.com/vatly/vatly-django
|
|
6
|
+
Project-URL: Documentation, https://docs.vatly.com
|
|
7
|
+
Project-URL: Issues, https://github.com/vatly/vatly-django/issues
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Framework :: Django
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: >=3.10
|
|
14
|
+
Requires-Dist: django<6.2,>=5.2
|
|
15
|
+
Requires-Dist: vatly-api-python==0.1.0a2
|
|
16
|
+
Requires-Dist: vatly-fluent-python==0.1.0a2
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# Vatly Django
|
|
20
|
+
|
|
21
|
+
**Alpha — under active development. Every alpha release may include breaking changes. Pin exact versions during alpha.**
|
|
22
|
+
|
|
23
|
+
Cashier-style billing for Django on [Vatly Fluent Python](https://github.com/vatly/vatly-fluent-python).
|
|
24
|
+
Python 3.10+; Django 5.2 LTS, 6.0 and 6.1 (6.x requires Python 3.12+).
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
INSTALLED_APPS = [*INSTALLED_APPS, "vatly_django"]
|
|
28
|
+
VATLY_SCOPE = "my-tenant/my-storefront"
|
|
29
|
+
VATLY_API_KEY = os.environ["VATLY_API_KEY"]
|
|
30
|
+
VATLY_WEBHOOK_SECRET = os.environ["VATLY_WEBHOOK_SECRET"]
|
|
31
|
+
VATLY_REDIRECT_URL_SUCCESS = "https://app.example.com/billing/success"
|
|
32
|
+
VATLY_REDIRECT_URL_CANCELED = "https://app.example.com/billing/canceled"
|
|
33
|
+
VATLY_CHECKOUTS = {"pro": {"products": [{"id": "subscription_plan_...", "quantity": 1}]}}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Install `vatly-django==0.1.0a2` after publication, add
|
|
37
|
+
`path("billing/", include("vatly_django.urls"))`, run `python manage.py migrate`.
|
|
38
|
+
Before publication, clone and run `.agents/setup`; locked uv sources use versioned
|
|
39
|
+
SDK/Fluent wheels from `vendor/` without cross-private-repo credentials.
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from uuid import uuid4
|
|
43
|
+
from vatly_django.billing import Billing
|
|
44
|
+
|
|
45
|
+
billing = Billing()
|
|
46
|
+
# user/team must already be authorized by your app. Save this key for retries.
|
|
47
|
+
url = billing.checkout(user, "pro", idempotency_key=uuid4())
|
|
48
|
+
# Bind an authorized existing Vatly customer to enable portal checkout identity.
|
|
49
|
+
billing.bind_customer(user, existing_customer_id)
|
|
50
|
+
portal_url = billing.portal(user)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Or inherit `BillableMixin` on your user/team model to get `checkout`,
|
|
54
|
+
`billing_portal`, `subscriptions`, `subscribed`, cancel/resume/swap helpers.
|
|
55
|
+
The mixin is abstract and adds no columns or auth-user coupling.
|
|
56
|
+
|
|
57
|
+
- Host-owned checkout records assign orders/subscriptions; **never customerId**.
|
|
58
|
+
- Signed webhooks atomically deduplicate, persist snapshots/links and enqueue outbox events.
|
|
59
|
+
- Read-only admin; CSRF-protected, login-required checkout/portal POST views.
|
|
60
|
+
- Raw SDK and async Fluent remain available for advanced integration.
|
|
61
|
+
- Pending core PR #2910: historical initial `subscription_plan` lines cannot identify
|
|
62
|
+
a subscription. `Billing.reconcile` reports this instead of guessing/granting access.
|
|
63
|
+
|
|
64
|
+
[Guides for vatly-docs sync](docs/README.md) cover configuration, ownership, transactions,
|
|
65
|
+
outbox delivery, testing and release. No tags/publication are performed by setup or CI.
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
.agents/setup
|
|
69
|
+
uv run pytest
|
|
70
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy
|
|
71
|
+
uv run python -m django makemigrations --check --dry-run --settings=tests.settings
|
|
72
|
+
uv build && uv run twine check dist/*
|
|
73
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Vatly Django
|
|
2
|
+
|
|
3
|
+
**Alpha — under active development. Every alpha release may include breaking changes. Pin exact versions during alpha.**
|
|
4
|
+
|
|
5
|
+
Cashier-style billing for Django on [Vatly Fluent Python](https://github.com/vatly/vatly-fluent-python).
|
|
6
|
+
Python 3.10+; Django 5.2 LTS, 6.0 and 6.1 (6.x requires Python 3.12+).
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
INSTALLED_APPS = [*INSTALLED_APPS, "vatly_django"]
|
|
10
|
+
VATLY_SCOPE = "my-tenant/my-storefront"
|
|
11
|
+
VATLY_API_KEY = os.environ["VATLY_API_KEY"]
|
|
12
|
+
VATLY_WEBHOOK_SECRET = os.environ["VATLY_WEBHOOK_SECRET"]
|
|
13
|
+
VATLY_REDIRECT_URL_SUCCESS = "https://app.example.com/billing/success"
|
|
14
|
+
VATLY_REDIRECT_URL_CANCELED = "https://app.example.com/billing/canceled"
|
|
15
|
+
VATLY_CHECKOUTS = {"pro": {"products": [{"id": "subscription_plan_...", "quantity": 1}]}}
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Install `vatly-django==0.1.0a2` after publication, add
|
|
19
|
+
`path("billing/", include("vatly_django.urls"))`, run `python manage.py migrate`.
|
|
20
|
+
Before publication, clone and run `.agents/setup`; locked uv sources use versioned
|
|
21
|
+
SDK/Fluent wheels from `vendor/` without cross-private-repo credentials.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
from uuid import uuid4
|
|
25
|
+
from vatly_django.billing import Billing
|
|
26
|
+
|
|
27
|
+
billing = Billing()
|
|
28
|
+
# user/team must already be authorized by your app. Save this key for retries.
|
|
29
|
+
url = billing.checkout(user, "pro", idempotency_key=uuid4())
|
|
30
|
+
# Bind an authorized existing Vatly customer to enable portal checkout identity.
|
|
31
|
+
billing.bind_customer(user, existing_customer_id)
|
|
32
|
+
portal_url = billing.portal(user)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Or inherit `BillableMixin` on your user/team model to get `checkout`,
|
|
36
|
+
`billing_portal`, `subscriptions`, `subscribed`, cancel/resume/swap helpers.
|
|
37
|
+
The mixin is abstract and adds no columns or auth-user coupling.
|
|
38
|
+
|
|
39
|
+
- Host-owned checkout records assign orders/subscriptions; **never customerId**.
|
|
40
|
+
- Signed webhooks atomically deduplicate, persist snapshots/links and enqueue outbox events.
|
|
41
|
+
- Read-only admin; CSRF-protected, login-required checkout/portal POST views.
|
|
42
|
+
- Raw SDK and async Fluent remain available for advanced integration.
|
|
43
|
+
- Pending core PR #2910: historical initial `subscription_plan` lines cannot identify
|
|
44
|
+
a subscription. `Billing.reconcile` reports this instead of guessing/granting access.
|
|
45
|
+
|
|
46
|
+
[Guides for vatly-docs sync](docs/README.md) cover configuration, ownership, transactions,
|
|
47
|
+
outbox delivery, testing and release. No tags/publication are performed by setup or CI.
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
.agents/setup
|
|
51
|
+
uv run pytest
|
|
52
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy
|
|
53
|
+
uv run python -m django makemigrations --check --dry-run --settings=tests.settings
|
|
54
|
+
uv build && uv run twine check dist/*
|
|
55
|
+
```
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# Billable operations
|
|
2
|
+
|
|
3
|
+
Render one server-generated UUID per purchase as a hidden `idempotency_key`. POST
|
|
4
|
+
to `billing/checkout/<offer>/` as an authenticated user with CSRF. Products, quantities,
|
|
5
|
+
customerId, metadata and redirect URLs come from server settings, not user input.
|
|
6
|
+
An invalid key/offer yields 400, a remote SDK error 502. Save/reuse the purchase key
|
|
7
|
+
when retrying ambiguous failures. A durable CheckoutAttempt commits before network
|
|
8
|
+
I/O and rejects key reuse for a different entity or changed payload. Never generate
|
|
9
|
+
a new key merely because payment creation timed out. Concurrent API retries use
|
|
10
|
+
the same key and local links are immutable/idempotent. Vatly's idempotency retention
|
|
11
|
+
still applies; investigate stale attempts instead of retrying them indefinitely.
|
|
12
|
+
|
|
13
|
+
The returned checkout URL redirects to Vatly. Success redirects do not prove payment.
|
|
14
|
+
Persisted Checkout records link order/subscription resources through signed events.
|
|
15
|
+
They never infer ownership from shared customer IDs or arbitrary metadata.
|
|
16
|
+
|
|
17
|
+
POST to `billing/portal/` to create a short-lived, single-use portal session for the
|
|
18
|
+
billable's bound customer. Do not cache/log the session URL. The portal request
|
|
19
|
+
uses the OpenAPI `returnUrl` field, not a query string or redirectUrl.
|
|
20
|
+
|
|
21
|
+
Mixin methods: `checkout`, `billing_portal`, `subscriptions`, `subscribed`,
|
|
22
|
+
`cancel_subscription`, `resume_subscription`, `swap_subscription`. Subscription
|
|
23
|
+
queries include only owned resources in the chosen scope/mode. `subscribed()`
|
|
24
|
+
requires active/trial/on_grace_period status and an unexpired local end time; it is
|
|
25
|
+
a convenience policy, not a replacement for your product's entitlement rules.
|
|
26
|
+
Grace expiry comes from Fluent's shared lifecycle mapping, not `canceledAt`
|
|
27
|
+
(the cancellation request time). Missing expiry raises `FluentError` and preserves
|
|
28
|
+
the prior committed state for explicit recovery; do not treat failed/stale syncs
|
|
29
|
+
as evidence of continuing entitlement. See Fluent's subscription guide for period
|
|
30
|
+
field precedence and the missing-deadline policy.
|
|
31
|
+
`Billing.subscription_action` also exposes sync, swap_and_invoice and
|
|
32
|
+
swap_without_charge. It checks local ownership before any API mutation. Cancellation
|
|
33
|
+
waits for signed events to update local state; resume refreshes immediately. Use
|
|
34
|
+
RequestOptions for stable mutation keys on the underlying Fluent/SDK when a workflow
|
|
35
|
+
must retry the same cancellation/swap. Never run these mutating methods on a GET.
|
|
36
|
+
|
|
37
|
+
`Billing.reconcile(billable, checkout_id)` checks own checkout ownership then fetches
|
|
38
|
+
checkout → order → subscriptions and persists snapshots/links transactionally.
|
|
39
|
+
It can hold the scope lock during bounded GET retries; run it in a background job
|
|
40
|
+
for busy deployments. It emits no local-created outbox event; consumers should
|
|
41
|
+
derive access from the reconciled records or implement their own durable policy.
|
|
42
|
+
|
|
43
|
+
## Pending core PR #2910
|
|
44
|
+
|
|
45
|
+
Before this core change, initial lines can be `subscription_plan` + plan ID.
|
|
46
|
+
There is no deterministic initial subscription ID to attach to a billable. The
|
|
47
|
+
result reports `legacy_plan_ids`; it never guesses by customerId/plan/quantity.
|
|
48
|
+
After the change, lines use `subscription` + intended subscription ID. Quantity
|
|
49
|
+
does not multiply IDs, and identical plans can yield distinct subscriptions.
|
|
50
|
+
An intended ID can temporarily404 or never exist for a skipped trial start;
|
|
51
|
+
`pending_subscription_ids` records unresolved IDs without granting access. Trial
|
|
52
|
+
AUTH_REQUEST flows can lack order.paid; reconcile the paid checkout's orderId.
|
|
53
|
+
Historical lines are not backfilled. Do not claim a complete live initial
|
|
54
|
+
subscription-to-entity flow until core provides the reference or an explicit host
|
|
55
|
+
record establishes it. Renewal/update subscription lines remain usable.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
Add `vatly_django` to INSTALLED_APPS and run migrations. Include its URLs under
|
|
4
|
+
your billing prefix. Use Django auth/session/CSRF middleware for browser endpoints.
|
|
5
|
+
Use HTTPS in production; configure your reverse proxy, allowed hosts and CSRF origins
|
|
6
|
+
as usual. Never disable CSRF for checkout/portal. Only webhook is exempt.
|
|
7
|
+
|
|
8
|
+
| Setting | Contract |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| VATLY_API_KEY | Required; falls back to environment. test_/live_ chooses mode |
|
|
11
|
+
| VATLY_SCOPE | Required stable tenant/storefront string (max 200 chars) |
|
|
12
|
+
| VATLY_WEBHOOK_SECRET | Required for webhooks; string or rotation list, never client-side |
|
|
13
|
+
| VATLY_REDIRECT_URL_SUCCESS / CANCELED | Required checkout HTTPS destinations |
|
|
14
|
+
| VATLY_PORTAL_REDIRECT_URL | Optional HTTPS returnUrl for hosted portal |
|
|
15
|
+
| VATLY_CHECKOUTS | Server allowlist: offer slug → products, optional locale/metadata/billingAddress |
|
|
16
|
+
| VATLY_BILLABLE_RESOLVER | Optional dotted callable(request) → authorized saved Django model; defaults to request.user |
|
|
17
|
+
| VATLY_SCOPE_RESOLVER | Optional dotted callable(request) → tenant/storefront string, also used on webhook routes |
|
|
18
|
+
|
|
19
|
+
For multi-tenant hosts, both resolvers must validate membership and select the
|
|
20
|
+
matching key and webhook secret through the deployment's settings strategy. Do not
|
|
21
|
+
trust query-string tenant IDs or webhook customerId to route ownership. The current
|
|
22
|
+
facade uses one API key/secret configuration per deployment; construct ORMDriver +
|
|
23
|
+
Fluent directly if you need a credential registry per tenant.
|
|
24
|
+
|
|
25
|
+
The abstract `vatly_django.mixins.BillableMixin` adds no columns; use it with a
|
|
26
|
+
custom user, team or organization model. Existing models need not inherit it:
|
|
27
|
+
`Billing(scope).checkout(model, offer, idempotency_key=uuid)` provides the same
|
|
28
|
+
behavior. Entity identities are model label + primary key (immutable across schema
|
|
29
|
+
renames unless you migrate billing references). The mixin's `billing()` can be
|
|
30
|
+
overridden to choose a trusted scope. Built-in views use explicit resolvers instead.
|
|
31
|
+
|
|
32
|
+
There is no automatic remote customer creation or email lookup. Call
|
|
33
|
+
`Billing.bind_customer(billable, authorized_customer_id)` from trusted provisioning
|
|
34
|
+
code to reuse a known customer. Binding uniqueness is enforced in both directions,
|
|
35
|
+
and does not assign entitlement ownership.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Development, support and release
|
|
2
|
+
|
|
3
|
+
Python 3.10–3.14; Django5.2 LTS,6.0,6.1 within their Python compatibility ranges.
|
|
4
|
+
CI runs representative supported combinations plus PostgreSQL17 concurrent delivery.
|
|
5
|
+
Tests use real ORM migrations + SDK MockTransport + signed local fixtures, no Vatly
|
|
6
|
+
account writes. They cover all event permutations, rollback including outbox/audit,
|
|
7
|
+
duplicate delivery, purchase-key recovery, authorization, CSRF, billing identity,
|
|
8
|
+
status/grace rules and legacy/new subscription references. The isolated built wheel
|
|
9
|
+
test migrates a fresh DB, imports the package, and checks py.typed.
|
|
10
|
+
|
|
11
|
+
`.agents/setup` provisions pinned uv0.12.9 and Python3.12, syncs the lockfile and
|
|
12
|
+
runs Django system checks. It is executable/idempotent and needs no secrets/services.
|
|
13
|
+
It does not migrate a host application's DB or seed data. `vendor/` pins unmodified
|
|
14
|
+
unpublished dependency wheels; compare SHA256SUMS when refreshing them.
|
|
15
|
+
|
|
16
|
+
PyPI name `vatly-django` returned404 on 2026-11-09 (not a reservation). Import name
|
|
17
|
+
is `vatly_django`, version0.1.0a2. Before any release configure PyPI trusted publisher
|
|
18
|
+
owner `vatly`, repo `vatly-django`, workflow `release.yml`; leave the environment
|
|
19
|
+
field blank. No GitHub environment or PyPI token is needed. Restrict repository
|
|
20
|
+
release access: there is no environment approval gate. Publish SDK then Fluent
|
|
21
|
+
then Django. The release workflow builds/checks artifacts and only publishes on a
|
|
22
|
+
published GitHub release whose tag matches `v` plus the package version. No tag or
|
|
23
|
+
publication has been made. PyPI packages are public even if GitHub source is private.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Vatly Django guides
|
|
2
|
+
|
|
3
|
+
**Alpha — under active development. Every alpha release may include breaking changes. Pin exact versions during alpha.**
|
|
4
|
+
|
|
5
|
+
Standalone Markdown for future vatly-docs sync; no docs-site mutation was performed.
|
|
6
|
+
|
|
7
|
+
- [Configuration](Configuration.md): settings, installation and authorized billables
|
|
8
|
+
- [Billing](Billing.md): mixin, checkout, portal, subscription lifecycle
|
|
9
|
+
- [Storage and webhooks](Webhooks.md): transactions, signed snapshots, outbox and recovery
|
|
10
|
+
- [Testing and release](Development.md): supported versions, offline tests, boot and publishing
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Webhooks, storage and outbox
|
|
2
|
+
|
|
3
|
+
Register the configured HTTPS `billing/webhook/` path in Vatly separately. Setup
|
|
4
|
+
and CI never register endpoints or create remote test data. The route verifies raw
|
|
5
|
+
request bytes against Vatly-Signature (SDK HMAC, default ±300 seconds, secret rotation).
|
|
6
|
+
The signed event.id is the dedup key; untrusted event-ID headers are ignored.
|
|
7
|
+
Invalid signatures/payloads are 400, wrong methods405, committed duplicates200.
|
|
8
|
+
Processing failures propagate as 500 so Vatly retries; all local writes roll back.
|
|
9
|
+
|
|
10
|
+
Each scope+mode has a BillingScope row. An atomic UPDATE acquires its write lock
|
|
11
|
+
before dedup reads, serializing callbacks across workers. The same transaction
|
|
12
|
+
contains WebhookCall audit, immutable Checkout/ResourceLink writes, complete
|
|
13
|
+
BillingResource snapshots, processed_at and Outbox rows. PostgreSQL is recommended
|
|
14
|
+
for concurrent production workers. SQLite supports local development; lock contention
|
|
15
|
+
may fail a delivery, which is safe to retry. Database uniqueness is the final guard.
|
|
16
|
+
|
|
17
|
+
Fluent's async protocols use thread-sensitive sync_to_async. ORMDriver.process
|
|
18
|
+
bridges the work callback with async_to_sync while the outer atomic transaction is
|
|
19
|
+
open, so nested writes remain on that same connection/thread. Never substitute
|
|
20
|
+
`thread_sensitive=False`, parallelize repository writes, or put network effects in
|
|
21
|
+
the callback. Storage assumes Django's default database; custom routers/multi-DB
|
|
22
|
+
transactions need a purpose-built driver. All models are scoped by tenant/storefront
|
|
23
|
+
and mode. Generic entity references deliberately have no cascading user deletion.
|
|
24
|
+
Handle GDPR retention/deletion explicitly through audited host administration.
|
|
25
|
+
|
|
26
|
+
Built-in reactions preserve signed snapshots and make no implicit API reads.
|
|
27
|
+
checkout.paid/order/subscription deliveries converge even when reordered. Only
|
|
28
|
+
subscription.started creates a missing local subscription; updates do not invent
|
|
29
|
+
one. Unknown events remain audited/dispatched. Optional refunds/chargebacks retain
|
|
30
|
+
full financial snapshots. Customer bindings are never an ownership fallback.
|
|
31
|
+
The alpha follows Fluent's last-delivery-wins snapshot semantics: dedup is not
|
|
32
|
+
event ordering; reconcile stale/conflicting events explicitly.
|
|
33
|
+
|
|
34
|
+
Outbox is durable, not an automatic sender. Implement a worker that claims rows
|
|
35
|
+
with database locks, sends using an idempotent consumer key (scope + outbox primary
|
|
36
|
+
key), and marks delivered_at after success. Delivery is at least once, not exactly
|
|
37
|
+
once across external systems. Do not delete an outbox row before successful delivery.
|
|
38
|
+
Local-created notifications can precede eventual ownership linkage; consumers must
|
|
39
|
+
read current persisted ownership and retry/defer unattributed resources, not infer
|
|
40
|
+
it from customerId. No entitlements or email side effects are enabled by default.
|
|
41
|
+
|
|
42
|
+
Admin pages are read-only, but signed envelopes may contain personal data. Grant
|
|
43
|
+
model view permissions only to trusted staff and apply your retention policy.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling==1.27.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "vatly-django"
|
|
7
|
+
version = "0.1.0a2"
|
|
8
|
+
description = "Cashier-style Django billing on Vatly Fluent"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = ["Django>=5.2,<6.2", "vatly-fluent-python==0.1.0a2", "vatly-api-python==0.1.0a2"]
|
|
13
|
+
classifiers = ["Development Status :: 3 - Alpha", "Framework :: Django", "Typing :: Typed"]
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Homepage = "https://github.com/vatly/vatly-django"
|
|
17
|
+
Documentation = "https://docs.vatly.com"
|
|
18
|
+
Issues = "https://github.com/vatly/vatly-django/issues"
|
|
19
|
+
|
|
20
|
+
[dependency-groups]
|
|
21
|
+
dev = ["pytest>=8,<10", "pytest-django>=4.11,<5", "ruff>=0.14,<1", "mypy>=1.18,<2", "django-stubs>=5.2,<7", "twine>=6,<7"]
|
|
22
|
+
|
|
23
|
+
[tool.uv.sources]
|
|
24
|
+
vatly-api-python = {path = "vendor/vatly_api_python-0.1.0a2-py3-none-any.whl"}
|
|
25
|
+
vatly-fluent-python = {path = "vendor/vatly_fluent_python-0.1.0a2-py3-none-any.whl"}
|
|
26
|
+
|
|
27
|
+
[tool.hatch.build.targets.wheel]
|
|
28
|
+
packages = ["src/vatly_django"]
|
|
29
|
+
|
|
30
|
+
[tool.hatch.build.targets.sdist]
|
|
31
|
+
include = ["src", "tests", "vendor", "scripts", "docs", "README.md", "CHANGELOG.md", "LICENSE", "pyproject.toml"]
|
|
32
|
+
|
|
33
|
+
[tool.pytest.ini_options]
|
|
34
|
+
DJANGO_SETTINGS_MODULE = "tests.settings"
|
|
35
|
+
pythonpath = ["."]
|
|
36
|
+
testpaths = ["tests"]
|
|
37
|
+
|
|
38
|
+
[tool.ruff]
|
|
39
|
+
line-length = 100
|
|
40
|
+
target-version = "py310"
|
|
41
|
+
|
|
42
|
+
[tool.ruff.lint]
|
|
43
|
+
select = ["E4", "E7", "E9", "F", "I"]
|
|
44
|
+
|
|
45
|
+
[tool.mypy]
|
|
46
|
+
plugins = ["mypy_django_plugin.main"]
|
|
47
|
+
strict = true
|
|
48
|
+
files = ["src/vatly_django"]
|
|
49
|
+
|
|
50
|
+
[tool.django-stubs]
|
|
51
|
+
django_settings_module = "tests.settings"
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""Install the actual wheel outside the checkout, including pinned prerelease dependencies."""
|
|
2
|
+
|
|
3
|
+
import pathlib
|
|
4
|
+
import subprocess
|
|
5
|
+
import tempfile
|
|
6
|
+
|
|
7
|
+
root = pathlib.Path(__file__).resolve().parents[1]
|
|
8
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
9
|
+
env = pathlib.Path(tmp) / "venv"
|
|
10
|
+
subprocess.run(["uv", "venv", str(env)], check=True)
|
|
11
|
+
python = str(env / "bin/python")
|
|
12
|
+
subprocess.run(
|
|
13
|
+
[
|
|
14
|
+
"uv",
|
|
15
|
+
"pip",
|
|
16
|
+
"install",
|
|
17
|
+
"--python",
|
|
18
|
+
python,
|
|
19
|
+
*map(str, (root / "vendor").glob("*.whl")),
|
|
20
|
+
str(next((root / "dist").glob("*.whl"))),
|
|
21
|
+
],
|
|
22
|
+
check=True,
|
|
23
|
+
)
|
|
24
|
+
subprocess.run(
|
|
25
|
+
[
|
|
26
|
+
python,
|
|
27
|
+
"-c",
|
|
28
|
+
"from importlib.resources import files; from django.conf import settings; settings.configure(INSTALLED_APPS=['vatly_django'], DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}}); import django; django.setup(); from django.core.management import call_command; call_command('migrate', verbosity=0); from vatly_django.models import BillingScope; assert BillingScope.objects.count() == 0; assert files('vatly_django').joinpath('py.typed').is_file(); print('Isolated wheel, migrations and py.typed OK')",
|
|
29
|
+
],
|
|
30
|
+
cwd=tmp,
|
|
31
|
+
check=True,
|
|
32
|
+
)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from django.contrib import admin
|
|
6
|
+
from django.http import HttpRequest
|
|
7
|
+
|
|
8
|
+
from .models import (
|
|
9
|
+
BillingResource,
|
|
10
|
+
BillingScope,
|
|
11
|
+
Checkout,
|
|
12
|
+
CheckoutAttempt,
|
|
13
|
+
CustomerBinding,
|
|
14
|
+
Outbox,
|
|
15
|
+
ResourceLink,
|
|
16
|
+
WebhookCall,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class BillingReadOnlyAdmin(admin.ModelAdmin): # type: ignore[type-arg]
|
|
21
|
+
list_filter = ["scope"]
|
|
22
|
+
|
|
23
|
+
def has_add_permission(self, request: HttpRequest) -> bool:
|
|
24
|
+
return False
|
|
25
|
+
|
|
26
|
+
def has_change_permission(self, request: HttpRequest, obj: Any = None) -> bool:
|
|
27
|
+
return False
|
|
28
|
+
|
|
29
|
+
def has_delete_permission(self, request: HttpRequest, obj: Any = None) -> bool:
|
|
30
|
+
return False
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@admin.register(BillingResource)
|
|
34
|
+
class ResourceAdmin(BillingReadOnlyAdmin):
|
|
35
|
+
list_display = ["vatly_id", "resource_type", "entity_kind", "entity_id", "scope", "updated_at"]
|
|
36
|
+
search_fields = ["vatly_id", "entity_id"]
|
|
37
|
+
list_filter = ["scope", "resource_type"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@admin.register(WebhookCall)
|
|
41
|
+
class WebhookAdmin(BillingReadOnlyAdmin):
|
|
42
|
+
list_display = ["event_id", "event_name", "scope", "processed_at"]
|
|
43
|
+
search_fields = ["event_id"]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@admin.register(Outbox)
|
|
47
|
+
class OutboxAdmin(BillingReadOnlyAdmin):
|
|
48
|
+
list_display = ["id", "event_name", "scope", "created_at", "delivered_at"]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
for model in (Checkout, CheckoutAttempt, CustomerBinding, ResourceLink):
|
|
52
|
+
admin.site.register(model, BillingReadOnlyAdmin)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@admin.register(BillingScope)
|
|
56
|
+
class ScopeAdmin(BillingReadOnlyAdmin):
|
|
57
|
+
list_display = ["name", "testmode"]
|
|
58
|
+
list_filter = ["testmode"]
|