Phase 5.x payment revamp + Xendit Stage-8 prep

- Backend wraps idn-finlogos npm at /assets/payment-icons/<slug>.svg with
  1y immutable cache. Mobile drops bundled SVGs (only placeholder remains)
  and fetches via flutter_cache_manager. payment_methods.icon is now a
  CSV of slugs; catalog emits icon_urls[]. CARDS tile renders Visa + MC +
  JCB side by side.
- Per-method min/max amount bounds (BIGINT, nullable). Picker greys out
  out-of-range tiles with subtitle; backend gates with INVALID_PAYMENT_AMOUNT
  (422). Defense in depth against stale-catalog clients.
- Xendit channel codes corrected from authoritative docs
  (BCA_VA -> BCA_VIRTUAL_ACCOUNT, CREDIT_CARD -> CARDS, ovo -> ovo-new,
  shopeepay -> shopee-pay, ...). 18 methods x 5 groups seeded with
  Xendit-published per-channel min/max.
- Re-runnable seed (ON CONFLICT DO NOTHING on payment_code + new unique
  index on group name). Operator CC edits never clobbered across re-runs.
  One-shot reset + inspect scripts under backend/.dev/.
- Customer redirect HTML pages at /payment/return/{success,failure},
  brand-styled with "Buka HaloBestie" CTA firing halobestie:// deeplink.
  URL scheme registered on Android (intent-filter w/ BROWSABLE on
  MainActivity) and iOS (CFBundleURLTypes). Waiting-payment poller still
  owns confirmation; deeplink just brings the activity to foreground.
- Control center payment-catalog page: min/max inputs + columns. Other
  CC pages restyled with new theme tokens (separate work, bundled here).

169/169 backend tests pass. See requirement/phase5-payment-revamp-2026-05-27.md
for the full revamp doc. Stage 8 (E2E) still pending: webhook URL routing
decision + two client_app follow-ups (legacy /chat/request removal,
extension Custom Tab).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 21:33:51 +08:00
parent 1f6d8e09ae
commit 2c95fd040d
53 changed files with 2389 additions and 832 deletions

View File

@@ -2,18 +2,58 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/api/api_client_provider.dart';
/// One row in the payment-method catalog (server-side: `payment_methods`).
///
/// `iconUrls` is the backend-resolved list of brand-SVG URLs for this method.
/// Relative paths (e.g. `/assets/payment-icons/qris.svg`) are prepended with
/// `ApiClient.baseUrl` by [PaymentIcon]. Composite tiles (e.g. credit card
/// showing Visa + Mastercard + JCB) carry multiple entries. Empty list = no
/// icon configured → the row renders the bundled placeholder.
///
/// `minAmount` / `maxAmount` are inclusive Rupiah bounds, either nullable
/// (null = no bound). The picker greys out methods the current bill misses,
/// and the backend enforces the same bounds defensively with
/// `INVALID_PAYMENT_AMOUNT`.
class PaymentMethodEntry {
final String id;
final String paymentCode;
final String displayName;
final String? icon;
final List<String> iconUrls;
final int? minAmount;
final int? maxAmount;
const PaymentMethodEntry({
required this.id,
required this.paymentCode,
required this.displayName,
this.icon,
this.iconUrls = const [],
this.minAmount,
this.maxAmount,
});
/// `null` when the method is usable at [amount]; otherwise a short reason
/// suitable as a tile subtitle (Indonesian, brand voice).
String? disabledReason(int amount) {
if (minAmount != null && amount < minAmount!) {
return 'min ${_rp(minAmount!)}';
}
if (maxAmount != null && amount > maxAmount!) {
return 'maks ${_rp(maxAmount!)}';
}
return null;
}
}
String _rp(int n) {
// Rp 10.000 (Indonesian thousand-separator). Matches the picker's other
// amount formatting via `formatRupiah` in core/constants.dart, kept local
// to avoid pulling that dependency into the catalog model.
final s = n.toString();
final buf = StringBuffer('Rp ');
for (var i = 0; i < s.length; i++) {
if (i > 0 && (s.length - i) % 3 == 0) buf.write('.');
buf.write(s[i]);
}
return buf.toString();
}
/// One group in the payment-method catalog (server-side:
@@ -50,11 +90,13 @@ const _kFallbackGroup = PaymentMethodGroup(
id: 'fallback-paling-cepat',
name: 'Paling Cepat',
methods: [
// Fallback path renders the bundled placeholder (iconUrls empty) — the
// catalog endpoint being unreachable usually means the icon endpoint is
// too, so deferring to the placeholder is the safest signal.
PaymentMethodEntry(
id: 'fallback-qris',
paymentCode: 'QRIS',
displayName: 'QRIS',
icon: 'qris',
),
],
);
@@ -74,11 +116,14 @@ final paymentCatalogProvider = FutureProvider<PaymentCatalog>((ref) async {
final gm = g as Map<String, dynamic>;
final methods = (gm['methods'] as List<dynamic>? ?? const []).map((m) {
final mm = m as Map<String, dynamic>;
final iconUrlsRaw = mm['icon_urls'] as List<dynamic>? ?? const [];
return PaymentMethodEntry(
id: mm['id'] as String,
paymentCode: mm['payment_code'] as String,
displayName: mm['display_name'] as String,
icon: mm['icon'] as String?,
iconUrls: iconUrlsRaw.cast<String>(),
minAmount: (mm['min_amount'] as num?)?.toInt(),
maxAmount: (mm['max_amount'] as num?)?.toInt(),
);
}).toList(growable: false);
return PaymentMethodGroup(