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

Stripe Checkout订阅模式带免费试用能否取消支付方式必填要求

解决方案

你可以在创建Checkout Session时添加参数实现支付方式非必填,免费试用场景下会自动隐藏该字段,具体操作如下:
在stripe.checkout.sessions.create的配置项中新增 payment_method_collection: 'if_required' 参数即可。
Stripe订阅模式的Checkout默认会始终要求用户填写支付方式,避免试用到期后自动扣款失败导致订阅中断。添加该参数后,只要当前订单没有即时需要支付的金额,支付方式字段就会自动取消必填、隐藏展示。

修改后的代码参考:

const freeTrial = {
    trial_from_plan:  realSubscription.id === 4 ? true : false
} 

if(customerStripeId != undefined || customerStripeId != null){
    const session = await stripe.checkout.sessions.create({
        mode: 'subscription',
        payment_method_types: ['card'],
        payment_method_collection: 'if_required', // 新增此行配置
        line_items: [
            {
                price: formData.monthlySetting === true ? realSubscription.monthly_price_id : realSubscription.annual_price_id,
                quantity: 1
            }
        ],
        customer: customerStripeId,
        success_url: `${BASE_URL}/success?session_id={CHECKOUT_SESSION_ID}`,
        cancel_url: BASE_URL,
        subscription_data: freeTrial
    })
    return {customerHasId: 'true', sessionData: session }
}else{
    return {customerHasId: 'false'}
}

注意事项:

  • 需确认你的订阅套餐试用期间无任何需要立即支付的费用,若存在首月折扣、开通服务费等即时收费项,支付方式字段仍会正常展示要求用户填写
  • 该配置仅对当前创建的Checkout Session生效,无需修改Stripe后台已配置的套餐规则

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 15:36:08