You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS Obj-C应用Stripe Payment Links自动设置数量方案咨询

解决方案:Stripe 自动设置活动报名数量(无需用户手动调整)

虽然Payment Links后台无法直接固定数量,但可以通过URL动态参数预设值,用户打开链接时会直接看到你指定的数量(若需限制修改,可在服务器端做最终校验):

  • 先在Stripe后台创建Payment Link时开启「允许用户修改数量」(后续通过URL覆盖默认值)
  • iOS端拼接数量参数到Payment Link末尾,直接打开即可

Obj-C 代码示例:

// 你的基础Payment Link地址
NSString *baseLink = @"https://buy.stripe.com/xxx";
// 预设的报名数量
NSInteger targetQuantity = 3;
// 拼接数量参数
NSString *finalPaymentLink = [NSString stringWithFormat:@"%@?quantity=%ld", baseLink, (long)targetQuantity];

// 用Safari打开链接
SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:finalPaymentLink]];
[self presentViewController:safariVC animated:YES completion:nil];

补充校验:服务器端监听Stripe支付成功的Webhook事件,核对实际支付数量是否与预设值一致,不一致则拒绝更新报名状态。

方案2:使用Stripe Checkout Session(完全控制数量)

这是更灵活的方式,通过服务器端生成Checkout Session,直接指定数量,用户无法修改:

  1. 服务器端操作:
    创建Checkout Session时,在line_items数组中明确设置quantity为目标值,且不开启allow_modification(默认关闭),生成后将Session的url返回给iOS客户端。
  2. iOS端打开Session链接:
// 从服务器获取的Checkout Session地址
NSString *sessionURL = @"https://checkout.stripe.com/pay/cs_test_xxx";
SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:sessionURL]];
safariVC.delegate = self;
[self presentViewController:safariVC animated:YES completion:nil];
  1. 支付结果校验:服务器通过checkout.session.completed Webhook事件确认支付成功,更新用户报名状态。

方案3:自定义支付UI(使用Payment Intents)

如果需要完全自定义APP内支付界面,无需跳转网页,可使用Payment Intents API:

  • 服务器端根据报名数量×单价计算总金额,创建Payment Intent并返回client_secret给客户端
  • iOS端用Stripe SDK收集支付信息,完成支付

Obj-C 代码示例(客户端部分):

#import <Stripe/Stripe.h>

// 从服务器获取的Payment Intent Client Secret
NSString *clientSecret = @"pi_test_xxx_secret_xxx";

STPPaymentConfiguration *config = [STPPaymentConfiguration sharedConfiguration];
STPPaymentIntentParams *params = [[STPPaymentIntentParams alloc] initWithClientSecret:clientSecret];

STPPaymentHandler *handler = [[STPPaymentHandler alloc] initWithPaymentConfiguration:config apiAdapter:[STPAPIClient sharedClient]];
[handler confirmPaymentParams:params withAuthenticationContext:self completion:^(STPPaymentHandlerActionStatus status, STPPaymentIntent * _Nullable intent, NSError * _Nullable error) {
    if (status == STPPaymentHandlerActionStatusSucceeded) {
        // 支付成功,通知服务器更新报名记录
    } else if (status == STPPaymentHandlerActionStatusFailed) {
        // 提示用户支付失败
    }
}];

核心注意事项

  • 所有涉及数量、金额的逻辑,必须在服务器端做最终验证,不能仅依赖客户端传入的值,防止恶意篡改
  • 保持Stripe iOS SDK为最新版本,避免兼容性问题

内容的提问来源于stack exchange,提问作者user717452

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 17:50:08