Two files, zero dependencies: the JS checkout widget for the buyer-facing badge, and the Python client for your backend. Every answer carries the tv1_* digest of the rules snapshot. Fail-closed by design: if the engine is unreachable, you get no numbers — the code never invents a rate.
Copy into your project or link directly — the widget is meant to be embedded in one line.
tv-widget.js tv_client.py README.mdThe script auto-scans data-tv-widget blocks and exposes TaxVega.calculate(). It shows a badge “VAT 19% · Germany · digest tv1_*” and returns the calculation to your JS. The widget never touches money — payment stays on your gateway.
<script src="https://your-site.example/sdk/tv-widget.js"
data-engine="https://engine.example:8797"
data-key="tv_..." data-lang="en"></script>
<!-- declarative badge anywhere on the page -->
<div data-tv-widget data-country="DE" data-buyer="b2c" data-amount="100"></div>
TaxVega.calculate({amount: 100, country: 'DE', buyer: 'b2c'})
.then(function (res) {
// res.rate === 19, res.grossAmount === 119.00,
// res.digest === 'tv1_bbadb83a17140ff66c1b1f56' — save it with the order
console.log(res.regime, res.rate, res.taxAmount, res.digest);
})
.catch(function (e) {
// e.code: 'network' | 'http_502' | 'bad_engine_answer' | 'bad_input'
// fail-closed: no numbers are shown, checkout still works
});
Copy tv_client.py into your project (Python 3.8+, no pip installs). Retry 3× on network/429/5xx with backoff; 4xx raise immediately.
curl -O https://your-site.example/sdk/tv_client.py
from tv_client import TaxVegaClient, TaxVegaError
tv = TaxVegaClient("https://taxvega.makomemory.com", key="tv_your_key")
res = tv.resolve("DE", buyer="b2c", vat_valid=False)
print(res["regime"], res["rate"], res["rule_digest"])
rules = tv.public_rules("RU") # rules as data + digest
res = tv.chain(participants=[{"id": "p0", "kind": "company", "country": "RU",
"role": "seller"},
{"id": "p1", "kind": "company", "country": "DE",
"role": "buyer"}],
links=[{"from": "p0", "to": "p1", "type": "goods",
"amount": 100000}])
try:
tv.resolve("DE")
except TaxVegaError as e:
print(e.code, e.detail) # fail-closed: no numbers on error
The same endpoints the widget and the SDK call. Key goes in the header, never in the URL.
curl "http://engine.example:8797/v1/resolve?country=DE&buyer=b2c&vat_valid=0"
curl -H "Authorization: Bearer tv_..." \
"http://engine.example:8797/v1/public/rules?country=RU"
curl -X POST -H "Content-Type: application/json" \
-H "Authorization: Bearer tv_..." \
-d '{"participants":[{"id":"p0","kind":"company","country":"RU","role":"seller"},
{"id":"p1","kind":"company","country":"DE","role":"buyer"}],
"links":[{"from":"p0","to":"p1","type":"goods","amount":100000}]}' \
"http://engine.example:8797/v1/chain"
No engine, no numbers. Every answer carries the digest; on failure you get a code and checkout continues without invented values.
| code | meaning |
|---|---|
200 | regime, rate, tv1_* digest |
401 | endpoint needs the key (chain), key missing |
402 | key unknown / demo quota over — sale possible, tax manually |
429 | limit reached — SDK retries 3× with backoff |
5xx | engine down — SDK retries 3×, then raises; widget shows “unavailable” |