Q: Add Customer Email in Stripe Checkout ONLY if it is exists How can I pass in the 'customer_email' into Stripe Checkout only if it exists. If it does not exist, I do not want to pass in an email/ property at all.
I have a case where if a user is logged-in, then their customer_email is passed to function; else I do not want to add the customer_email property.
Case logged-in: let customerEmail = "example@example.com";
Case logged-out: let customerEmail;
customer_email: customerEmail ? customerEmail: null
Essentially, is it possible to pass in a property/ key into an object dynamically based on its existence?
Is this possible?
let customerEmail;

const session = await stripe.checkout.sessions.create({
      payment_method_types: [
        "card"
      ],
      payment_method_options: {
        wechat_pay: {
          client: "web",
        },
      },
      line_items: [
        {
          price: priceId,
          quantity: 1,
          description: priceName,
        },
      ],
      mode: "payment",
      allow_promotion_codes: true,
      locale: "auto"
      },
      customer_email: customerEmail ? customerEmail: null,
      success_url:
        "http://google.com/session_id={CHECKOUT_SESSION_ID}",
      cancel_url: "http://google.com/",
    });

    res.redirect(303, session.url);
  });

Thank you.

A: You can do somthing like this
var strip_param = {
    payment_method_types: [
        "card"
    ],
    payment_method_options: {
        wechat_pay: {
            client: "web",
        },
    },
    line_items: [
        {
            price: priceId,
            quantity: 1,
            description: priceName,
        },
    ],
    mode: "payment",
    allow_promotion_codes: true,
    locale: "auto",
    success_url: "http://google.com/session_id={CHECKOUT_SESSION_ID}",
    cancel_url: "http://google.com/",
};

if(customerEmail){
    strip_param = {...strip_param, customer_email: customerEmail}
}

const session = await stripe.checkout.sessions.create(strip_param);

