feat(documents): ticket and receipt PDFs, attached and downloadable (#35) #115

Merged
amiryahaya merged 10 commits from feat/35-pdf-documents into main 2026-10-28 06:38:00 +01:00
Owner

Closes #35.

What

Ticket and receipt PDFs, built on demand with signintech/gopdf (pure Go, no change to the distroless image), attached to the purchase email and downloadable in the apps.

  • internal/documents: renderer (A4, one page per ticket with QR + code, receipt with line table), Service (the only builder; limiter of 2 per node, 200-ticket cap, 3 s read-only snapshot), pgstore reader, Mailer.
  • Routes: GET /v1/me/transactions/{id}/tickets.pdf|receipt.pdf (own sales only, 404 otherwise) and GET /v1/admin/transactions/{id}/tickets.pdf|receipt.pdf (platform scope; admin_portal.tickets.scan OR admin_portal.finance.manage through the new rbac.Guard.RequireAny). Only completed sales; cancelled/replaced tickets are not printed.
  • Email: notify.Attachment, multipart/mixed in the SMTP sender; ticket sale = tickets + receipt, overstay = receipt only. Over 200 tickets keeps the receipt; over 6 MiB or any non-busy failure sends the text email; busy retries but never on the last attempt (no lost email).
  • Receipt is a plain receipt, not a KRA tax invoice. Nothing is stored. ADR 0024 records this, including the override of "render in the worker, not the API" (pure Go, milliseconds, capped).

Verification

  • make cover: 91.0 % (minimum 80 %); documents 93.1 %, documents/pgstore 83.6 %, notify 97.6 %, smtpsender 86.7 %.
  • make lint 0 issues, make contract ok, go test -race -count=1 ./... 55 packages ok, scripts/generate-clients.sh ok.
  • Dual-pass review: Pass 1 (Ponytail) Must fix none; Pass 2 no Critical, one Important (busy retry could dead-letter the purchase email) fixed with a test; Pass 1 re-check of the fix wave: Must fix none. Skipped Should-fix/nice-to-have: build generics, shared limiter, variadic PlatformOnly.

Not verified / owner to confirm ([verify] list in ADR 0024)

  • No QR was scanned with a phone or gate scanner (only the QR matrix is tested; sample PDFs were looked at once).
  • 200-ticket and 6 MiB caps; staff may download any customer's ticket PDF (carries the secret code); organization access to sales comes with #51/#52; guest sales are staff-only; font files came from the notofonts repo (provenance unverified).
  • Known minors: CleanText negative max, no end-to-end Mailer-to-SMTP test, 401/403 from the admin guard lack no-store.

🤖 Generated with Claude Code

Closes #35. ## What Ticket and receipt PDFs, built on demand with `signintech/gopdf` (pure Go, no change to the distroless image), attached to the purchase email and downloadable in the apps. - `internal/documents`: renderer (A4, one page per ticket with QR + code, receipt with line table), `Service` (the only builder; limiter of 2 per node, 200-ticket cap, 3 s read-only snapshot), `pgstore` reader, `Mailer`. - Routes: `GET /v1/me/transactions/{id}/tickets.pdf|receipt.pdf` (own sales only, 404 otherwise) and `GET /v1/admin/transactions/{id}/tickets.pdf|receipt.pdf` (platform scope; `admin_portal.tickets.scan` OR `admin_portal.finance.manage` through the new `rbac.Guard.RequireAny`). Only completed sales; cancelled/replaced tickets are not printed. - Email: `notify.Attachment`, `multipart/mixed` in the SMTP sender; ticket sale = tickets + receipt, overstay = receipt only. Over 200 tickets keeps the receipt; over 6 MiB or any non-busy failure sends the text email; busy retries but never on the last attempt (no lost email). - Receipt is a plain receipt, not a KRA tax invoice. Nothing is stored. ADR 0024 records this, including the override of "render in the worker, not the API" (pure Go, milliseconds, capped). ## Verification - `make cover`: **91.0 %** (minimum 80 %); documents 93.1 %, documents/pgstore 83.6 %, notify 97.6 %, smtpsender 86.7 %. - `make lint` 0 issues, `make contract` ok, `go test -race -count=1 ./...` 55 packages ok, `scripts/generate-clients.sh` ok. - Dual-pass review: Pass 1 (Ponytail) Must fix none; Pass 2 no Critical, one Important (busy retry could dead-letter the purchase email) fixed with a test; Pass 1 re-check of the fix wave: Must fix none. Skipped Should-fix/nice-to-have: build generics, shared limiter, variadic `PlatformOnly`. ## Not verified / owner to confirm ([verify] list in ADR 0024) - No QR was scanned with a phone or gate scanner (only the QR matrix is tested; sample PDFs were looked at once). - 200-ticket and 6 MiB caps; staff may download any customer's ticket PDF (carries the secret code); organization access to sales comes with #51/#52; guest sales are staff-only; font files came from the notofonts repo (provenance unverified). - Known minors: `CleanText` negative max, no end-to-end Mailer-to-SMTP test, 401/403 from the admin guard lack `no-store`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Pure-Go A4 PDFs with gopdf (MIT): one page per ticket with its QR
(rsc.io/qr, level M) and the code in groups of four; a receipt whose
lines table continues on new pages, with totals, payment methods and
the footer on every page. Noto Sans Regular/Bold (SIL OFL) embedded.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Service builds ticket and receipt PDFs on demand behind a per-node Limiter
(ErrBusy without reading when full), caps a ticket PDF at MaxTickets.
pgstore reads a completed sale in one REPEATABLE READ READ ONLY snapshot:
receipt (Nairobi completion date, buyer, lines, succeeded payment methods)
and its valid tickets, master first, including a top-up's replacements.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Line prices are already net of the promo (ADR 0014): print the discount as
included in them, and no row when it is zero. Read at most MaxTickets+1
tickets under a 3 s statement timeout; a timeout is ErrBusy.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
GET /v1/me/transactions/{id}/tickets.pdf|receipt.pdf (the buyer's own, else 404)
and GET /v1/admin/transactions/{id}/tickets.pdf|receipt.pdf (platform scope,
admin_portal.tickets.scan or admin_portal.finance.manage, via the new
rbac.Guard.RequireAny and documents.StaffOnly). Downloads are attachments with
fixed names, no-store and nosniff; ErrTooManyTickets is a 422, ErrBusy a 503
with Retry-After: 1. Four OpenAPI operations (tag Documents) and live calls.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
notify.Attachment and Message.Attachments; notify.Documents (consumed by
PurchaseHandler) is implemented by documents.Mailer: ticket PDF (not for
an overstay or a sale without valid tickets) and receipt, from one read
in one build slot. Busy wraps notify.ErrDocumentsBusy and retries the
job; any other failure or more than 10 MB sends the email without them
and logs the sale id only. The SMTP sender wraps the alternative body in
multipart/mixed with base64 parts and refuses unsafe file names; without
attachments the message is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A sale over MaxTickets now skips only the ticket PDF and keeps the
receipt. The attachment cap is 7 MB raw (base64 adds a third, so it
stays under a 10 MB relay limit). The SMTP sender accepts only
[A-Za-z0-9-] plus .pdf as an attachment name and builds multipart/mixed
only when there are attachments; a build test pins CRLF, 76-column
base64, the closing boundary and an empty attachment.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
7 MiB raw is about 10.04 million bytes once base64 and CRLFs are added,
over a 10,000,000-byte relay limit. 6 MiB raw is about 8.6 million bytes
on the wire; the comment shows the arithmetic.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(documents): final review fixes (#35)
All checks were successful
ci / changes (pull_request) Successful in 11s
ci / clients (pull_request) Successful in 2m1s
ci / api (pull_request) Successful in 19m23s
ci / ci-gate (pull_request) Successful in 3s
f57272bd40
- A busy renderer no longer dead-letters the purchase email: busy retries
  only before the last attempt, then the email goes text-only.
- notify.Documents.Attachments takes only the sale id; the Mailer uses the
  sale type from its own read. SaleDocs.Status (unused) removed.
- Receipt: sale type display names, no Paid by row without payments,
  amounts never shortened; a master without members prints no group line.
- Spec: receipts document no 422. ADR 0024 and CLAUDE.md: busy and
  last-attempt rule, cap counts the master, refunds, [verify] marks.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!115
No description provided.