Phase 4 §4: payment-before-pair for returning users + Maestro suite

Stages 5.1, 5.3, 5.4 of the returning-user flow rework. All three §4
entry paths now require payment BEFORE pairing, matching the updated
mermaid spec.

* Spec (requirement/flow_customer.mermaid.md §4): payment block converges
  three call-sites (bestie-yang-udah-kenal-online, bestie-baru,
  offline-popup → cari bestie lain). PairRoute dispatches lama → targeted
  pair, baru/cari-lain → §3 blast. §3 retains its post-payment-shared
  contract.

* Stage 5.1 (client_app): PaymentDraft carries targetedMitraId +
  topicSensitivity. bestie_history_list seeds the draft + pushes
  /payment/entry (was legacy /payment). searching_screen branches on
  draft.targetedMitraId for blast-vs-targeted dispatch.
  payment_entry uses resetExceptTarget(); bestie_choice_sheet + home
  _onCurhatBestieBaruPressed call explicit reset() before push so
  the keepAlive draft can't leak stale targeting into a blast.

* Stage 5.3 (client_app): new BestieOfflineVariant.prePayReturning.
  Bestie-history-list _BestieRow splits tappable from dim so offline
  rows render dimmed but route taps into the popup. CTA "cari bestie
  lain" resets the draft + pushes /payment/entry.

* Stage 5.4 (client_app): deleted legacy /payment route,
  payment_screen.dart, payment_notifier.dart(+.g.dart). router cleaned.

* Tests (requirement/phase4-customer-flow.md + client_app/.maestro/):
  six Maestro flows TS-01..TS-06 covering every §4 branching point,
  all passing end-to-end. Shared onboarding prelude under
  .maestro/subflows/. New helper scripts: accept_latest_pending,
  force_mitra_offline, force_other_mitra_online,
  reset_all_mitras_online, mitra_accept_latest_internal. New backend
  _test endpoints to match. /reset-phone now cascade-deletes
  customer_transactions (FK was blocking). /force-pairing-timeout
  branches targeted (RETURNING_CHAT_TIMEOUT via
  expireTargetedPairingRequest, now exported) vs blast (PAIRING_FAILED).
  seed_history_session also outputs MITRA_NAME_RE (regex-escaped) for
  reliable selectors against display names containing regex specials.

* mitra_app: dispose-during-deactivate guardrail for back-press on the
  mitra chat screen after the customer's goodbye message. Pending real
  emulator repro verification (carried over from 2026-05-15).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-17 20:25:15 +08:00
parent 1c9d81d81d
commit e09f76ceb6
32 changed files with 1755 additions and 680 deletions

View File

