Files
wangjia 252779c607
ci-pangolin / Redline Scan — 脱敏 (UI 文案) (pull_request) Successful in 24s
ci-pangolin / Cleartext Scan — Android 禁明文 (pull_request) Successful in 19s
ci-pangolin / OpenAPI Sync Check (pull_request) Successful in 45s
ci-pangolin / Portable SQL — 可移植性 (mysql/sqlite) (pull_request) Successful in 20s
ci-pangolin / Flutter — analyze + test (pull_request) Successful in 37s
ci-pangolin / Codegen Drift — token 生成物未漂移 (pull_request) Successful in 3s
ci-pangolin / DS-flow — 原型/跨端同源/代码色单源闸 (pull_request) Successful in 4s
ci-pangolin / Go — build + test (pull_request) Failing after 15s
ci-pangolin / E2E Smoke — L4 进程级端到端 (pull_request) Failing after 10s
ci-pangolin / Go — integration (mysql/redis testcontainers) (pull_request) Successful in 4m41s
ci-pangolin / Golden — 视觉回归 (全量:components/auth/desktop/tablet) (pull_request) Failing after 20s
ci-pangolin / Lint — shellcheck (pull_request) Failing after 12m35s
fix(client/pay): CNY 渠道 method 对齐生产哪吒(nezha)+ 下单失败不再静默
根因(购买按钮全端「点了没反应」):
- 生产 pay-v2 的 CNY 渠道是哪吒(nezha)聚合(底层支付宝/微信),客户端却给
  CNY 发 method=alipay → pay 不认 → POST /api/v2/orders 400。USDT/crypto 一直正常。
- 且 _buy 只在 awaitingPayment 时导航,下单失败(phase=failed)既不导航也不弹错,
  非 Auth 异常还直接从 start() 抛出未捕获 → 用户看着「没反应」。

改:
- PayChannelX.method:cny 'alipay' → 'nezha'(usdt 仍 crypto)
- payment_provider._metadata 法币条件同步 nezha;start() 补 catch(_) 兜非 Auth 异常
  落 failed(状态机不再卡 creating)
- purchase_page._buy:phase==failed 时 showPangolinToast 显式提示
- payment_page 换支付方式的另一渠道 alipay → nezha
- 测试钉:PayChannel.cny.method == 'nezha'(发错 method 会被 pay 400)

nezha 返回 render_type=redirect(payload.url),客户端现成 redirect 分支直接接;
orders_page 早有 'nezha'→payMethodNezha 标签。服务端无需改(method 透传、
SettlementCurrency 只区分 crypto vs 法币)。

验证:flutter analyze 干净;payment 相关 18 测试全过。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-12 22:09:31 +08:00

158 lines
5.8 KiB
Dart

