#dodo54-webhook
1 messages ยท Page 1 of 1 (latest)
cli
And I followed this tutorial :
https://stripe.com/docs/payments/checkout/fulfill-orders#create-event-handler
Are you using the signing secret (endpointSecret) the CLI spits out when you do stripe listen?
yup
And it's definitely defined as a variable in your handler? I can't see it in what you shared
Can you log it out successfully
It is defined on the top :
const endpointSecret = process.env.STRIPE_ENDPOINT_SECRET;
And my stripe :
const stripe = require("stripe")(process.env.STRIPE_SECRET_KEY);
And is the value you log for endpointSecret correct to what the CLI states?
yeah it is successfully printing when I log
yup
There's so many quirks with this because constructEvent basically expects the raw payload and a lot of these frameworks parse it before you can even access it ๐ซ
Our actual webhook docs use express.raw instead of bodyParser: https://stripe.com/docs/webhooks/quickstart
How can I turn it to raw
Could you try switching that?
Sorry to butt in but I've noticed some web servers don't handle case sensitivity in http headers well. Noticed you have stripe-signature - try Stripe-Signature
Now I am receiving unable to extract timestamp and signatures from header
by trying this way
router.post(
"/webhook",
express.raw({ type: 'application/json' }),(req, res) => {
const payload = req.body;
const sig = req.headers["stripe-signature"];
let event;
try {
event = stripe.webhooks.constructEvent(payload, sig, endpointSecret);
res.status(200);
} catch (e) {
console.log(e)
return res.status(400).send(`Webhook Error: ${e.message}`);
}
if (event.type === 'checkout.session.completed') {
const session = event.data.object;
// Fulfill the purchase...
fulfillOrder(session);
}
res.status(200);
}
);
same stripe signature error
In 90% of cases like this, the secret value is wrong. Can you share an Event ID?
how to grab that ?
is it in event = stripe.webhooks.constructEvent ?
my secret key value is also right
In the CLI, you'll see the log of the events it's receiving (evt_xxx)
yeah I am seeing many id
customer created , invoice finalized ..... checkout.session.completed
invoice.payment.succeedeed
Can you share one?
Hi there
stepping in here as ynnoj needs to step away soon
Give me a moment to catch up and I'll respond as soon as I can
Thanks ๐
Seems like the event id is invalid
what version of express are you running?
No I mean the express JS package
express - 4.17.1
okay, on my test app I'm running the same version and I remember I had to change my code to this
instead of setting bodyParser property inline
app.use('/stripe-events', express.raw({type: "*/*"}))
and the route was just
app.post('/stripe-events', async (req,res) => {
I already tried this
Same error
I used this solution from stackoverflow :
It worked but
then after sometime I get this from cli :
2022-06-24 19:02:51 [ERROR] Failed to POST: Post "http://localhost:5000/api/webhook": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
here is code :
router.post(
"/webhook",
bodyParser.raw({ type: 'application/json' }),(req, res) => {
const payload = req.body;
const sig = req.headers["stripe-signature"];
let event;
try {
event = stripe.webhooks.constructEvent(payload, sig, "whsec_7a0b4901079792abb5164e1e0aa7c1262588fdd325ba86600148d2cef8076473");
res.status(200);
} catch (e) {
console.log(e)
return res.status(400).send(`Webhook Error: ${e.message}`);
}
if (event.type === 'checkout.session.completed') {
const session = event.data.object;
// Fulfill the purchase...
fulfillOrder(session);
}
res.status(200);
}
);
can you set res.status(200).end()
res.status(200).end() ? right ?
yup