本文介绍了带不同试用天数的价格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像下面这样的结账会话,其中包含三种不同的产品价格和 3 个不同的试用日:

I have a checkout session like bellow with three different product-prices, and 3 different trial days:

session = stripe.checkout.Session.create(
    customer="cus_ILmp6P6s1AfFWf",
    payment_method_types=['card'],
    line_items=[
        {
            'price': "price_1HjynjHdAaIdH7ntShQwSUAK",
            'quantity': 1,
            'tax_rates': ["txr_1Hk0zDHdAaIdH7ntg4yXtzmX", ],
        },
        {
            'price': "price_1HkaSlHdAaIdH7ntd8cbQJbG",
            'quantity': 1,
        },
        {
            'price': "price_1Hjyj5HdAaIdH7nt0YQPLd60",
            'quantity': 1,
        }, ],

    mode='subscription',
    billing_address_collection='required',
    subscription_data={'trial_period_days': 5},
    allow_promotion_codes=True,
    success_url=request.build_absolute_uri(reverse('thanks')) + '?session_id={CHECKOUT_SESSION_ID}',
    cancel_url=request.build_absolute_uri(reverse('index_payment')),
)

但是,通过使用 subscription_data={'trial_period_days': 5},显然我别无选择,只能为所有项目分配相同的试用期(5 天).

however by using subscription_data={'trial_period_days': 5}, apparantely I have no choice but to assigne same trial period ( 5 days) to all of the items.

我想知道是否有任何方法可以在结帐会话中为单独的产品/价格设置单独的试用天数.例如,如果只有一种产品进行了试用怎么办?谢谢,

I was wondering if there is any way to set separate trial days for separate product/prices in checkout session. for instance what if only one of the products has trial?Thanks,

推荐答案

您正在此处创建具有 3 个不同价格的单一订阅.有多个试用期是没有意义的,因为只有一个订阅.拥有多个计费锚点和试用期的单个订阅将是以后维护和审核的噩梦.

You are creating a singular Subscription here with 3 different Prices. It doesn't make sense to have multiple trial periods since there's only one Subscription. Having a single Subscription with multiple billing anchors and trial periods would be a nightmare to maintain and audit later.

如果您想为每个价格设置单独的试用期,则必须为每个价格创建一个新的订阅.

If you want to have separate trial periods for each Price, then you'd have to create a new Subscription for each.

这篇关于带不同试用天数的价格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 13:01