You can convert the values to undefined to omit it.
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
customer: customerEmail ? undefined : customer, //remove this line if new customer
customer_email: customerEmail || undefined, //remove this line if existing customer
line_items: [{price: planId, quantity: 1}],
subscription_data: {
trial_period_days: 15
},
metadata: {'planId': planId,'product': product},
success_url: `${domainURL}/index.html?product=${product}&session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${domainURL}/product=${product}&index.html?session_id=cancelled` ,
mode: 'subscription',
});
Another solution would be to extend the object conditionally.
const session = await stripe.checkout.sessions.create({
payment_method_types: ["card"],
line_items: [{price: planId, quantity: 1}],
subscription_data: {
trial_period_days: 15
},
metadata: {'planId': planId,'product': product},
success_url: `${domainURL}/index.html?product=${product}&session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${domainURL}/product=${product}&index.html?session_id=cancelled` ,
mode: 'subscription',
...(customerEmail ? { customer_email: customerEmail } : { customer })
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…