#louis_checkout-tax

1 messages Ā· Page 1 of 1 (latest)

stone pantherBOT
#

šŸ‘‹ Welcome to your new thread!

ā²ļø We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

ā±ļø We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.

šŸ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1250841897430286356

šŸ“ Have more to share? Add details, code, screenshots, videos, etc. below.

halcyon lichen
#

I have my checkout session set up likehtis but i dont want to calculate tax on each product. Iwant tax to be applied tothe total amout on checkout which is shipping + all lineitem prices const lineItems = products.map((product) => ({
price_data: {
currency: "cad",
product_data: {
name: product.name,
},
unit_amount: Math.round(product.price * 100), // Ensure price is in cents
},
// tax_rates: [taxRate.id],
quantity: product.qty,
}));

// Create stripe session
const session = await stripe.checkout.sessions.create({
  shipping_options: [
    {
      shipping_rate_data: {
        type: "fixed_amount",
        fixed_amount: {
          amount: shipping * 100,
          currency: "cad",
        },
        display_name: "Express shipping", // Example: display name for shipping
      },
    },
  ],
  payment_method_types: ["card"],
  line_items: lineItems,
  shipping_address_collection: shippingAddress,
  mode: "payment",
  after_expiration: {
    recovery: {
      enabled: true,
      allow_promotion_codes: true,
    },
  },
  success_url: `${req.protocol}://${frontendBaseUrl}/ordersuccess`,
  cancel_url: `${req.protocol}://${frontendBaseUrl}/orderfailed`,
});

// Send the session URL back to the client instead of redirecting
res.status(200).json({ sessionUrl: session.url, sessionId: session.id });

} catch (error) {
console.error("Error creating checkout session:", error);
res.status(500).json({ error: "Internal server error." });
}
});

storm fox
halcyon lichen
#

if i add this to the session how to do i ensure it collects tax in my region automatic_tax
: {
enabled
: true,
},

storm fox
#

I's recommend reading the docs I shared!

#

louis_checkout-tax

halcyon lichen
#

i did and still do not understandwhere to apply tax to my session. that is why i am here

storm fox
#

You don't "appluy tax to a session". You instead enable automatic tax calculation and we (Stripe) will calculate the tax for you
But for that to work you have to configure all your Products/Prices to have the relevant tax code, you have to tell us where you are registered to file taxes, etc.
This is something you need to carefully read end to end in our guide which walks you through the integration

halcyon lichen
#

when i add this to my stripe expressbackend it throws and error when trying to create the session automatic_tax
: {
enabled
: true,
},

storm fox
#

I'm sorry your code is weirdly formatted with new lines in the middle and no context. I can't really help you without exact real code, exact error message, what you tried, what doesn't work, etc.

halcyon lichen
storm fox
#

there is no mention of the word automatic_tax on that page anywhere

halcyon lichen
#

i havenot pushedit intothe repository but when I add it won't creat the session

storm fox
#

All good! I'm trying to help you debug things here. You're the developer writing the code and you see the code. What exact code are you using? What exact error are you getting?
Our API is usually really clear and tells you exactly what's wrong

halcyon lichen
#

this is the error I am getting Payment failed:
Object { stack: "AxiosError@http://localhost:3000/static/js/bundle.js:509471:18\nsettle@http://localhost:3000/static/js/bundle.js:510124:12\nonloadend@http://localhost:3000/static/js/bundle.js:508786:66\n", message: "Request failed with status code 500", name: "AxiosError", code: "ERR_BAD_RESPONSE", config: {…}, request: XMLHttpRequest, response: {…} }
​
code: "ERR_BAD_RESPONSE"
​
config: Object { timeout: 0, xsrfCookieName: "XSRF-TOKEN", xsrfHeaderName: "X-XSRF-TOKEN", … }
​
message: "Request failed with status code 500"
​
name: "AxiosError"
​
request: XMLHttpRequest { readyState: 4, timeout: 0, withCredentials: false, … }
​
response: Object { data: {…}, status: 500, statusText: "Internal Server Error", … }
​
stack: "AxiosError@http://localhost:3000/static/js/bundle.js:509471:18\nsettle@http://localhost:3000/static/js/bundle.js:510124:12\nonloadend@http://localhost:3000/static/js/bundle.js:508786:66\n"
​
<prototype>: Object { constructor: AxiosError(message, code, config, request, response), toJSON: toJSON(), stack: "", … }

#

when my session is like this const session = await stripe.checkout.sessions.create({
shipping_options: [
{
shipping_rate_data: {
type: "fixed_amount",
fixed_amount: {
amount: shipping * 100,
currency: "cad",
},
display_name: "Express shipping", // Example: display name for shipping
},
},
],
payment_method_types: ["card"],
line_items: lineItems,
shipping_address_collection: shippingAddress,
automatic_tax
: {
enabled
: true,
},
mode: "payment",
after_expiration: {
recovery: {
enabled: true,
allow_promotion_codes: true,
},
},
success_url: ${req.protocol}://${frontendBaseUrl}/ordersuccess,
cancel_url: ${req.protocol}://${frontendBaseUrl}/orderfailed,
});

storm fox
#

When you call our API, if an error is returned it's raised as an exception. Read https://docs.stripe.com/error-handling?lang=node which covers in details how this works and make sure to properly catch exceptions and log them.
Once you do, this should give you the exact error message our API return and help you self-serve debugging the issue.

#

You can also go in your Dashboard and read the logs at https://dashboard.stripe.com/test/logs my guess is that you have a real/clear error there you're not seeing in your code and it's going to tell you what you missed

#

You likely forgot to activate/configure Stripe Tax first

halcyon lichen
#

where do i find activate/configure stripe tax in my dashboard

storm fox