简体   繁体   中英

how to add trial period in Checkout session in Stripe

I have this code:

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`,
    });

and I want to add this:

    subscription_data: {
       trial_end=1605387163
    }

but whereever I put it, it doesn't work? How do i fix this?

For future reference, what I was doing wrong was the way I was defining trial_end .

this is the function at a whole:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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