// payment.dart — pay v2 支付领域模型(server 代理端点的响应形状)。
// 金额只读展示:price_minor 为 CNY 分;crypto 精确金额在 session.payload 里。
/// 支付渠道:结算币种即支付方式(一步定)。usdt→加密货币 / cny→支付宝。
/// 各币种一口价(不做实时汇率换算);实际扣款以 pay 侧为准。
enum PayChannel { usdt, cny }
extension PayChannelX on PayChannel {
String get currency => this == PayChannel.usdt ? 'USDT' : 'CNY';
// CNY 渠道生产走哪吒(nezha)聚合(底层支付宝/微信),非直连 alipay 商户。
String get method => this == PayChannel.usdt ? 'crypto' : 'nezha';
}
class PayCatalogItem {
const PayCatalogItem({
required this.sku,
required this.plan,
required this.days,
required this.priceMinor,
required this.currency,
this.priceUsdtMicro = 0,
this.promo = false,
});
final String sku;
final String plan;
final int days;
final int priceMinor; // CNY 分(展示)
final String currency; // CNY
final int priceUsdtMicro; // USDT 微元(展示;各币种一口价)
final bool promo; // 全员可见的限时优惠档(如 pro_month_promo)
factory PayCatalogItem.fromJson(Map<String, dynamic> j) => PayCatalogItem(
sku: j['sku'] as String,
plan: j['plan'] as String? ?? 'pro',
days: (j['days'] as num?)?.toInt() ?? 0,
priceMinor: (j['price_minor'] as num?)?.toInt() ?? 0,
currency: j['currency'] as String? ?? 'CNY',
priceUsdtMicro: (j['price_usdt_micro'] as num?)?.toInt() ?? 0,
promo: j['promo'] as bool? ?? false,
);
/// 约当月数(31→1 / 92→3 / 366→12),用于每月折算展示。
int get months {
final m = (days / 30.4).round();
return m < 1 ? 1 : m;
}
/// 按渠道币种给总价文案(USDT $ / CNY ¥)。
String priceLabel(PayChannel ch) => ch == PayChannel.usdt
? '\$${(priceUsdtMicro / 1000000).toStringAsFixed(2)}'
: '¥${(priceMinor / 100).toStringAsFixed(2)}';
/// 按渠道币种给每月折算文案(不含 /月 后缀,后缀由 l10n 提供)。
String perMonthLabel(PayChannel ch) => ch == PayChannel.usdt
? '\$${(priceUsdtMicro / 1000000 / months).toStringAsFixed(2)}'
: '¥${(priceMinor / 100 / months).toStringAsFixed(2)}';
}
/// PayOrderSummary — 订单列表项(server orderView 台账视图)。
/// 金额为结算币种 minor:CNY 分 / USDT 微元。
class PayOrderSummary {
const PayOrderSummary({
required this.orderNo,
required this.sku,
required this.plan,
required this.days,
required this.method,
required this.status,
required this.amountMinor,
required this.currency,
required this.createdAt,
this.paidAt,
});
final String orderNo;
final String sku;
final String plan;
final int days;
final String method; // crypto | alipay | nezha …
final String status; // created | paid | canceled(本地台账)
final int amountMinor;
final String currency; // CNY | USDT
final DateTime? createdAt;
final DateTime? paidAt;
factory PayOrderSummary.fromJson(Map<String, dynamic> j) => PayOrderSummary(
orderNo: j['order_no'] as String? ?? '',
sku: j['sku'] as String? ?? '',
plan: j['plan'] as String? ?? 'pro',
days: (j['days'] as num?)?.toInt() ?? 0,
method: j['method'] as String? ?? '',
status: j['status'] as String? ?? '',
amountMinor: (j['amount_minor'] as num?)?.toInt() ?? 0,
currency: j['currency'] as String? ?? 'CNY',
createdAt: j['created_at'] == null ? null : DateTime.tryParse(j['created_at'] as String),
paidAt: j['paid_at'] == null ? null : DateTime.tryParse(j['paid_at'] as String),
);
/// 结算币种金额文案(USDT 6 位、CNY 2 位)。
String amountLabel() => currency == 'USDT'
? '\$${(amountMinor / 1000000).toStringAsFixed(2)}'
: '¥${(amountMinor / 100).toStringAsFixed(2)}';
}
class PaySession {
const PaySession({required this.renderType, required this.payload, this.expiresAt});
final String renderType; // crypto_address | redirect | qr
final Map<String, dynamic> payload;
final DateTime? expiresAt;
factory PaySession.fromJson(Map<String, dynamic> j) => PaySession(
renderType: j['render_type'] as String? ?? '',
payload: (j['payload'] as Map<String, dynamic>?) ?? const {},
expiresAt: j['expires_at'] == null ? null : DateTime.tryParse(j['expires_at'] as String),
);
}
class PayOrder {
const PayOrder({required this.orderNo, required this.session});
final String orderNo;
final PaySession session;
factory PayOrder.fromJson(Map<String, dynamic> j) => PayOrder(
orderNo: j['order_no'] as String,
session: PaySession.fromJson((j['session'] as Map<String, dynamic>?) ?? const {}),
);
}
/// PayOrderStatus — 查单/详情响应。轮询只用 activated;订单详情页额外用
/// 台账富字段(server GetOrder 现回带 orderView 全字段)。
class PayOrderStatus {
const PayOrderStatus({
required this.orderNo,
required this.payStatus,
required this.activated,
this.expiresAt,
this.summary,
});
final String orderNo;
final String payStatus;
final bool activated; // server 台账已消费 = 权益已开通(轮询成功判据)
final DateTime? expiresAt;
final PayOrderSummary? summary; // 台账富字段(sku/plan/method/金额/时间…);详情页用
factory PayOrderStatus.fromJson(Map<String, dynamic> j) => PayOrderStatus(
orderNo: j['order_no'] as String? ?? '',
payStatus: j['pay_status'] as String? ?? '',
activated: j['activated'] as bool? ?? false,
expiresAt: j['expires_at'] == null ? null : DateTime.tryParse(j['expires_at'] as String),
// 详情端点回带台账字段(列表端点同形);sku 存在才解析。
summary: j['sku'] == null ? null : PayOrderSummary.fromJson(j),
);
}