#HERZ - stripe connectivity
1 messages ยท Page 1 of 1 (latest)
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.
Okay and where are you running this code?
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.)
And you said you've run the Stripe connectivity script inside the Docker container?
Yes. And as I said inside the container I ran this script, and inside the code I tested node-fetch, and it works perfectly.
https://github.com/stripe/stripe-reachability
Okay can I see the bit of code where you are trying to connect to stripe? Where this error gets thrown?
HERZ - stripe connectivity
Just a snippet please between three `
// 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 }
)
}```
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.
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?
Okay, unfortunately I can't do these tests at the moment, is it okay if I do them in the next few days, or will the thread be closed?