繁体   English   中英

如何在 Stripe 的 Checkout session 中添加试用期

[英]how to add trial period in Checkout session in Stripe

我有这个代码:

const session = await stripe.checkout.sessions.create({
    billing_address_collection: 'auto',
    payment_method_types: ['card'],
    customer_email: email,
    line_items: [
        {
        price: priceID,
        // For metered billing, do not pass quantity
        quantity: 1,
        },
    ],
    // subscription_data: 
    mode: 'subscription',
    success_url: `${YOUR_DOMAIN}/gen_trainerclientlist`,
    cancel_url: `${YOUR_DOMAIN}/cancel.html`,
    });

我想补充一点:

    subscription_data: {
       trial_end=1605387163
    }

但无论我把它放在哪里,它都不起作用? 我该如何解决?

为了将来参考,我做错的是我定义trial_end的方式。

这是 function 的整体:

var priceID = "price_1K6dU7IPT89VeZtCF2YLsVNo"
    console.log(priceID)
    const session = await stripe.checkout.sessions.create({
    billing_address_collection: 'auto',
    payment_method_types: ['card'],
    customer_email: email,
    line_items: [
        {
        price: priceID,
        // For metered billing, do not pass quantity
        quantity: 1,
        },
    ],
    subscription_data: {
        trial_end: Math.floor(+new Date() / 1000) + 15 * 24 * 60 * 60,
    },
    mode: 'subscription',
    success_url: `${YOUR_DOMAIN}/success`,
    cancel_url: `${YOUR_DOMAIN}/login`,
    });

res.redirect(303, session.url)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM