#AlphaRyze
1 messages · Page 1 of 1 (latest)
Hi, I'm unable to open a thread here. Can you summarize the ask here and I'm happy to further assist
sure
this is my code
so basically i'm sending through post request the events to a lambda function
on aws
using node
the old code, don't mind the tokens, those are already changed
i tried adding as suggested by this sent from a moderator: https://github.com/stripe/stripe-node/issues/356
i added the event = JSON.stringify({ body: event })
before the const sig = ...
What is the issue here? Can you be more specific? Are you seeing error? What errors are you seeing?
No problem, happy you got it working
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
On your screenshot, please delete it as your secret API key is exposed. I'd recommend that you roll your key as well: https://stripe.com/docs/keys#rolling-keys
don't worry
i've already changed it
it has already been changed a while ago
it's just a test purpose screen
Next, I'd recommend that you manually pass your webhook secret key to your code.
And see if it works
already done
Does it work? Or are you still seeing the same error?
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)"
]
}
If it is the same error, it's likely that you're using the wrong secret webhook key. Are you working with multiple accounts?
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
When you paste this, are you making sure that you're not adding any extra space?
sure
100%
may i ask you since before i was talking to @full radish and he was proposing solutions
They are out for the day, looking on my end
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.
as this error
I see, sorry I read too quickly. I'm talking to a colleague about this. Thank you for your patience.
no problems
Can you log the event please?
sure
1 sec
i'm gonna send you the pastebin link
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Oh, I see. So the issue here is that headers will be on the request and not on the event object. I recommend that you start from scratch again and follow this. guide, https://stripe.com/docs/webhooks/quickstart?lang=node.
Specifically, on line 17.. we're looking at the request const signature = request.headers['stripe-signature']; for the headers.