feat(mobile): customer ticket app with offline tickets and wallet checkout #169

Merged
amiryahaya merged 27 commits from claude/mobile-app-design-060334 into main 2026-11-06 10:37:12 +01:00
Owner

Customer ticket app for Android in mobile/ticket (Flutter 3.35.3), following the "Clear booking" design. Tickets and receipts are saved on the phone and open without internet; customers can also browse parks and buy.

Design: docs/superpowers/specs/2026-11-06-mobile-ticket-app-design.md. Plan: docs/superpowers/plans/2026-11-06-mobile-ticket-app.md.

What it does

  • Sign-in: OIDC PKCE (client kws-ticket-app); the refresh token is kept in secure storage. After a sign-out, the next sign-in asks for the password again (prompt=login).
  • Offline:
    • Tickets, sales, receipt and tickets PDFs, and the profile are kept in an AES-GCM encrypted store. Trips, QR codes (drawn on the phone) and PDFs open with no network.
    • The park catalogue and photos are cached.
    • Sign-out wipes the private data, shared PDF copies and opened parks.
  • Buying:
    • Parks list, park page, ticket picker and the server cart (/v1/me/cart).
    • Checkout by wallet only: M-Pesa is parked and top-up is a disabled "coming soon" button. A 100 % promo code completes without a wallet balance.
    • Checkout and pay are idempotent, and prices are never calculated on the phone.
  • API: checkout records channel mobile when the token's azp/client_id equals KWS_OIDC_MOBILE_CLIENT_ID; unset = always website.
  • Dev:
    • deploy/dev-idp/seed-wallet.sql adds test money.
    • The mock IdP gets a kws-ticket-app mapping. Restart the idp container.
  • CI: new mobile-ticket job (scripts/mobile-ci.sh: analyze, tests, coverage gate, debug app bundle), wired through detect-changes.sh and in ci-gate.needs.

Checks

  • scripts/mobile-ci.sh at 31f6253: exit 0, 271 tests, line coverage of mobile/ticket/lib 97.7 % (minimum 80 %, every lib file must be in lcov).
  • make cover: 91.5 % (minimum 80 %).
  • Emulator journey, not in CI. It ran on an Android 30 emulator against the dev API at 2157f0a, before the final review fixes, and was not rerun after them.
    • Covered: sign-in, browse, add, wallet pay, then the pass and QR; after a restart with the network cut, the trip, QR, receipt and tickets PDF still opened.
    • Not real: the sign-in step posts the mock IdP form itself (the AppAuth browser step is not covered), and offline is simulated by a failing HTTP client.
  • Reviews: one review per task, then a whole-branch dual-pass review (Ponytail complexity, then correctness); all findings fixed or ruled.

Not done or not checked

  • Release builds sign with the debug key, and CI builds a debug bundle only (no R8/release build). Set up signing before any upload.
  • prompt=login is not checked against Zitadel or the mock IdP.
  • Retry-After is not read. The wallet page shows the last 50 entries. An order left at the pay step just expires.
  • iOS is not configured for release.
  • Zitadel kws-ticket-app setup: see mobile/ticket/README.md.

🤖 Generated with Claude Code

