feat(partnerpay): cancel an itinerary and refund the organization (#52, PR B) #159

Merged
amiryahaya merged 6 commits from feat/partner-cancel-52 into main 2026-11-04 16:45:44 +01:00
Owner

#52 PR B: cancel an itinerary and refund the organization

POST /v1/orgs/{id}/itineraries/{itinerary_id}/cancel ({version}, Idempotency-Key, business_portal.itinerary.make_payment, purchase rate class).

  • Unpaid sales are cancelled through Completer.Cancel; paid sales have their tickets cancelled (checkin.CancelSaleTickets, gateless activities) and the payment refunded to the organization wallet (payments.Service.RefundSucceeded, key refund:<payment id>; a waived payment is only closed).
  • Any checked-in/out ticket refuses the whole cancel (409 ticket_used); an expired one 409 ticket_expired; wrong state 409 not_cancellable; stale version 409.
  • Migration 0040: payments_guard() also allows succeeded -> refund_due; ticket_activities.gate_id becomes nullable.
  • Cancelled email (notify.itinerary_cancelled, queued in the transaction, worker sends).
  • Review fixes: deadlock (40P01) is wallet.ErrBusy (retryable 503); the M-Pesa STK job skips a sale no longer processing.

Coverage: make cover total 91.4% (minimum 80%). make lint 0 issues.
Review: dual pass (Ponytail complexity, then correctness); Pass 1 re-checked after fixes.

Rulings / [verify] for the owner

  • Finance reports and receipts shift after a refund on a completed sale (a completed sale stays completed).
  • Child sales (vehicle add-on, top-up) are not cancelled or refunded.
  • The payments guard is wider than "this path only".
  • Gateless cancellations are absent from the ticket-activity report.
  • No itinerary log row for the cancel.

🤖 Generated with Claude Code

## #52 PR B: cancel an itinerary and refund the organization `POST /v1/orgs/{id}/itineraries/{itinerary_id}/cancel` (`{version}`, `Idempotency-Key`, `business_portal.itinerary.make_payment`, `purchase` rate class). - Unpaid sales are cancelled through `Completer.Cancel`; paid sales have their tickets cancelled (`checkin.CancelSaleTickets`, gateless activities) and the payment refunded to the organization wallet (`payments.Service.RefundSucceeded`, key `refund:<payment id>`; a waived payment is only closed). - Any checked-in/out ticket refuses the whole cancel (409 `ticket_used`); an expired one 409 `ticket_expired`; wrong state 409 `not_cancellable`; stale version 409. - Migration 0040: `payments_guard()` also allows `succeeded -> refund_due`; `ticket_activities.gate_id` becomes nullable. - Cancelled email (`notify.itinerary_cancelled`, queued in the transaction, worker sends). - Review fixes: deadlock (40P01) is `wallet.ErrBusy` (retryable 503); the M-Pesa STK job skips a sale no longer `processing`. **Coverage:** `make cover` total 91.4% (minimum 80%). `make lint` 0 issues. **Review:** dual pass (Ponytail complexity, then correctness); Pass 1 re-checked after fixes. ### Rulings / [verify] for the owner - Finance reports and receipts shift after a refund on a completed sale (a completed sale stays `completed`). - Child sales (vehicle add-on, top-up) are not cancelled or refunded. - The payments guard is wider than "this path only". - Gateless cancellations are absent from the ticket-activity report. - No itinerary log row for the cancel. 🤖 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>
fix(partnerpay): review fixes for cancel (#52)
All checks were successful
ci / changes (pull_request) Successful in 16s
ci / clients (pull_request) Successful in 2m17s
ci / web-partner (pull_request) Successful in 3m22s
ci / web-admin (pull_request) Successful in 5m0s
ci / web-ticket (pull_request) Successful in 7m39s
ci / api (pull_request) Successful in 20m20s
ci / ci-gate (pull_request) Successful in 11s
62f01a3d83
Deadlock maps to wallet.ErrBusy, STK push skipped for a non-processing sale,
expired tickets refuse the cancel (409 ticket_expired), email and spec text.

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!159
No description provided.