#vially.dag
1 messages · Page 1 of 1 (latest)
hello! I think the first thing to check here is if the request to retrieve the customer was actually made. Can you track down the corresponding request id [0]? it'd look like req_xxx
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Hello and thank you for your response. Indeed, the request is not being executed. Here is my code:
const stripe = require("stripe")(process.env.PRIVATE_KEY_STRIPE);
const getCustomer = async ({ customerId }) => {
try {
console.log("customer ID in getCustomer: ", customerId);
const customer = await stripe.customers.retrieve(customerId);
console.log("customer in getCustomer: ", customer);
return customer;
} catch (error) {
console.error(
"An error occurred while retrieving the Stripe customer:",
error
);
return null;
}
};```
In production mode, the console.log after the retrieve function is not displayed.
so it logs the first console.log with the customerID but doesn't run the method to retrieve the customer?
if you comment out the customers.retrieve function, does it move on to the second console.log at least?
I'm testing this right away.
Yes, when I comment out that line, the code runs normally, and the other logs are displayed.
okay, i'm pretty baffled at what's going on too, can you uncomment the customers.retrieve function back, and use the debugger to step through your code line by line, that might give us a better idea of what's actually occurring here
this might be a bit silly, but make sure you've saved your file if you've made any changes
😭 😭 The problem is that in development mode, I don't encounter this issue. Everything works perfectly.
Thank you so much for your time.
I'm sorry but I'm not sure how else to help then. It feels like some kind of production/server specific issue. Maybe check in your server logs (I'm not familiar with Vercel) to see if there's anything that you can spot.
It's just seems logically impossible for the server to totally ignore that line entirely without logging some detail as to why they're ignoring the line / not making the request
Have you also checked your Dashboard logs to be 100% sure the request was never sent/made at all?
you'll need to ensure you filter for GET requests also when looking at the Dashboard logs, since the Dashboard doesn't show GET requests by default
I just checked, and indeed the request was made with a 200 code on Stripe!!! But why am I not getting a response, and why is it blocking?😐
well, we're making some progress at least. What do you mean by blocking?
By 'blocked,' I mean my code doesn't execute the rest of the function. No, on Stripe, I don't see anything abnormal. Just that the call is made with a 200 code
Hi @static fiber have you checked the server logs and see if there are any errors?
Hello, yes, I just checked and there is no error in the logs, especially for GET type calls
I mean your Vercel server logs, not the logs in Stripe Dashboard.
Yes, there too. There is no error. Just the log before the retrieve function call, after that, nothing. The code doesn't even enter the catch block
At first, I thought I had misconfigured the Stripe secret key in Vercel, but no, because it still verifies the webhook signature and detects the event type
That's very strange indeed. So it works in you local machine, but doesn't after being deployed to vercel?
Exactly, it works perfectly on my machine. But in production, this function causes a problem
Can you deliberately crash your app and see if Vercel shows any error logs?
Okay, I'll test that right away and get back to you
Sorry I took a bit of time. Yes, when I have an error, it shows up in the logs. It also enters the catch block when needed.
Hi! I'm taking over from my colleague. Please, give me a moment to catch up.
hi! ok no problem
If I understand correctly, you don't see the second console.log() here?
Could you please share a screenshot of the logs that contain the first console.log?
yes, the second console.log after the call of customer.retrieve
ok no problem
And nothing afterwards?
this is the log in vercel
Do you have a Request ID for the GET request?
Wait, that's not the text from the code
"customer ID in getCustomer" in your code and "customer ID dans le getCustomer" in the logs.
yes i no, i don't speak english well😅 , and i used chat gpt to traduct my text and my code was in
Do I need to find it in Stripe?
Can you please share the actual code?
my code : ```js
const getCustomer = async ({ customerId }) => {
try {
console.log("customer ID dans le getCustomer : ", customerId);
const customer = await stripe.customers.retrieve(customerId);
console.log("customer dans le getCustomer : ", customer);
return customer;
} catch (error) {
console.error(
"Une erreur s'est produite lors de la récupération du client Stripe :",
error
);
return null;
}
};```
the request ID in stripe : req_QkEBhLBnb751GR
Does this only happen with GET requests?
Not seeing anything out of the ordinary.
Yes, in production mode, it's the only function causing issues. But everything works fine locally
As you see, the response comes back successful, with status 200. So it's something in your code that causes this. Maybe there's some timeout?
Can you replace it with something? Maybe GET PaymentIntent or anything else. I am just trying to understand what part of the code causes the problem.
Or maybe remove the try/catch block so if there's an error it's thrown outside of the function.
Where are you calling this function actually? Does the execution continue after it?
No, there is no timeout in the code. Okay, I will try what you said. I'll share with you the place where I call the function.
case "customer.subscription.created":
subscription = event.data.object;
status = subscription.status;
console.log("le status est : ", status);
getCustomer({ customerId: subscription?.customer }).then((customer) => {
console.log("customer : ", customer);
if (customer) {
SubscriptionControler.createSubscription({
subscription,
email: customer?.email,
}).then(() => {
console.log(
`Création de l'abonnement de ${customer?.email} dans la db - status : ${status}`
);
});
} else {
console.log("Client introuvable.");
}
});
break;```
the log in vercel : le status est : trialing
customer ID dans le getCustomer : cus_OymjEPitNykD2i
Have you tried those other things?
i remove the try/catch block and change the methode : ```js
const getCustomer = async ({ customerId }) => {
//displayed
console.log("customer ID dans le getCustomer : ", customerId);
const paymentIntent = await stripe.paymentIntents.create({
amount: 100,
currency: 'eur',
customer: customerId,
});
//no displayed
console.log("paymentIntent : ", paymentIntent);
// const customer = await stripe.customers.retrieve(customerId);
const paymentIntentCreated = await stripe.paymentIntents.retrieve(paymentIntent.id);
console.log("intent dans le getCustomer : ", paymentIntentCreated);
return paymentIntentCreated;
};
my log in vercel : le status est : trialing
customer ID dans le getCustomer : cus_OymjEPitNykD2i
the payment intent in stripe : pi_3OArErCBRBbKE7DD1fMZYBsp
I no longer understand.
😭
So your code just stops working at some point?
yes
I would reach out to Vercel to ask why is this happening. The issue doesn't seem to be on the Stripe side.
Okay, I'll contact them and see if they can help me because I don't understand anything anymore. Everything works fine with Stripe and with my local code. Thanks again for your time.🙏
Hope they find a solution.
Happy to help.