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

ASP.NET中Stripe 5.3.0.0自定义订阅账单日期更新问题求助

如何修改Stripe订阅的自定义账单日期?

你尝试通过StripeSubscriptionUpdateOptions修改订阅账单日期为自定义日期时,直接给BillingCycleAnchor传自定义日期会触发错误:

"When updating an existing subscription, billing_cycle_anchor must be either unset, 'now', or 'unchanged'"

之后你设置BillingCycleAnchorNow = true,结果账单日期被改为操作日加30天(2024年4月1日操作变为5月1日),需要实现自定义日期的修改。

你尝试的代码:

public int newSPayment()
{
   int issuccess = 0;
   var service = new 
   StripeSubscriptionService(ConfigurationManager.AppSettings["StripeApiSecretKey"]);
   DateTime newNextBillingDate = DateTime.UtcNow.AddDays(5);
   var subscriptionId = "sub_1OwGLfCKifPDqZIAQib3UnBL";
   var cusID = "cus_PjzMQRteo1FhAQ";
   var updateOptions = new StripeSubscriptionUpdateOptions
   {               
      BillingCycleAnchor = newNextBillingDate,                
      BillingCycleAnchorUnchanged = true,
      BillingCycleAnchorNow = true,                
    };
    var updatedSubscription = service.Update(cusID,subscriptionId, updateOptions);
}

解决方法

Stripe更新现有订阅时,确实不允许直接设置BillingCycleAnchor为自定义日期,要实现自定义账单日期,需要通过**订阅计划(Subscription Schedule)**来操作,具体步骤如下:

  1. 使用StripeSubscriptionScheduleService创建或更新订阅计划,将自定义日期设置为计划的StartDate,并关联到目标订阅。
  2. 设置合适的ProrationBehavior避免不必要的按比例计费(比如设置为none)。

修正后的代码示例:

public int UpdateSubscriptionBillingDate()
{
    int issuccess = 0;
    var apiKey = ConfigurationManager.AppSettings["StripeApiSecretKey"];
    var subscriptionId = "sub_1OwGLfCKifPDqZIAQib3UnBL";
    // 自定义账单日期(必须为UTC时间)
    DateTime customBillingDate = DateTime.UtcNow.AddDays(5);

    try
    {
        var scheduleService = new StripeSubscriptionScheduleService(apiKey);
        var scheduleOptions = new StripeSubscriptionScheduleCreateOptions
        {
            FromSubscription = subscriptionId,
            StartDate = customBillingDate,
            ProrationBehavior = "none" // 避免生成按比例计费账单,可根据业务需求调整
        };

        var schedule = scheduleService.Create(scheduleOptions);
        issuccess = 1;
    }
    catch (StripeException ex)
    {
        // 捕获并处理Stripe返回的错误
        issuccess = 0;
    }

    return issuccess;
}

关键说明

  • FromSubscription:指定要关联的现有订阅,Stripe会基于该订阅的配置创建新的计划,并替换原有订阅的计费周期规则。
  • StartDate:设置为你需要的自定义账单日期(UTC格式),该日期会成为新的计费周期锚点。
  • ProrationBehavior:根据业务需求选择,none表示不生成按比例计费账单,不会立即扣费;如果需要按实际使用时长计费,可设置为create_prorations。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 17:03:32