#vm1172

1 messages · Page 1 of 1 (latest)

tough mulchBOT
meager temple
#

"stripe": "^11.14.0",

novel rapids
#

Can you find the errored request in Dashboard, or is it errored on client?

meager temple
#

I also have the STRIPE_SECRET_KEY inside the .env files (since all other calls are being made properly

#

sure one second

#

request id = req_jN2N84YttjLVAm

#

tax API is never being hit, it just shows up as undefined property on the stripe singleton

novel rapids
#

Hmm that's a normal PaymentIntent creation and it succeeded

#

Can you share your code?

meager temple
#
  public async calculateTax(amount: number, gentlyId: string, postal_code: string): Promise<number> {
    const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { apiVersion: '2022-11-15' });
    console.log({ stripe });
    const paymentIntent = await this.getPaymentIntent('pi_3NxtVcCa1hzW9vNX1aCxEdit');
    console.log({ paymentIntent });
    const params: CalculationCreateParams = {
      currency: CURRENCY,
      line_items: [
        {
          amount,
          reference: gentlyId,
        },
      ],
      customer_details: {
        address: {
          postal_code,
          country: ALLOWED_COUNTRY,
        },
        address_source: 'shipping',
      },
      expand: ['line_items.data.tax_breakdown'],
    };

    console.log({ params });
    const calculation = await stripe.tax.calculations.create(params);
    return calculation.tax_breakdown[0].amount;
  }
#

while this works

  public async getPaymentIntent(paymentIntentId: string): Promise<Stripe.PaymentIntent> {
    const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { apiVersion: '2022-11-15' });
    const paymentIntent = await stripe.paymentIntents.retrieve(paymentIntentId);
    console.log('paymentIntent: ', paymentIntent);
    return paymentIntent;
  }
novel rapids
#

It's the API version I think

#

Why wouldn't you use a newer one? Like 2023

meager temple
#

I can try swapping to the latest version but that might require a migration effort and fixing breaking changes

#

what i dont understand is why it would working in our staging environment and not in the production server

novel rapids
#

Let's try to see if that's really the version which is causing the error

meager temple
#

do you mean just do this?

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { apiVersion: '2023-08-16' });

novel rapids
#

No, on the call const calculation = await stripe.tax.calculations.create(params);

meager temple
#

ah like this

novel rapids
#
const calculation = await stripe.tax.calculations.create(
    params,
    {
        stripe_version: '2023-08-16',
    }
);
meager temple
#

const calculation = await stripe.tax.calculations.create(params, { apiVersion: '2023-08-16' });

novel rapids
#

Yep yep

meager temple
#

got it thank you, trying it out now

#

still getting the same error

error:  TypeError: Cannot read property 'calculations' of undefined
0|server  |     at CheckoutSessionService.calculateTax (/home/ubuntu/server/src/services/checkoutsession.service.ts:153:42)
novel rapids
#

Can you upgrade your Node SDK to latest version?

meager temple
#

its working on staging

#

imo its not a Node SDK version issue

novel rapids
#

Yeah got it. But just to be sure, which SDK version is your staging server, vs your production server?

meager temple
#

and we merge from staging into production so its parity ->
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, { apiVersion: '2022-11-15' });

novel rapids
#

Uhmmm I see...

#

Only from 12.14.0 you have Tax calculations

#

I think your Staging may have something else made it working

meager temple
#

those just seem like type changes, and not actual implementation of the stripe.tax.calculations

#

but let me update to the latest version and get back to you

#

ill need some time upgrading the packages and running some tests, do you mind keeping this thread open?

novel rapids
#

Sure, but my colleague may take over later

meager temple
#

hey, so we cannot upgrade Stripes SDK right now since it will require a lot of changes. Based on the Stripe Change log, Tax Calculations API was added before the version we're currently using (11.14.0)

#

With no change to our current set up, I could still hit the tax calculations endpoint properly

Also the types wouldn't be available for tax.calculations.create if it was not available in the version i'm on

novel rapids
#

Hi, could you clarify where do you see this?

Based on the Stripe Change log, Tax Calculations API was added before the version we're currently using (11.14.0)

novel rapids
#

Hmm okie, could you double (triple!) check your Node version on Production server?

meager temple
#

hey, we're just going ahead and upgrading. if there are any issues fortunately we can roll back

novel rapids