Customer ticket app for Android in `mobile/ticket` (Flutter 3.35.3), following the "Clear booking" design. Tickets and receipts are saved on the phone and open without internet; customers can also browse parks and buy. Design: `docs/superpowers/specs/2026-11-06-mobile-ticket-app-design.md`. Plan: `docs/superpowers/plans/2026-11-06-mobile-ticket-app.md`. ## What it does - **Sign-in:** OIDC PKCE (client `kws-ticket-app`); the refresh token is kept in secure storage. After a sign-out, the next sign-in asks for the password again (`prompt=login`). - **Offline:** - Tickets, sales, receipt and tickets PDFs, and the profile are kept in an AES-GCM encrypted store. Trips, QR codes (drawn on the phone) and PDFs open with no network. - The park catalogue and photos are cached. - Sign-out wipes the private data, shared PDF copies and opened parks. - **Buying:** - Parks list, park page, ticket picker and the server cart (`/v1/me/cart`). - Checkout by **wallet only**: M-Pesa is parked and top-up is a disabled "coming soon" button. A 100 % promo code completes without a wallet balance. - Checkout and pay are idempotent, and prices are never calculated on the phone. - **API:** checkout records channel `mobile` when the token's `azp`/`client_id` equals `KWS_OIDC_MOBILE_CLIENT_ID`; unset = always `website`. - **Dev:** - `deploy/dev-idp/seed-wallet.sql` adds test money. - The mock IdP gets a `kws-ticket-app` mapping. **Restart the `idp` container.** - **CI:** new `mobile-ticket` job (`scripts/mobile-ci.sh`: analyze, tests, coverage gate, debug app bundle), wired through `detect-changes.sh` and in `ci-gate.needs`. ## Checks - `scripts/mobile-ci.sh` at 31f6253: exit 0, 271 tests, **line coverage of `mobile/ticket/lib` 97.7 %** (minimum 80 %, every lib file must be in lcov). - `make cover`: **91.5 %** (minimum 80 %). - Emulator journey, not in CI. It ran on an Android 30 emulator against the dev API at 2157f0a, before the final review fixes, and was not rerun after them. - Covered: sign-in, browse, add, wallet pay, then the pass and QR; after a restart with the network cut, the trip, QR, receipt and tickets PDF still opened. - Not real: the sign-in step posts the mock IdP form itself (the AppAuth browser step is not covered), and offline is simulated by a failing HTTP client. - Reviews: one review per task, then a whole-branch dual-pass review (Ponytail complexity, then correctness); all findings fixed or ruled. ## Not done or not checked - Release builds sign with the debug key, and CI builds a debug bundle only (no R8/release build). Set up signing before any upload. - `prompt=login` is not checked against Zitadel or the mock IdP. - Retry-After is not read. The wallet page shows the last 50 entries. An order left at the pay step just expires. - iOS is not configured for release. - Zitadel `kws-ticket-app` setup: see `mobile/ticket/README.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bearer JWT's azp (else client_id) is kept in the request context; checkout
records channel mobile when it equals KWS_OIDC_MOBILE_CLIENT_ID, else website.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Profile tab (name and email cached in the private store, currency choice, last synced, sign out with confirm), Wallet page (online only,
disabled top-up), README for the local stack, release signing and the Zitadel client, a debug-only cleartext config, an emulator
journey test, and the mock IdP mapping that gives kws-ticket-app tokens the kws-api audience.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Sign-out and a user switch also delete share_plus's PDF copy, the app's own
  share copies (now in <tmp>/kws_pdf) and opened_parks (store/wipe.dart).
- My trips shows the saved trips (pass, QR, PDFs) for the kept subject after
  a refused refresh, with a sign-in banner; a stale read after sign-out is
  dropped.
- Saved tickets are parsed row by row (savedTickets / ticketsOf); sync reads
  sales as plain JSON, so an unknown enum value no longer breaks trips,
  checkout or the PDF plan. PDF writes go through the same guard as JSON.
- Share failures show a fixed SnackBar; the missing-PDF text fits a PDF that
  never downloads; manifest declares INTERNET and allowBackup=false.
- Shared helpers from the complexity review: one sign-in message helper (the
  cart now shows it), lib/kenya_time.dart, lib/api_json.dart (ApiException
  with the status), one wallet reader, no plan-task comments, unused
  ProductGroup.key and QuantityStepper.max removed, PdfScreen.viewer
  nullable, crypto dev dependency dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A 403 from checkout (place, pay, wallets) and the wallet screen shows one
  fixed text; sync records it as `blocked` (saved data kept) and Profile
  shows the text instead of waiting forever.
- Opening the Profile tab syncs only when the last private sync is 60 s old.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign-out does not end the identity provider's browser session, so on a shared
phone the next Sign in could silently reuse the previous customer's cookie.
An explicit sign-out now stores a flag (SecureKv `login_prompt`, written before
the wipe); the next sign-in sends prompt=login and the flag is cleared once a
sign-in succeeds. A refused refresh or a user switch does not set it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fix(mobile): hide trips during sign-out, tidy shared helpers
All checks were successful
ci / changes (pull_request) Successful in 16s
ci / clients (pull_request) Successful in 2m5s
ci / web-partner (pull_request) Successful in 7m6s
ci / api (pull_request) Successful in 13m6s
ci / web-ticket (pull_request) Successful in 14m48s
ci / mobile-ticket (pull_request) Successful in 19m13s
ci / web-admin (pull_request) Successful in 4m33s
ci / ci-gate (pull_request) Successful in 7s
31f6253687
- Session.signOut forgets the subject in memory and notifies before the wipe,
  so a failing wipe no longer leaves My trips showing the signed-out
  customer's tickets (the stored sub/flag order is unchanged).
- One isBlocked() / blockedStatus in api_json.dart for the deactivated-account
  403 (sync, checkout, wallet screen).
- WalletInfo, walletToPay and myWallets move to lib/wallets.dart; the wallet
  screen no longer imports checkout.
- SyncService's doc comment attaches to the class again (helpers moved below).

Co-Authored-By: Claude Opus 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!169
No description provided.