#SenorKarlos-help

1 messages ยท Page 1 of 1 (latest)

viral zenith
#

This is channel for Stripe related technical questions. If you have Stripe question regarding to that, you can share your question here

halcyon ridge
#

it's related to building the session checkout object if that counts ๐Ÿ˜‚

#

I'll pose it and you tell me lol

  sessions: {
    checkout: async function(req, res) {
      const mode = req.body.mode;
      const customerID = req.body.customerID;
      const priceID = req.body.priceID;
      var sessionbody = {
        mode: mode,
        customer: customerID,
        line_items: [
          {
            price: priceID,
            quantity: 1,
          },
        ],
        success_url: config.map_url,
        cancel_url: config.map_url,
      };
      if (config.stripe.taxes.active == true) {
        if (config.stripe.taxes.automatic == true) {
          sessionbody.automatic_tax.enabled = true;
        } else if (config.stripe.taxes.dynamic == true) {
          sessionbody.line_items[0].dynamic_tax_rates = config.stripe.taxes.rate_ids;
        } else {
          sessionbody.line_items[0].tax_rates = config.stripe.taxes.rate_ids;
        }
      }
      if (config.stripe.addresses.billing == true) {
        sessionbody.billing_address_collection = "required";
        sessionbody.customer_update.address = "auto";
      }
      if (config.stripe.addresses.shipping) {
        sessionbody.shipping_address_collection.allowed_countries = config.stripe.addresses.shipping;
        sessionbody.customer_update.shipping = "auto";
      }
      try {
        const session = await stripe_js.checkout.sessions.create(sessionbody);
        return res.redirect(303, session.url);
      } catch (e) {
        res.status(400);
        return res.send({
          error: {
            message: e.message,
          }
        });
      }
    }
  }

I'm trying to use automatic tax currently, but am building the bot for configurable usage. I get this error when I click my continue button

(node:9069) UnhandledPromiseRejectionWarning: TypeError: Cannot set property 'enabled' of undefined
    at Object.checkout (/home/senorkarlos/StripeWall/modules/stripe.js:238:45)
    at /home/senorkarlos/StripeWall/wall.js:181:26

238:45 is sessionbody.automatic_tax.enabled = true;

#

everything I've read says that once you create an object variable you can just push new key pairs to it by using dot notation, but ๐Ÿคทโ€โ™‚๏ธ

viral zenith
#

looking into it now

halcyon ridge
#

oh cool thanks! I was startin to think it was just out of scope n forgot to say no LOL

viral zenith
#

it should be:

automatic_tax: {
  enabled: true,
}
halcyon ridge
#

that's what the resulting object item would be yea but I'm writing it with lines of js code, not statically

viral zenith
#

This should be how the request looks like for automatic tax

halcyon ridge
#

I've just got a reply from a node programming buddy working a much more complex program than mine, I'm guessin he'll know what I mean and how to fix my stupid ๐Ÿ˜„ lol

#

ty for replying ๐Ÿ™‚

#

it really is out of the scope of 'stripe support' more like 'help me with my basic coding skill gaps'

#

๐Ÿคฆโ€โ™‚๏ธ so now that he explained it to me in layman, I know what you meant. And thank you again LOL ๐Ÿ˜„

viral zenith
#

No problem! Happy to help ๐Ÿ™‚