87f92987b2
前端: - 集成 in_app_purchase 插件,实现 IAP 支付流程 - 添加支付模块 (payments/) 处理产品获取、购买、验证 - 积分中心页面集成 Apple Pay 购买入口 - 设置页面重构: 关于/隐私/协议直接展示,删除 legal_center 子页面 - 修复欢迎引导页滚动检测阈值问题 - 修复解卦结果页 iOS 侧滑返回手势被阻止的问题 - 邀请码绑定按钮临时禁用(待后端实现) 后端: - 新增 apple_iap_transactions 表记录交易 - 实现 Apple 服务器端验证 (App Store Server API) - 支付成功后自动发放积分 - 支持 Sandbox/Production 环境切换 - 添加退款处理和交易状态机 协议: - 更新积分流水协议,支持 purchase/refund 类型 - 新增 PAYMENT_* 错误码
75 lines
2.1 KiB
Dart
75 lines
2.1 KiB
Dart
enum ProductCode { newUserPack, basicPack, popularPack, premiumPack }
|
|
|
|
enum PackageType { starter, regular }
|
|
|
|
class PackageInfo {
|
|
const PackageInfo({
|
|
required this.productCode,
|
|
required this.appStoreProductId,
|
|
required this.type,
|
|
required this.price,
|
|
required this.credits,
|
|
required this.isStarter,
|
|
required this.starterEligible,
|
|
required this.sortOrder,
|
|
});
|
|
|
|
final ProductCode productCode;
|
|
final String appStoreProductId;
|
|
final PackageType type;
|
|
final double price;
|
|
final int credits;
|
|
final bool isStarter;
|
|
final bool starterEligible;
|
|
final int sortOrder;
|
|
|
|
factory PackageInfo.fromJson(Map<String, dynamic> json) {
|
|
return PackageInfo(
|
|
productCode: _parseProductCode(json['productCode'] as String),
|
|
appStoreProductId: json['appStoreProductId'] as String,
|
|
type: json['type'] == 'starter'
|
|
? PackageType.starter
|
|
: PackageType.regular,
|
|
price: (json['price'] as num).toDouble(),
|
|
credits: json['credits'] as int,
|
|
isStarter: json['isStarter'] as bool,
|
|
starterEligible: json['starterEligible'] as bool,
|
|
sortOrder: json['sortOrder'] as int,
|
|
);
|
|
}
|
|
|
|
static ProductCode _parseProductCode(String code) {
|
|
return switch (code) {
|
|
'new_user_pack' => ProductCode.newUserPack,
|
|
'basic_pack' => ProductCode.basicPack,
|
|
'popular_pack' => ProductCode.popularPack,
|
|
'premium_pack' => ProductCode.premiumPack,
|
|
_ => throw ArgumentError('Unknown product code: $code'),
|
|
};
|
|
}
|
|
|
|
String get priceDisplay => '\$${price.toStringAsFixed(2)}';
|
|
}
|
|
|
|
class PackagesResult {
|
|
const PackagesResult({
|
|
required this.region,
|
|
required this.currency,
|
|
required this.packages,
|
|
});
|
|
|
|
final String region;
|
|
final String currency;
|
|
final List<PackageInfo> packages;
|
|
|
|
factory PackagesResult.fromJson(Map<String, dynamic> json) {
|
|
return PackagesResult(
|
|
region: json['region'] as String,
|
|
currency: json['currency'] as String,
|
|
packages: (json['packages'] as List<dynamic>)
|
|
.map((e) => PackageInfo.fromJson(e as Map<String, dynamic>))
|
|
.toList(),
|
|
);
|
|
}
|
|
}
|