#ctodan
1 messages · Page 1 of 1 (latest)
I don't think we have examples for specifically typescript node. Is there something you are getting stuck on while following that doc?
was tryna figure out how to do the signing check
but actually just found it
is this signing secret persitent across environment?
aka one secret for live and one for test?
It is per webhook, so you'll need to use the right one for whichever endpoint you created
The CLI will pring out its secret when it makes one. For webhooks that you created in your dashboard, you can go to the endpoint's page and click "Reveal" under "Signing Secret"
got it thanks
In this guide btw, i think there is a minor bug:
app.post('/webhook', express.raw({type: 'application/json'}), (request, response) => {
const sig = request.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(request.body, sig, endpointSecret);
}
catch (err) {
response.status(400).send(Webhook Error: ${err.message});
}
// Handle the event
switch (event.type) {
case 'payment_intent.succeeded':
const paymentIntent = event.data.object;
console.log('PaymentIntent was successful!');
break;
case 'payment_method.attached':
const paymentMethod = event.data.object;
console.log('PaymentMethod was attached to a Customer!');
break;
// ... handle other event types
default:
console.log(Unhandled event type ${event.type});
}
// Return a response to acknowledge receipt of the event
response.json({received: true});
});
pretty sure if there is a failure in constructing the event, the 400 response gets sent, but then the code continues to execute switching on a broken event
Have you run that test code to confirm? I actually thought that send ended execution of that function. Thanks for flagging though, I can test to confirm.
I’m gonna test that now as I build it out
I always thought that you need to return the response or execution continues
Yeah, now seeing that in docs when doing a cursory look.
Please let me know what you see when you test! I'm boucning between a couple threads right now so I haven't had a chance to test yet
No probs
Can let you know in a few
ok just tested, its def a bug
end up getting an error trying to read type on undefined event
Awesome, thanks for catching! I will report this so we can fix it
no probs! One of my engineers commented on one of my PRs about that a month or two ago. Basically noted its best practice to return the res.send or execution will continue after