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

能否在Stripe中延迟X天扣款?非免费试用方案及Portal操作咨询

Stripe延迟扣款(非免费试用)实现方案

一、核心功能实现逻辑

完全可以实现需求:留存用户支付方式,待团队确认后再触发扣款,且该等待时段不标记为免费试用。核心是不使用Stripe的免费试用功能,通过「预存支付方式 + 延迟创建/激活订阅」的方式实现。

方式1:先留存支付方式,确认后创建订阅

  • 第一步:收集用户支付方式并关联到Stripe Customer
    使用Stripe Checkout的setup_mode: 'setup'模式,或SetupIntent API,引导用户完成支付方式验证,将支付方式绑定到Customer对象,此时不会产生任何扣款。
    示例代码(Node.js):
    const stripe = require('stripe')('your_secret_key');
    const setupIntent = await stripe.setupIntents.create({
      customer: 'cus_XXX',
      payment_method_types: ['card'],
      setup_future_usage: 'off_session' // 支持后续自动扣款
    });
    
  • 第二步:团队确认后创建订阅并扣款
    确认合作后,基于已绑定的Customer和支付方式创建订阅,设置首次计费日期为确认当天(或按需调整),Stripe会自动发起扣款。
    示例代码:
    const subscription = await stripe.subscriptions.create({
      customer: 'cus_XXX',
      items: [{ price: 'price_XXX' }],
      default_payment_method: 'pm_XXX', // 已留存的支付方式ID
      payment_behavior: 'default_incomplete', // 扣款失败可后续重试
      billing_cycle_anchor: Math.floor(Date.now() / 1000) // 首次计费时间设为当前时间
    });
    

方式2:创建待确认的订阅,延迟扣款

如果需要在用户订阅时就生成订阅记录,但暂不扣款:

  • 创建订阅时设置payment_behavior: 'default_incomplete',同时通过billing_cycle_anchor将首次计费日期设为2周后(或团队确认后的日期),此时订阅处于incomplete状态,不会立即扣款。
  • 团队确认后,调用stripe.subscriptions.confirm()方法确认订阅,Stripe会在billing_cycle_anchor指定日期发起扣款;若需立即扣款,可修改billing_cycle_anchor为当前时间后再确认。

二、Stripe Portal实现步骤

该功能可通过Stripe Customer Portal实现,具体操作如下:

  1. 配置Customer Portal设置
    • 登录Stripe Dashboard,进入「设置」→「客户门户」
    • 在「订阅管理」中开启「允许客户添加/更新支付方式」权限
    • 关闭「免费试用」相关显示选项,避免用户误解
  2. 生成Portal会话(供用户留存支付方式)
    用户申请订阅时,通过API生成Customer Portal会话,引导用户进入Portal添加支付方式:
    const session = await stripe.billingPortal.sessions.create({
      customer: 'cus_XXX',
      return_url: 'https://your-domain.com/confirmation',
      flow_data: {
        type: 'setup',
        setup: {
          payment_method_types: ['card'],
          setup_future_usage: 'off_session'
        }
      }
    });
    
    将生成的url返回给用户,用户完成支付方式绑定。
  3. 团队确认后触发扣款
    确认合作后,可在Stripe Dashboard中找到对应Customer,手动创建订阅并选择已留存的支付方式,设置首次计费日期为当前时间,Stripe会自动发起扣款;批量场景也可通过API批量处理。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 01:10:21