feat: 增加ios支付&ui修改

This commit is contained in:
2025-12-09 05:51:32 -08:00
parent dc5a5fc78a
commit ca913eb38f
12 changed files with 463 additions and 365 deletions
@@ -842,17 +842,47 @@ 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 也被设置,如果需要保存卡片信息
final clientSecret = checkoutResponse.stripe?.clientSecret;
if (clientSecret == null || clientSecret.isEmpty) {
KRCommonUtil.kr_showToast('缺少支付凭证,请稍后重试');
return;
}
// 仅 iOS 使用 Apple Pay
if (!Platform.isIOS) {
KRCommonUtil.kr_showToast('Apple Pay 仅在 iOS 可用');
return;
}
print('Platform: ${Platform.operatingSystem} ${Platform.operatingSystemVersion}');
print('Merchant identifier: ${Stripe.merchantIdentifier}');
// 检查设备是否支持 Platform PayApple Pay
final supported = await Stripe.instance.isPlatformPaySupported();
if (!supported) {
KRCommonUtil.kr_showToast('当前设备或 Wallet 不支持 Apple Pay,请确认已添加可用卡');
return;
}
// 2. 创建确认支付的参数对象
final params = PlatformPayConfirmParams.applePay(
applePay: ApplePayParams(
merchantCountryCode: 'US',
currencyCode: 'USD',
cartItems: [
ApplePayCartSummaryItem.immediate(
label: 'Hi快VPN 服务',
amount: kr_getPlanPrice(
kr_plans[kr_selectedPlanIndex.value],
).toStringAsFixed(2),
),
],
),
);
// B. 显示支付表单给用户
await Stripe.instance.presentPaymentSheet();
// 🚀 3. 调用方法,直接启动 Apple Pay 原生界面
await Stripe.instance.confirmPlatformPayPaymentIntent(
clientSecret: clientSecret,
confirmParams: params,
);
// C. 支付成功
print('✅ Stripe 支付成功!');