#HERZ - stripe connectivity

1 messages ยท Page 1 of 1 (latest)

jade chasmBOT
fickle inlet
#

Hi ๐Ÿ‘‹

Can you summarize your overall question?

stark idol
# fickle inlet Hi ๐Ÿ‘‹ Can you summarize your overall question?

Ok, basically I get this error using the Stripe Library: /app/node_modules/stripe/lib/StripeResource.js:572:15 An error occurred with our connection to Stripe

I tried different versions of node, different versions of the library. I tried node-fetch, I tried running the Stripe script to check the connection. And nothing, everything seems fine only the library gives me this error. I`ve been trying again for about 2 months now in the hope that later versions will come to my rescue in solving the problem, or figuring out its source. But nothing.

fickle inlet
#

Okay and where are you running this code?

stark idol
#

On a Node Container. I have tried different versions of node, both on standard, slim and alpine images, even on different versions of debian (buster, bullseye, etc.)

https://hub.docker.com/_/node

fickle inlet
#

And you said you've run the Stripe connectivity script inside the Docker container?

stark idol
fickle inlet
#

Okay can I see the bit of code where you are trying to connect to stripe? Where this error gets thrown?

#

HERZ - stripe connectivity

fickle inlet
#

Just a snippet please between three `

stark idol
#
// Setup stripe
const stripe = new Stripe(STRIPE_SECRET_KEY, {
  apiVersion: '2020-08-27'
})

// Creation of a new Stripe's Customer
const createCustomer = async (email: string): Promise<Stripe.Response<Stripe.Customer>> => {
  const customer = await stripe.customers.create({
    email,
    description: email
  })
  return customer
}

// Creation of a Stripe's checkout session
const createPaymentSession = async (customer: string, price: string): Promise<Stripe.Response<Stripe.Checkout.Session>> => {
  const successUrl = process.env.STRIPE_SUBSCRIPTION_SUCCESS_URL
  const cancelUrl = process.env.STRIPE_SUBSCRIPTION_CANCEL_URL
  if (!successUrl || !cancelUrl) {
    const errorString = 'Invalid configuration: STRIPE_SUBSCRIPTION_SUCCESS_URL, STRIPE_SUBSCRIPTION_CANCEL_URL'
    enqueueLogMessage('-1', 'createPaymentSession', LogSeverity.Fatal, 'Invalid configuration', errorString)
    throw new Error(errorString)
  }

  const trialDays = parseInt(process.env.TRIAL_PERIOD_DAYS || '30')
  if (isNaN(trialDays)) {
    throw new Error(`Unable to parse ${process.env.TRIAL_PERIOD_DAYS} as number`)
  }
  const session = await stripe.checkout.sessions.create({
    mode: 'subscription',
    payment_method_types: ['card'],
    customer,
    line_items: [
      {
        price
      }
    ],
    subscription_data: {
      trial_period_days: trialDays
    },

    success_url: successUrl,
    cancel_url: cancelUrl
  })

  return session
}

const createBillingSession = async (customer: string): Promise<Stripe.Response<Stripe.BillingPortal.Session>> => {
  const session = await stripe.billingPortal.sessions.create({
    customer
  })
  return session
}

const updateCustomerMail = async (cusId: string, newMail: string) : Promise<void> => {
  await stripe.customers.update(
    cusId,
    { description: newMail, email: newMail }
  )
}```
fickle inlet
#

Okay and is the error being thrown at new Stripe(...)

#

?

stark idol
#

No, at createCustomer. Or any other call to Stripe.

However, I think it's not a problem with the code. Locally it works, inside the container it doesn't. It would be more useful to have a more explicit error of what is happening.

fickle inlet
#

I can agree with that. However, this error is generally thrown when the outgoing request is unable to reach the Stripe server. Can you log outgoing HTTP requests outside the container? So we could examine what the requests look like after they leave the container?

stark idol
fickle inlet
#

This thread will be closed but you can always reference it and summarize this information.

#

And we'll be here to help as soon as you can share more networking info