#vially.dag

1 messages · Page 1 of 1 (latest)

final basaltBOT
tardy wind
#

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

[0] https://stripe.com/docs/api/request_ids?

static fiber
# tardy wind hello! I think the first thing to check here is if the request to retrieve the c...

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.
tardy wind
#

so it logs the first console.log with the customerID but doesn't run the method to retrieve the customer?

static fiber
#

yes

#

and it doesn't even enter the catch block so that I can see the errors

tardy wind
#

if you comment out the customers.retrieve function, does it move on to the second console.log at least?

static fiber
#

I'm testing this right away.

#

Yes, when I comment out that line, the code runs normally, and the other logs are displayed.

tardy wind
#

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

static fiber
#

😭 😭 The problem is that in development mode, I don't encounter this issue. Everything works perfectly.

#

Thank you so much for your time.

tardy wind
#

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

static fiber
#

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?😐

tardy wind
#

well, we're making some progress at least. What do you mean by blocking?

static fiber
#

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

olive spoke
#

Hi @static fiber have you checked the server logs and see if there are any errors?

static fiber
#

Hello, yes, I just checked and there is no error in the logs, especially for GET type calls

olive spoke
#

I mean your Vercel server logs, not the logs in Stripe Dashboard.

static fiber
#

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

olive spoke
#

That's very strange indeed. So it works in you local machine, but doesn't after being deployed to vercel?

static fiber
#

Exactly, it works perfectly on my machine. But in production, this function causes a problem

olive spoke
#

Can you deliberately crash your app and see if Vercel shows any error logs?

static fiber
#

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.

acoustic crag
#

Hi! I'm taking over from my colleague. Please, give me a moment to catch up.

static fiber
#

hi! ok no problem

acoustic crag
#

Could you please share a screenshot of the logs that contain the first console.log?

static fiber
acoustic crag
#

And nothing afterwards?

static fiber
#

this is the log in vercel

static fiber
#

yes, nothing

acoustic crag
#

Do you have a Request ID for the GET request?

acoustic crag
#

"customer ID in getCustomer" in your code and "customer ID dans le getCustomer" in the logs.

static fiber
#

yes i no, i don't speak english well😅 , and i used chat gpt to traduct my text and my code was in

static fiber
acoustic crag
static fiber
#

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

acoustic crag
acoustic crag
static fiber
acoustic crag
acoustic crag
#

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?

static fiber
#

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

acoustic crag
static fiber
#

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.

#

😭

acoustic crag
#

So your code just stops working at some point?

static fiber
#

yes

acoustic crag
#

I would reach out to Vercel to ask why is this happening. The issue doesn't seem to be on the Stripe side.

static fiber
#

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.🙏

acoustic crag
#

Hope they find a solution.
Happy to help.