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

@stripe/stripe-react-native PaymentSheet无法显示「保存支付方式」复选框

问题解决方法

要让PaymentSheet显示「保存支付方式」复选框,核心是在创建PaymentIntent时明确配置setup_future_usage字段,以下是具体步骤:

  • 修改后端PaymentIntent创建逻辑
    你当前的代码没有设置setup_future_usage,Stripe默认不会触发保存支付方式的选项。需要在创建PaymentIntent时添加该字段,值设为on_session(允许用户在当前支付会话中选择保存支付方式):

    try {
        const theReqBody = JSON.parse(request.body);
        const paymentIntent = await stripeClient.paymentIntents.create({
            amount: theReqBody.amount * 100,  // pennies
            customer: theReqBody.customerId, // cus_xxx
            currency: 'usd',
            automatic_payment_methods: {
                enabled: true
            },
            setup_future_usage: 'on_session' // 新增配置
        });
        response.json({paymentIntent: paymentIntent.client_secret});
    } catch (e) {
        response.status(400).json({
            error: e.message
        })
    }
    
  • 验证前端配置完整性
    确保前端传入的customerId和customerEphemeralKeySecret是有效的、对应同一个Stripe客户对象。这两个参数是将支付方式关联到客户名下的必要条件,缺少或错误会导致保存选项无法正常显示。

  • 确认PaymentIntent返回值
    修改后,返回的PaymentIntent中setup_future_usage字段应该显示为on_session,而非之前的null。

补充说明:你看到的“不要启用setup_future_usage”的说法可能是指避免强制保存(无需用户确认就自动保存),但实际上要显示复选框,必须主动设置该字段为on_session,让用户自主选择是否保存。

内容的提问来源于stack exchange,提问作者Janelle Thorn Contreras

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 23:55:29