feat: 实现 iOS Apple Pay 内购支付功能
前端: - 集成 in_app_purchase 插件,实现 IAP 支付流程 - 添加支付模块 (payments/) 处理产品获取、购买、验证 - 积分中心页面集成 Apple Pay 购买入口 - 设置页面重构: 关于/隐私/协议直接展示,删除 legal_center 子页面 - 修复欢迎引导页滚动检测阈值问题 - 修复解卦结果页 iOS 侧滑返回手势被阻止的问题 - 邀请码绑定按钮临时禁用(待后端实现) 后端: - 新增 apple_iap_transactions 表记录交易 - 实现 Apple 服务器端验证 (App Store Server API) - 支付成功后自动发放积分 - 支持 Sandbox/Production 环境切换 - 添加退款处理和交易状态机 协议: - 更新积分流水协议,支持 purchase/refund 类型 - 新增 PAYMENT_* 错误码
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meeyao_qianwen/features/payments/data/models/apple_purchase_models.dart';
|
||||
|
||||
void main() {
|
||||
group('VerifyTransactionRequest', () {
|
||||
test('toJson includes all required fields', () {
|
||||
const request = VerifyTransactionRequest(
|
||||
productCode: 'basic_pack',
|
||||
appStoreProductId: 'com.meeyao.qianwen.basic_pack',
|
||||
transactionId: '1000000123456789',
|
||||
signedTransactionInfo: 'eyJhbGciOiJFUzI1NiIs...',
|
||||
);
|
||||
|
||||
final json = request.toJson();
|
||||
|
||||
expect(json['productCode'], 'basic_pack');
|
||||
expect(json['appStoreProductId'], 'com.meeyao.qianwen.basic_pack');
|
||||
expect(json['transactionId'], '1000000123456789');
|
||||
expect(json['signedTransactionInfo'], 'eyJhbGciOiJFUzI1NiIs...');
|
||||
expect(json.containsKey('appAccountToken'), false);
|
||||
});
|
||||
|
||||
test('toJson includes appAccountToken when provided', () {
|
||||
const request = VerifyTransactionRequest(
|
||||
productCode: 'basic_pack',
|
||||
appStoreProductId: 'com.meeyao.qianwen.basic_pack',
|
||||
transactionId: '1000000123456789',
|
||||
signedTransactionInfo: 'eyJhbGciOiJFUzI1NiIs...',
|
||||
appAccountToken: 'abc123def456',
|
||||
);
|
||||
|
||||
final json = request.toJson();
|
||||
|
||||
expect(json['appAccountToken'], 'abc123def456');
|
||||
});
|
||||
});
|
||||
|
||||
group('VerifyTransactionResponse', () {
|
||||
test('parses granted status correctly', () {
|
||||
final json = {
|
||||
'status': 'granted',
|
||||
'productCode': 'basic_pack',
|
||||
'transactionId': '1000000123456789',
|
||||
'creditsAdded': 100,
|
||||
'newBalance': 180,
|
||||
'ledgerEventId': 'payment.apple_iap:1000000123456789',
|
||||
};
|
||||
|
||||
final response = VerifyTransactionResponse.fromJson(json);
|
||||
|
||||
expect(response.status, VerifyTransactionStatus.granted);
|
||||
expect(response.productCode, 'basic_pack');
|
||||
expect(response.transactionId, '1000000123456789');
|
||||
expect(response.creditsAdded, 100);
|
||||
expect(response.newBalance, 180);
|
||||
expect(response.ledgerEventId, 'payment.apple_iap:1000000123456789');
|
||||
});
|
||||
|
||||
test('parses already_granted status correctly', () {
|
||||
final json = {
|
||||
'status': 'already_granted',
|
||||
'productCode': 'basic_pack',
|
||||
'transactionId': '1000000123456789',
|
||||
'creditsAdded': 0,
|
||||
'newBalance': 180,
|
||||
'ledgerEventId': 'payment.apple_iap:1000000123456789',
|
||||
};
|
||||
|
||||
final response = VerifyTransactionResponse.fromJson(json);
|
||||
|
||||
expect(response.status, VerifyTransactionStatus.alreadyGranted);
|
||||
expect(response.creditsAdded, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user