代码之家  ›  专栏  ›  技术社区  ›  Tez Wingfield

使用条带签出API(C#)设置订阅结束日期

  •  0
  • Tez Wingfield  · 技术社区  · 2 年前

    希望标题能描述这个问题,但我会给出更多的上下文。

    所以,我有两个价格计划的测试应用程序:一次性付款(效果很好)和订阅。

    该服务的性质只需要订阅12个月。虽然我可以创建订阅,但我不能使用checkout api设置订阅的结束日期?

    下面是一段代码:

            var baseUrl = $"{_configuration["BaseURL"]}";
            var options = new SessionCreateOptions
            {
                Mode = "subscription",
                SuccessUrl = $"{baseUrl}/payment/success/?session_id=" + "{CHECKOUT_SESSION_ID}",
                CancelUrl = $"{baseUrl}/payment/cancelled",
                CustomerEmail = customerEmail,
                LineItems = new List<SessionLineItemOptions>()
            };
            var sessionLineItem = new SessionLineItemOptions
            {
                Quantity = 1,
                PriceData = new SessionLineItemPriceDataOptions()
                {
                    UnitAmount = (long)19.99 * 100,
                    Currency = "gbp",
                    ProductData = new SessionLineItemPriceDataProductDataOptions
                    {
                        Name = "subscription"
                    },
                    Recurring = new SessionLineItemPriceDataRecurringOptions
                    {
                        Interval = "month",
                        IntervalCount = 1
                    }
    
                }
    

    在经历了大多数财产之后,它似乎不存在了?我想知道是否有人成功地实现了这一点?

    谢谢你抽出时间。

    1 回复  |  直到 2 年前
        1
  •  0
  •   Lucky2501    2 年前

    这在Checkout Session调用中是不可能的。

    你必须稍后再做,方法有两种:
    1-使用更新订阅 cancel_at
    https://stripe.com/docs/api/subscriptions/update#update_subscription-cancel_at
    2-向订阅添加时间表,然后使用更新该时间表 phases[0]iterations=12
    https://stripe.com/docs/billing/subscriptions/subscription-schedules/use-cases#existing-subscription

    我个人更喜欢选项2,尽管它有更多的调用,因为至少你不应该因为Unix时间代码计算错误而遇到任何按比例分配的问题。