Backend - payment_sessions → payment_requests rename across DB schema + 29 files - payment.service.js becomes product-agnostic owner: EventEmitter + Xendit wrapper + requestPayment / confirmPayment public API; legacy aliases retained for existing chat callers - Webhook handler at POST /api/shared/payment/webhooks/xendit, with constant-time token verification (8 vitest cases) - Server-driven pairing: payment.service emits payment_request.confirmed → pairing subscriber starts the blast. Legacy POST /chat/request still works during the cutover. - Reconciliation sweeper extended (re-emits events for confirmed rows with no chat session) - SIGTERM drain + startup reconciliation pass in server.js Customer app - waiting_payment_screen opens xendit_invoice_url via LaunchMode.inAppBrowserView - searching / no-bestie / targeted-waiting / pairing-notifier updated to consume the new payment_request_id contract - pending_payments_provider + bestie-unavailable dialog migrated Dev / testing - XENDIT_ENABLED=false is the safe default; .env.example documents the four new vars - backend/.dev/xendit-fake-webhook.sh exercises the handler without ngrok - 90/92 backend tests pass (two pre-existing session-timer flakes, unrelated); client_app analyzer clean - requirement/phase5-xendit-plan.md is the canonical reference Stage 8 (live E2E) blocked on Xendit test-mode keys. The dashboard's single-webhook-URL constraint will be worked around via a self-poll script next session. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
192 lines
7.2 KiB
Dart
192 lines
7.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../../core/pairing/pairing_notifier.dart';
|
|
import '../../../core/theme/halo_tokens.dart';
|
|
import '../../../core/theme/widgets/widgets.dart';
|
|
import '../widgets/bestie_unavailable_dialog.dart';
|
|
|
|
/// Phase 4 Stage 5 — `SWaitingBestie` overlay.
|
|
///
|
|
/// Entry route: `/chat/waiting-targeted/:mitraId` — pushed from the chat
|
|
/// history "Curhat lagi" CTA after the targeted payment session is confirmed.
|
|
///
|
|
/// Three sub-states mapped from `pairingProvider`:
|
|
///
|
|
/// - `waiting` (PairingTargetedWaitingData) — orb + 20s countdown + cancel.
|
|
/// The countdown is purely cosmetic; the server owns the auto-reject timer.
|
|
/// - `accepted` (PairingBestieFoundData / PairingActiveData) — routes into
|
|
/// the chat screen immediately.
|
|
/// - `declined` (PairingTargetedUnavailableData) — shows the
|
|
/// [BestieOfflinePopup] returning variant; the popup may offer a
|
|
/// fallback-to-blast CTA when other besties are reachable.
|
|
class TargetedWaitingScreen extends ConsumerStatefulWidget {
|
|
final String mitraId;
|
|
const TargetedWaitingScreen({super.key, required this.mitraId});
|
|
|
|
@override
|
|
ConsumerState<TargetedWaitingScreen> createState() =>
|
|
_TargetedWaitingScreenState();
|
|
}
|
|
|
|
class _TargetedWaitingScreenState extends ConsumerState<TargetedWaitingScreen> {
|
|
bool _popupShown = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
ref.listenManual<PairingData>(pairingProvider, _onPairingState);
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
if (!mounted) return;
|
|
_onPairingState(null, ref.read(pairingProvider));
|
|
});
|
|
}
|
|
|
|
void _onPairingState(PairingData? prev, PairingData next) {
|
|
if (!mounted) return;
|
|
|
|
if (next is PairingBestieFoundData) {
|
|
context.go('/chat/session/${next.sessionId}', extra: next.mitraName);
|
|
return;
|
|
}
|
|
if (next is PairingActiveData) {
|
|
context.go('/chat/session/${next.sessionId}', extra: next.mitraName);
|
|
return;
|
|
}
|
|
if (next is PairingCancelledData) {
|
|
context.go('/home');
|
|
return;
|
|
}
|
|
if (next is PairingTargetedUnavailableData && !_popupShown) {
|
|
_popupShown = true;
|
|
// ignore: discarded_futures
|
|
BestieOfflinePopup.show(
|
|
context,
|
|
variant: BestieOfflineVariant.returning,
|
|
mitraName: next.mitraName,
|
|
paymentRequestId: next.paymentRequestId,
|
|
topicSensitivity: next.topicSensitivity,
|
|
).then((_) {
|
|
if (mounted) _popupShown = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final state = ref.watch(pairingProvider);
|
|
|
|
final waiting = state is PairingTargetedWaitingData ? state : null;
|
|
final mitraName = waiting?.mitraName ?? 'bestie';
|
|
final secondsRemaining = waiting?.secondsRemaining ?? 0;
|
|
|
|
return PopScope(
|
|
// Targeted-wait is reachable directly from chat history; per the
|
|
// deep-link pop-fallback rule (project memory), we drop the user
|
|
// back to home if they swipe back rather than into a stale stack.
|
|
canPop: false,
|
|
onPopInvokedWithResult: (didPop, _) {
|
|
if (didPop) return;
|
|
ref.read(pairingProvider.notifier).cancelSearch();
|
|
},
|
|
child: Scaffold(
|
|
backgroundColor: HaloTokens.bg,
|
|
body: SafeArea(
|
|
child: Padding(
|
|
padding: const EdgeInsets.fromLTRB(
|
|
HaloSpacing.s24,
|
|
HaloSpacing.s24,
|
|
HaloSpacing.s24,
|
|
HaloSpacing.s24,
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Expanded(
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
HaloOrb(
|
|
size: 120,
|
|
seed: mitraName.hashCode,
|
|
label: mitraName,
|
|
),
|
|
const SizedBox(height: HaloSpacing.s20),
|
|
const Text(
|
|
'◦ MENUNGGU JAWABAN ◦',
|
|
style: TextStyle(
|
|
fontFamily: HaloTokens.fontBody,
|
|
fontSize: 12,
|
|
fontWeight: FontWeight.w700,
|
|
letterSpacing: 1.6,
|
|
color: HaloTokens.brand,
|
|
),
|
|
),
|
|
const SizedBox(height: HaloSpacing.s8),
|
|
Text(
|
|
'lagi nungguin $mitraName',
|
|
textAlign: TextAlign.center,
|
|
style: const TextStyle(
|
|
fontFamily: HaloTokens.fontDisplay,
|
|
fontSize: 24,
|
|
height: 30 / 24,
|
|
fontWeight: FontWeight.w700,
|
|
color: HaloTokens.brandDark,
|
|
),
|
|
),
|
|
const SizedBox(height: HaloSpacing.s12),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: HaloSpacing.s16,
|
|
vertical: HaloSpacing.s8,
|
|
),
|
|
decoration: BoxDecoration(
|
|
color: HaloTokens.brandSofter,
|
|
borderRadius: BorderRadius.circular(999),
|
|
border: Border.all(color: HaloTokens.brandSoft),
|
|
),
|
|
child: Text(
|
|
'${secondsRemaining}d',
|
|
style: const TextStyle(
|
|
fontFamily: HaloTokens.fontDisplay,
|
|
fontSize: 22,
|
|
fontWeight: FontWeight.w700,
|
|
color: HaloTokens.brandDark,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(height: HaloSpacing.s12),
|
|
ConstrainedBox(
|
|
constraints: const BoxConstraints(maxWidth: 280),
|
|
child: const Text(
|
|
'kalau bestie nggak respon dalam 20 detik, kami bantu cariin yang lain.',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontFamily: HaloTokens.fontBody,
|
|
fontSize: 13,
|
|
height: 20 / 13,
|
|
color: HaloTokens.inkSoft,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
HaloButton(
|
|
label: 'batalkan',
|
|
variant: HaloButtonVariant.ghost,
|
|
fullWidth: true,
|
|
onPressed: () =>
|
|
ref.read(pairingProvider.notifier).cancelSearch(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|