Phase 4 Stage 3: payment shell (multi-screen flow)
Six new screens under /payment/* + a paymentDraftProvider holding
mode/durationId/durationMinutes/priceIDR/paymentId/isFirstSessionDiscount
across the flow. PaymentEntryScreen handles the routing decision
(eligible+enabled -> /payment/discount-paywall, else /payment/method-pick)
and clears the draft on fresh entry.
Screens:
- discount_paywall_screen: S6 first-session discount with struck-through
gimmick price + actual price + 'mulai · Rp{actual}' CTA -> /payment/method
- method_pick_screen: chat vs call cards
- duration_pick_screen: tier list with chat|call mode toggle that resets
the selection on swap
- payment_method_screen: QRIS-first list, posts to existing
/api/client/payment-sessions with mode/duration/price/discount/method
- waiting_payment_screen: qr_flutter QR (encodes paymentId in mock mode),
20-min countdown header, 3s polling for status, pauses on background
via WidgetsBindingObserver
- payment_expired_screen: retry CTA -> /payment/method with draft retained
Status mapping: real payment_sessions.status uses 'confirmed'/'consumed'
for paid (not 'paid' as in plan) and 'expired'/'abandoned' as terminal.
home_screen 'Mulai Curhat' CTA now pushes /payment/entry.
Dev-only /internal/_test/force-expire-payment endpoint to drive Maestro
flow 04_payment_expired.yaml without waiting 20 minutes. Gated behind
NODE_ENV !== 'production'.
chat_opening_provider PricingData extended to carry Phase 4 chat/call
groups + firstSessionDiscount, back-compat with the Phase 3 shape.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../../core/chat/chat_opening_provider.dart';
|
||||
import '../../../core/theme/halo_tokens.dart';
|
||||
import '../state/payment_draft_provider.dart';
|
||||
|
||||
/// Single point of truth for the discount-vs-method-pick branch.
|
||||
///
|
||||
/// Reads `chat-pricing.first_session_discount.eligible`. When the customer
|
||||
/// is eligible (and the discount is enabled), routes to the S6 paywall;
|
||||
/// otherwise routes to the regular method-pick screen. The draft is reset
|
||||
/// here so a fresh entry into the flow always starts clean.
|
||||
class PaymentEntryScreen extends ConsumerStatefulWidget {
|
||||
const PaymentEntryScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<PaymentEntryScreen> createState() => _PaymentEntryScreenState();
|
||||
}
|
||||
|
||||
class _PaymentEntryScreenState extends ConsumerState<PaymentEntryScreen> {
|
||||
bool _routed = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Future.microtask(() {
|
||||
if (!mounted) return;
|
||||
ref.read(paymentDraftNotifierProvider.notifier).reset();
|
||||
});
|
||||
}
|
||||
|
||||
void _routeOnce(String location) {
|
||||
if (_routed || !mounted) return;
|
||||
_routed = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
context.go(location);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final pricingAsync = ref.watch(chatPricingProvider);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: HaloTokens.bg,
|
||||
body: pricingAsync.when(
|
||||
loading: () => const Center(child: CircularProgressIndicator()),
|
||||
error: (_, __) {
|
||||
// Pricing fetch failed — fall through to method-pick (which fetches
|
||||
// pricing again and surfaces the error there).
|
||||
_routeOnce('/payment/method-pick');
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
data: (pricing) {
|
||||
if (pricing.firstSessionDiscount?.eligible ?? false) {
|
||||
_routeOnce('/payment/discount-paywall');
|
||||
} else {
|
||||
_routeOnce('/payment/method-pick');
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user