#AlphaRyze

1 messages · Page 1 of 1 (latest)

somber wedgeBOT
hollow cloud
#

Hi, I'm unable to open a thread here. Can you summarize the ask here and I'm happy to further assist

hybrid nest
#

sure

#

this is my code

#

so basically i'm sending through post request the events to a lambda function

#

on aws

#

using node

hybrid nest
# hybrid nest

the old code, don't mind the tokens, those are already changed

#

i added the event = JSON.stringify({ body: event })

#

before the const sig = ...

hollow cloud
#

What is the issue here? Can you be more specific? Are you seeing error? What errors are you seeing?

hybrid nest
#

wait i think i found a solution

#

sorry for disturbing

hollow cloud
#

No problem, happy you got it working

hybrid nest
#

oke

#

i wasn't able to resolve

#

basically i have an Endpoint that sends specific events to an AWS API GATEWAY

#

connected to a lambda function

#

but the fact is that it tells me that the stripe-headers are not valid

hollow cloud
hybrid nest
#

don't worry

#

i've already changed it

#

it has already been changed a while ago

#

it's just a test purpose screen

hollow cloud
#

Next, I'd recommend that you manually pass your webhook secret key to your code.

#

And see if it works

hybrid nest
#

already done

hollow cloud
#

Does it work? Or are you still seeing the same error?

hybrid nest
#

same error

#

let me send you a screen

#
export const handler = async (event) => {
  
  const stripe = new Stripe("sk_test_51M.....");
  // Validate the webhook signature
  const sig = event.headers['stripe-signature'];
  const payload = event.body;
  const endpointSecret = "whsec_ihT......";

  let stripeEvent;

  try {
    stripeEvent = stripe.webhooks.constructEvent(payload, sig, endpointSecret);
  } catch (err) {
    console.error(`Webhook Error: ${err.message}`);
    return {
      statusCode: 400,
      body: `Webhook Error: ${err.message}`,
    };
  }

  // Handle different event types
  switch (stripeEvent.type) {
    case 'checkout.session.completed':
      // Update the user profile in DynamoDB
      const session = stripeEvent.data.object;
      const stripeCustomerId = session.customer;
      const subscriptionId = session.subscription;
      const userId = session.metadata.userId;

      try {
        return { statusCode: 200, body: 'Success' };
      } catch (error) {
        console.error('Error updating user profile:', error);
        return { statusCode: 500, body: 'Error updating user profile' };
      }

  }
};
#

But the results are that the stripe-signature

#

{
"errorType": "TypeError",
"errorMessage": "Cannot read properties of undefined (reading 'stripe-signature')",
"trace": [
"TypeError: Cannot read properties of undefined (reading 'stripe-signature')",
" at Runtime.handler (file:///var/task/index.mjs:123:28)",
" at Runtime.handleOnceNonStreaming (file:///var/runtime/index.mjs:1085:29)"
]
}

hollow cloud
#

If it is the same error, it's likely that you're using the wrong secret webhook key. Are you working with multiple accounts?

hybrid nest
#

nop

#

the fact is that the request is right

#

and also

#

i just have the secret client and the webhook secret

#

so i just copied the secret private digital key

#

and pasted into the webhook secret

hollow cloud
#

When you paste this, are you making sure that you're not adding any extra space?

hybrid nest
#

sure

#

100%

#

may i ask you since before i was talking to @full radish and he was proposing solutions

hollow cloud
#

They are out for the day, looking on my end

hybrid nest
#

ok ty anyways

#

cause i'm dying inside xD

hollow cloud
#

Instead of passing endpointSecret on your stripe.webhooks.constructEvent, can you pass the webhook secret? I think there might be an extension or something that is parsing the webhook secret.

hybrid nest
#

the fact is

#

theat i can't pass the const sig

hollow cloud
#

I see, sorry I read too quickly. I'm talking to a colleague about this. Thank you for your patience.

hybrid nest
#

no problems

hollow cloud
#

Can you log the event please?

hybrid nest
#

sure

#

1 sec

#

i'm gonna send you the pastebin link

hollow cloud
#

Specifically, on line 17.. we're looking at the request const signature = request.headers['stripe-signature']; for the headers.