feat(topup): ticket top-up (upgrade) sales (#36) #106
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/kws!106
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/36-ticket-topup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Ticket top-up (upgrade) slice of #36, the last one. Closes the remaining part of #36 (refunds #100, overstay #104 and vehicle add-on #105 already merged).
What it does
POST /v1/admin/gates/{id}/ticket-top-ups(Idempotency-Keyrequired, permissionadmin_portal.tickets.scan). It creates a child saletype = 'topup_ticket'for the difference (every day of the stay in the parent's currency, minus what the old ticket was paid; no promo, tax or fee). The customer pays (wallet or M-Pesa) or Finance waives it.checkin.Service.CancelReplaced, insideCompleter.Complete, before the status change) and the new tickets are issued into the parent sale under the same master withreplaces_ticket_id, so check-in, overstay and add-ons work on them unchanged. A ticket used or expired before payment cancels the sale and the payment becomesrefund_due.createTicketTopupplus live contract test, CLAUDE.md "Ticket top-up" section.LockSaleis nowFOR NO KEY UPDATE: found in review, a wallet-paid top-up and a Finance refund of the parent's payment could deadlock (FK key-share on the parent vsFOR UPDATE). A race test forces the interleaving; it failed with40P01before the change.Owner decisions (approved defaults)
Credit = what was paid (after promo); whole stay priced (deliberate fix: legacy charged the last day only; the 1-day legacy golden case still matches); cheaper or equal refused (422); no upgrade after check-in; staff only (no customer self-upgrade); old ticket becomes
cancelled; limited-seat target products refused and an old limited seat is not released; vehicle tickets not upgradable.Known limits (ADR 0020)
No staff-side payment (#48); no downgrade or refund of a difference; form answers not carried (only holder name; not built yet); an expired-but-pending top-up reads as pending for up to a minute until
sales.expireruns; a ticket'stransaction_idis the visit's sale, so reports (#38) must count top-up lines rather than ticket prices.Review (dual pass)
SELECT typeinInsertTicketsand one unreachable guard.Verification
go test -race -count=1 ./...green (47 packages),make lint0 issues,make contractok, clients generated, migration 0024 down/up round trip passes.make cover: total coverage 90.4% (minimum 80%).Deploy
Run migration 0024 (
KWS_MODE=migrate). No new environment variables. The worker must be running (as for checkout); API and worker both wire the check-in service into the completer.🤖 Generated with Claude Code