#mo-daniel_api

1 messages ¡ Page 1 of 1 (latest)

honest ivyBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1376910138329403392

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

warm adder
#

when I deploy it , it does not work
What do you mean here? What is not working as you expect it to?

#

You shared an example charge that appears to have been successful

neon fox
#

so the tax rate is not calculated

#

it works on my machine when building

#

but not after deployment on the web

#

should i configure anything on stripe for it to work with https

warm adder
#

Can you be more precise about what exactly you expect to see where, and where that doesnt match what you observe happening?

#

For example, is there some request with a different result that you expect?

neon fox
#

I expect it to return the actual Tax rate in the invoice card, but it shows 0%. When working locally it calculates it automatically

#

using the stripe tax api

warm adder
#

Sure, but this is showing me your app ui, not a Stripe API request with an unexpected result. Have you narrowed this down to an unexpected API result from stripe?

neon fox
#

yes

#

this is my firebase function for stripe tax calculation:
export const calculateTaxRate = onCall(
commonOptions,
async (request): Promise<{ taxRate: number; success: boolean; message?: string; exactPercentage: string }> => {
const data = request.data
try {
const { address } = data

  const stripe = new Stripe(STRIPE_CONFIG.secretKey.value(), {
    apiVersion: STRIPE_CONFIG.apiVersion.value() as Stripe.LatestApiVersion,
  })

  const customerDetails: Stripe.Tax.CalculationCreateParams.CustomerDetails = {
    address: {
      line1: address.line1,
      line2: address.line2 || '',
      city: address.city,
      state: address.state,
      postal_code: address.postal_code,
      country: address.country || 'US',
    },
    address_source: 'shipping',
  }

  const calculation_params: Stripe.Tax.CalculationCreateParams = {
    currency: 'usd',
    customer_details: customerDetails,
    line_items: [
      {
        amount: 1,
        reference: 'invoice_subtotal',
        tax_code: 'txcd_20020009',
      },
    ],
    expand: ['tax_breakdown'],
  }

  const taxCalculation = await stripe.tax.calculations.create(calculation_params)

  const actualPercentageDecimal = taxCalculation.tax_breakdown?.[0]?.tax_rate_details?.percentage_decimal || '0'
  const taxRate = parseFloat(actualPercentageDecimal) / 100

  return {
    success: true,
    taxRate: taxRate,
    exactPercentage: actualPercentageDecimal,
  }
} catch (error: unknown) {
  const err = error as Error
  console.error('Error calculating tax rate:', err)
  return {
    success: false,
    message: err.message,
    taxRate: 0,
    exactPercentage: '0',
  }
}

}
)

warm adder
#

Ok, and you're saying this works differently for you in test mode vs live mode?

#

Do you have the exact request IDs of the examples using the same params with different results in test vs live? Or the tax calculation ID from those requests?

#

If this is test vs live, or using a different account etc, my first thought is mismatched tax registrations leading to a different calculation. But having the object IDs to inspect would let me confirm that or find other explanations.

neon fox
#

yes, we are using connect accounts

#

i set the tax registration up for the main account , do i need to set tax registration up for each new account connected to it

honest ivyBOT
fierce coral
#

Hello, taking over for my colleague who has to step out. I'm still catching up, will get to your latest question in a moment