#diavo-checkout-trial
1 messages · Page 1 of 1 (latest)
hello, you want this: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-trial_period_days
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Thanks but how do i implement it in here ? ``` app.post("/create-checkout-session", async (req, res) => {
const domainURL = process.env.DOMAIN;
const amount = process.env.SITE_PRICE_ID;
const { priceId } = req.body;
let customerName = req.body.customername;
let customerDesc = req.body.customerdesc;
let customer = await stripe.customers.create({
name: customerName,
metadata: { entreprise: customerDesc}
});
try {
const session = await stripe.checkout.sessions.create({
customer: customer.id,
phone_number_collection: {
enabled: true,
},
billing_address_collection: 'required',
mode: "subscription",
payment_method_types: ["card"],
line_items: [
{
price: priceId,
quantity: 1,
},
{
price : amount,
adjustable_quantity:{
enabled:true,
minimum: 0,
maximum:10,
},
quantity: 1,
},
],
automatic_tax: {
enabled: true,
},
success_url: `${domainURL}/success.html?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${domainURL}/canceled.html`,
});
return res.redirect(303, session.url);
} catch (e) {
res.status(400);
return res.send({
error: {
message: e.message,
}
});
}
});``` ?
are you the developer building the integration?
Yeah
the API ref link shows what you need to pass, you have to pass subscription_data.trial_period_days
Yeah but what is the syntax ? How do i add my 30 days here ?
subscription_data is a hash
so
...
}```
and inside that you pass `trial_period_days: 30`
Ok fuck me. In my code uphere, i have 2 products, it possible to assign this behaviour (trial 30 days) to the first one (price: priceId?)
no it applies to the whole Subscription, you cannot give trial only on one of the products
ok and i have a last question ``` line_items: [
{
price: priceId,
quantity: 1,
tax_behavior: "exclusive",
},
{
price : amount,
adjustable_quantity:{
enabled:true,
minimum: 0,
maximum:10,
},
quantity: 1,
tax_behavior: "exclusive",
},
],
subscription_data:{
trial_period_days:30
},
automatic_tax: {
enabled: true,
},``` i wanted to add tax to my product but it says "{"error":{"message":"Received unknown parameter: line_items[0][tax_behavior]"}}" i activated tax on my dashboard also
so tax_behavior is not a parameter on line_items if you see the API ref
instead it is inside the price_data hash
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-tax_behavior
which you are not using, you are passing a Price ID (for a Price you already created)
you would have to update the Price via the Dashboard or API and update tax_behavior on that
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
And there is no way to get trial subscription only for one item during checkout ? Thanks mate !
there isn't no
Ok thanks mate, have a good dayt