feat: 增加ios支付
This commit is contained in:
@@ -203,7 +203,7 @@ class KRLoginView extends GetView<KRLoginController> {
|
||||
controller: controller.accountController,
|
||||
hintText: 'Email',
|
||||
),
|
||||
SizedBox(height: 10.w),
|
||||
SizedBox(height: 10),
|
||||
_buildStandardInputField(
|
||||
controller: controller.psdController,
|
||||
hintText: '密码',
|
||||
@@ -226,7 +226,7 @@ class KRLoginView extends GetView<KRLoginController> {
|
||||
bool isPassword = false,
|
||||
}) {
|
||||
return SizedBox(
|
||||
height: 50, // 固定高度
|
||||
// height: 50, // 固定高度
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
obscureText: isPassword,
|
||||
|
||||
+60
-9
@@ -17,6 +17,7 @@ import '../../../services/api_service/kr_api.user.dart';
|
||||
import '../../../utils/kr_event_bus.dart';
|
||||
import '../../../network/http_util.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_stripe/flutter_stripe.dart';
|
||||
|
||||
/// 会员购买控制器
|
||||
/// 负责处理会员套餐选择、支付方式选择和订阅流程
|
||||
@@ -460,18 +461,54 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
|
||||
/// 处理购买和结账流程
|
||||
Future<void> kr_processPurchaseAndCheckout() async {
|
||||
|
||||
final selectedPlan = kr_plans[kr_selectedPlanIndex.value];
|
||||
// =========================================================================
|
||||
// 🔽 支付方式选择优化:iOS 优先使用 Stripe 🔽
|
||||
// =========================================================================
|
||||
final isIOS = Platform.isIOS;
|
||||
|
||||
// ⚠️ 支付方式接口暂未实现,使用默认支付方式 ID (1) 和平台 'alipay'
|
||||
final paymentMethodId = kr_paymentMethods.isNotEmpty && kr_selectedPaymentMethodIndex.value >= 0
|
||||
? kr_paymentMethods[kr_selectedPaymentMethodIndex.value].id
|
||||
: 1;
|
||||
final paymentPlatform = kr_paymentMethods.isNotEmpty && kr_selectedPaymentMethodIndex.value >= 0
|
||||
? kr_paymentMethods[kr_selectedPaymentMethodIndex.value].platform
|
||||
: 'alipay';
|
||||
// 1. 初始化为默认回退值
|
||||
int finalPaymentMethodId = 1;
|
||||
String finalPaymentPlatform = 'alipay';
|
||||
|
||||
// 获取选中的数量
|
||||
if (kr_paymentMethods.isNotEmpty) {
|
||||
// 检查是否有用户已选中且索引有效
|
||||
final bool isIndexValid = kr_selectedPaymentMethodIndex.value >= 0 &&
|
||||
kr_selectedPaymentMethodIndex.value < kr_paymentMethods.length;
|
||||
|
||||
if (isIOS) {
|
||||
// 2. iOS 专属:查找 'stripe'
|
||||
final stripeMethod = kr_paymentMethods.firstWhere(
|
||||
(method) => method.platform == 'Stripe',
|
||||
);
|
||||
|
||||
if (stripeMethod != null) {
|
||||
// 找到了 Stripe,使用它
|
||||
finalPaymentMethodId = stripeMethod.id;
|
||||
finalPaymentPlatform = stripeMethod.platform;
|
||||
} else if (isIndexValid) {
|
||||
// 找不到 Stripe,但用户有选中,使用选中的方式
|
||||
finalPaymentMethodId =
|
||||
kr_paymentMethods[kr_selectedPaymentMethodIndex.value].id;
|
||||
finalPaymentPlatform =
|
||||
kr_paymentMethods[kr_selectedPaymentMethodIndex.value].platform;
|
||||
}
|
||||
} else {
|
||||
// 3. 非 iOS 环境:如果用户有选中,使用选中的方式
|
||||
if (isIndexValid) {
|
||||
finalPaymentMethodId =
|
||||
kr_paymentMethods[kr_selectedPaymentMethodIndex.value].id;
|
||||
finalPaymentPlatform =
|
||||
kr_paymentMethods[kr_selectedPaymentMethodIndex.value].platform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final paymentMethodId = finalPaymentMethodId;
|
||||
final paymentPlatform = finalPaymentPlatform;
|
||||
// =========================================================================
|
||||
// 🔼 支付方式选择优化结束 🔼
|
||||
// =========================================================================
|
||||
final quantity = kr_getSelectedQuantity();
|
||||
|
||||
// 判断是续订还是新购
|
||||
@@ -805,6 +842,20 @@ class KRPurchaseMembershipController extends GetxController {
|
||||
print(' Stripe Client Secret: ${checkoutResponse.stripe?.clientSecret}');
|
||||
print('💳 显示 Stripe 支付表单...');
|
||||
print('═══════════════════════════════════════');
|
||||
await Stripe.instance.initPaymentSheet(
|
||||
paymentSheetParameters: SetupPaymentSheetParameters(
|
||||
// ⚠️ Stripe SDK 必须在 main() 中初始化过 publishableKey
|
||||
paymentIntentClientSecret: checkoutResponse.stripe?.clientSecret,
|
||||
merchantDisplayName: 'Hi快VPN',
|
||||
// 确保 customerId 和 ephemeralKeySecret 也被设置,如果需要保存卡片信息
|
||||
),
|
||||
);
|
||||
|
||||
// B. 显示支付表单给用户
|
||||
await Stripe.instance.presentPaymentSheet();
|
||||
|
||||
// C. 支付成功
|
||||
print('✅ Stripe 支付成功!');
|
||||
|
||||
Get.toNamed(
|
||||
Routes.KR_ORDER_STATUS,
|
||||
|
||||
Reference in New Issue
Block a user