feat(sales): overstay charges for checked-in tickets (#36, overstay slice) #104

Merged
amiryahaya merged 7 commits from feat/36-overstay into main 2026-10-26 18:57:44 +01:00
Owner

Overstay slice of #36 (does not close it: vehicle add-on and ticket top-up (upgrade) remain, as separate PRs).

What

  • Migration 0022: transactions.type gains overstay; new immutable parent_transaction_id and gate_id; one transaction_lines row per overstayed ticket (ticket_id, quantity 1) tied to a park-entry ticket of the parent sale and to its product by trigger.
  • sales.Overstay.Create (POST /v1/admin/gates/{id}/overstay, admin_portal.tickets.scan, Idempotency-Key required, body codes + payment_method): finds the checked-in, overstayed tickets under the ticket-family locks (new checkin.Service.Overstayed, ADR 0017 Kenya-date rule), prices each overstay day at that day's park-product price in the parent sale's currency, totals through totals.Overstay (no promo; no tax or fee on wallet), writes a pending child sale. A master code expands to its overstayed children; one charge per ticket while not cancelled; at most 30 days; a day without a price is a 409 no_price; a charge that rounds to zero but is not free is a 422 (same rule as checkout).
  • Completion (Completer.Complete, type-aware): an overstay issues no tickets and takes no seats, and checks the tickets out in the same transaction through the new checkin.Service.CheckOutPaid. Wallet pay, waive and M-Pesa settle all go through it. A cancelled or expired charge leaves the tickets checked in; a late payment is refund_due as for any sale. The purchase email job is reused with an overstay subject.
  • idempotency.Handle now writes a field rejection with its own status (409) instead of always 422 (existing 422 behaviour unchanged); checkin.WriteRefusal became checkin.Refusal; NewCompleter takes the check-out. OpenAPI and live contract tests, ADR 0018, spec, CLAUDE.md "Overstay" section. Plan: docs/superpowers/plans/2026-10-27-overstay.md.

Rulings and limits (ADR 0018)

  • Staff cannot take money in this slice: the customer pays from the app (wallet, M-Pesa) or Finance waives. card is accepted but has no customer route yet, so card charges and charges on guest sales can only be waived. Taking money at the gate waits for the POS (#48).
  • A pending charge blocks a new one for the same tickets until paid, cancelled or expired (intended double-charge guard; no cancel route yet).
  • One ticket's gate refusal at completion leaves all of the charge's tickets checked in while the sale still completes; a check-out database error during an M-Pesa settle rolls the payment row back and is recovered by the callback retry and reconciliation.
  • PayWithWallet can wait up to the 3 s lock wait for a ticket family lock behind a gate scan (retryable 503).
  • Guesses to confirm [verify]: the 30-day cap; a day with no price refuses the charge (legacy silently charged nothing); expiry is capped at Kenya midnight; wallet payment is allowed (the legacy POS hid it); the overstay email wording; Kenya dates instead of legacy UTC dates; pricing uses each overstay day's own price.
  • The overstay receipt lists one line per ticket with its total, not the individual days.

Review

Dual pass done. Pass 1: no Must fix (empty-list panic, silent blank error and the pending-charge rule fixed or documented). Pass 2 found a tiny positive total treated as free (the visitor would be checked out unpaid), fixed in eff6a0b with a line/product trigger gap and five ADR limits; Pass 1 re-check: Ship.

Checks

make cover: 90.0% (minimum 80%). go test -race ./..., make lint, make contract and client generation green (implementer run); database end-to-end tests cover the Review Focus lines, including real-goroutine races.

Deploy

Run migration 0022. No new environment variables. The worker must be running (completion emails and expiry). A dev database already migrated to 0022 from an earlier build needs down then up or make clean-testdb.

🤖 Generated with Claude Code

Overstay slice of #36 (does **not** close it: vehicle add-on and ticket top-up (upgrade) remain, as separate PRs). ## What - **Migration 0022:** `transactions.type` gains `overstay`; new immutable `parent_transaction_id` and `gate_id`; one `transaction_lines` row per overstayed ticket (`ticket_id`, quantity 1) tied to a park-entry ticket of the parent sale and to its product by trigger. - **`sales.Overstay.Create`** (`POST /v1/admin/gates/{id}/overstay`, `admin_portal.tickets.scan`, `Idempotency-Key` required, body `codes` + `payment_method`): finds the checked-in, overstayed tickets under the ticket-family locks (new `checkin.Service.Overstayed`, ADR 0017 Kenya-date rule), prices each overstay day at that day's park-product price in the parent sale's currency, totals through `totals.Overstay` (no promo; no tax or fee on wallet), writes a pending child sale. A master code expands to its overstayed children; one charge per ticket while not cancelled; at most 30 days; a day without a price is a 409 `no_price`; a charge that rounds to zero but is not free is a 422 (same rule as checkout). - **Completion** (`Completer.Complete`, type-aware): an overstay issues no tickets and takes no seats, and checks the tickets out in the same transaction through the new `checkin.Service.CheckOutPaid`. Wallet pay, waive and M-Pesa settle all go through it. A cancelled or expired charge leaves the tickets checked in; a late payment is `refund_due` as for any sale. The purchase email job is reused with an overstay subject. - `idempotency.Handle` now writes a field rejection with its own status (409) instead of always 422 (existing 422 behaviour unchanged); `checkin.WriteRefusal` became `checkin.Refusal`; `NewCompleter` takes the check-out. OpenAPI and live contract tests, ADR 0018, spec, CLAUDE.md "Overstay" section. Plan: `docs/superpowers/plans/2026-10-27-overstay.md`. ## Rulings and limits (ADR 0018) - Staff cannot take money in this slice: the customer pays from the app (wallet, M-Pesa) or Finance waives. `card` is accepted but has no customer route yet, so card charges and charges on guest sales can only be waived. Taking money at the gate waits for the POS (#48). - A pending charge blocks a new one for the same tickets until paid, cancelled or expired (intended double-charge guard; no cancel route yet). - One ticket's gate refusal at completion leaves all of the charge's tickets checked in while the sale still completes; a check-out database error during an M-Pesa settle rolls the payment row back and is recovered by the callback retry and reconciliation. - `PayWithWallet` can wait up to the 3 s lock wait for a ticket family lock behind a gate scan (retryable 503). - **Guesses to confirm [verify]:** the 30-day cap; a day with no price refuses the charge (legacy silently charged nothing); expiry is capped at Kenya midnight; wallet payment is allowed (the legacy POS hid it); the overstay email wording; Kenya dates instead of legacy UTC dates; pricing uses each overstay day's own price. - The overstay receipt lists one line per ticket with its total, not the individual days. ## Review Dual pass done. Pass 1: no Must fix (empty-list panic, silent blank error and the pending-charge rule fixed or documented). Pass 2 found a tiny positive total treated as free (the visitor would be checked out unpaid), fixed in `eff6a0b` with a line/product trigger gap and five ADR limits; Pass 1 re-check: Ship. ## Checks `make cover`: **90.0%** (minimum 80%). `go test -race ./...`, `make lint`, `make contract` and client generation green (implementer run); database end-to-end tests cover the Review Focus lines, including real-goroutine races. ## Deploy Run migration 0022. No new environment variables. The worker must be running (completion emails and expiry). A dev database already migrated to 0022 from an earlier build needs `down` then `up` or `make clean-testdb`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
docs(overstay): CLAUDE.md rules for overstay charges (#36)
All checks were successful
ci / changes (pull_request) Successful in 16s
ci / clients (pull_request) Successful in 1m9s
ci / api (pull_request) Successful in 5m48s
ci / ci-gate (pull_request) Successful in 2s
cb05fb84e0
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!104
No description provided.