Code: Invoicing with web services: VAT, SOAP and GraphQL
Invoicing with web services: the code
The programs behind the slides, for Jennifer 0.27.0. Run everything from this folder. Two programs use decks, @deckyard/vies and @deckyard/money, listed in deck.toml: run jvc update once here to resolve them and fill vendor/ (it also writes camcorder.lock; later, jvc install restores from that lock).
Nothing here needs an account. The VAT checks go to the European Commission's VIES test service (checkVatTestService), which answers by number: 100 valid, 200 invalid, 300 SERVICE_UNAVAILABLE, 600 MS_MAX_CONCURRENT_REQ. The shop is a stand-in written in Jennifer on 127.0.0.1:8099; its token is the placeholder demo-token. Companies, addresses and the seller's VAT ID ATU12345678 are invented.
Servers (start these first)
shop.j: the GraphQL stand-in. It answers the operationsOrders(cursor pages of seven invented orders) andOrder(a single order;2026-0199gives aFORBIDDENerror with HTTP 200) by name; it does not parse GraphQL. Run:jennifer run shop.j &vies_down.j: VIES on a bad day, on127.0.0.1:8098:/maintenanceanswers 503 with an HTML page,/slowwaits 5 seconds first ("When VIES is down"). Run:jennifer run vies_down.j &
Programs
soap_send.j:soap.operation,soap.envelope, andsoap.sendagainst the test service, a fault with HTTP 200 ("SOAP without a WSDL", "Calling VIES by hand"). Run:jennifer run soap_send.jsoap_call.j:soap.call, and a fault as asoap.SoapError("call: a fault is an error"). Run:jennifer run soap_call.jvies_basics.j: the deck'sparseand syntax check,check,checkApproxand aViesError("What @deckyard/vies adds", "check and checkApprox", "When VIES says no, or not now"). Needsjvc update. Run:jennifer run vies_basics.jorders.j: all open orders, page by page ("Every page, until there is no next"). Needsshop.j. Run:SHOP_TOKEN=demo-token jennifer run orders.jgraphql_errors.j: errors in a 200 answer,tryQuery, and a 401 ("Errors arrive with HTTP 200"). Needsshop.j. Run:SHOP_TOKEN=demo-token jennifer run graphql_errors.jrobust.j: retries, a maintenance page, a timeout and a host nobody listens on ("When VIES is down"). Needsvies_down.jandjvc update. Run:jennifer run robust.jinvoice.j: the whole pipeline: orders fromshop.j, VAT checks with a one-day cache (vat-cache.json) and an audit trail (vat-audit.jsonl), the tax decision, amounts with@deckyard/money, oneinvoice-<number>.pdfper issued invoice ("The decision as code", "The amounts", "On the invoice", "The result", "Unverified is a result", "A cache that respects the rules", "The audit trail"). Needsshop.jandjvc update. Run:SHOP_TOKEN=demo-token jennifer run invoice.j(deletevat-cache.jsonandvat-audit.jsonlto start over).recheck.j: asks VIES again for every VAT ID whose latest audit record isunverified("The audit trail"). Run afterinvoice.j:jennifer run recheck.j
The string trap
The parse error on "GraphQL: the query is a raw string" comes from a two-line file that is deliberately not included, because it does not parse:
use io;
def q as string init "{ viewer { login } }";
io.printf("%s\n", $q);Stop the servers with kill %1 %2 (or pkill -f shop.j, pkill -f vies_down.j) when you are done.
Not tax or legal advice: the tax decision in invoice.j is a simplified example for an Austrian seller of consulting services.
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 3.4 KiB | raw |
| deck.toml | 286 B | raw |
| graphql_errors.j | 1.1 KiB | raw |
| invoice.j | 9.9 KiB | raw |
| orders.j | 1.3 KiB | raw |
| recheck.j | 983 B | raw |
| robust.j | 1.1 KiB | raw |
| shop.j | 6.0 KiB | raw |
| soap_call.j | 888 B | raw |
| soap_send.j | 1.0 KiB | raw |
| vies_basics.j | 1011 B | raw |
| vies_down.j | 640 B | raw |