@@ -1,7 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../../core/constants.dart';
import '../../../core/pairing/pairing_notifier.dart';
import '../../../core/theme/halo_tokens.dart';
import '../../../core/theme/widgets/widgets.dart';
@@ -44,18 +43,32 @@ class _SearchingScreenState extends ConsumerState<SearchingScreen> {
ref.listenManual<PairingData>(pairingProvider, _onPairingState);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
// Kick off the blast if pairing hasn't started yet — Phase 4's
// multi-screen payment flow lands here without a startSearch call
// Kick off pairing if it hasn't started yet — Phase 4's multi-screen
// payment flow lands here without an upstream startSearch call
// (waiting → notif-gate → /chat/searching, no intermediate that
// owned the call).
// owned the call). Branch on draft.targetedMitraId: a returning-user
// "Curhat lagi" flow stamped the targeted mitra onto the draft before
// payment, so we fire the targeted request and bounce to the dedicated
// wait overlay; everything else is a general blast.
final state = ref.read(pairingProvider);
if (state is PairingInitialData) {
final draft = ref.read(paymentDraftNotifierProvider);
if (draft.paymentId != null) {
if (draft.targetedMitraId != null) {
// ignore: discarded_futures
ref.read(pairingProvider.notifier).startTargetedSearch(
paymentSessionId: draft.paymentId!,
mitraId: draft.targetedMitraId!,
mitraName: draft.targetedMitraName ?? 'Bestie',
topicSensitivity: draft.topicSensitivity,
);
context.go('/chat/waiting-targeted/${draft.targetedMitraId}');
return;
}
// ignore: discarded_futures
ref.read(pairingProvider.notifier).startSearch(
paymentSessionId: draft.paymentId!,
topicSensitivity: TopicSensitivity.regular,
topicSensitivity: draft.topicSensitivity,
);
}
}

View File

@@ -6,24 +6,31 @@ import '../../../core/constants.dart';
import '../../../core/pairing/pairing_notifier.dart';
import '../../../core/theme/halo_tokens.dart';
import '../../../core/theme/widgets/widgets.dart';
import '../../payment/state/payment_draft_provider.dart';
import '../../support/widgets/tanya_admin_sheet.dart';
/// Phase 4 Stage 8 — `BestieOfflinePopup`.
///
/// Two variants:
/// Three variants:
/// - [BestieOfflineVariant.returning] — the customer tried to chat with a
/// specific mitra (history "Curhat lagi"); the targeted attempt failed
/// (409 `targeted_mitra_offline`, or WS `returning_chat_timeout` /
/// `returning_chat_rejected`). Payment session is still `confirmed`, so we
/// surface a `Chat dengan bestie lain` primary CTA when other besties are
/// reachable (calls [Pairing.fallbackToBlast]).
/// - [BestieOfflineVariant.prePayReturning] — Stage 5.3: the customer tapped
/// a dimmed (offline) row in `BestieHistoryList` BEFORE any payment. No
/// payment session exists yet, so the "cari bestie lain" CTA resets the
/// payment draft and pushes `/payment/entry` for a fresh blast-payment
/// flow. This branch never calls [Pairing.fallbackToBlast] because there's
/// no `paymentSessionId` to attach to.
/// - [BestieOfflineVariant.new_] — the customer triggered a general blast
/// that bottomed out (no online besties). No fallback button; just a
/// ghost `tanya admin` and a `kembali ke home` exit.
///
/// Both variants expose `tanya admin` via a ghost CTA that opens the
/// All variants expose `tanya admin` via a ghost CTA that opens the
/// [TanyaAdminSheet].
enum BestieOfflineVariant { returning, new_ }
enum BestieOfflineVariant { returning, prePayReturning, new_ }
class BestieOfflinePopup extends ConsumerWidget {
final BestieOfflineVariant variant;
@@ -65,8 +72,12 @@ class BestieOfflinePopup extends ConsumerWidget {
final hasOtherAvailable = availabilityAsync.valueOrNull ?? false;
final isReturning = variant == BestieOfflineVariant.returning;
final title = isReturning ? '$mitraName lagi nggak online' : 'semua bestie lagi istirahat';
final body = isReturning
final isPrePayReturning = variant == BestieOfflineVariant.prePayReturning;
final mentionsBestie = isReturning || isPrePayReturning;
final title = mentionsBestie
? '$mitraName lagi nggak online'
: 'semua bestie lagi istirahat';
final body = mentionsBestie
? 'bestie kamu belum bisa nerima chat sekarang. coba bestie lain atau balik ke beranda dulu ya.'
: 'lagi nggak ada bestie yang siap dengerin. coba lagi bentar, atau hubungin admin biar dibantu.';
@@ -139,6 +150,19 @@ class BestieOfflinePopup extends ConsumerWidget {
);
},
)
else if (isPrePayReturning)
HaloButton(
label: 'cari bestie lain',
fullWidth: true,
onPressed: () {
// No payment session yet — clear any targeted-mitra intent
// on the draft so the fresh `/payment/entry` flow falls
// through to the blast branch.
ref.read(paymentDraftNotifierProvider.notifier).reset();
Navigator.of(context).pop();
context.push('/payment/entry');
},
)
else
HaloButton(
label: 'kembali ke home',
@@ -161,7 +185,7 @@ class BestieOfflinePopup extends ConsumerWidget {
TanyaAdminSheet.show(context);
},
),
if (canFallbackToBlast) ...[
if (canFallbackToBlast || isPrePayReturning) ...[
const SizedBox(height: HaloSpacing.s4),
HaloButton(
label: 'kembali ke home',