Set up Stripe Webhook Signature Checking with React and Express
HTML-код
- Опубликовано: 5 сен 2024
- How to set up stripe webhooks with React on the front and Node (Express) on the back.
base code set up: github.com/Vuk...
finished code: github.com/Vuk...
Flask Version: • Set up Stripe Payment ...
---------------------------------------------------------------------------------------------------
stripe: stripe.com/
But the error is still there
thanks man!
How to resolve No signature match error
Managed to solve?
Hi and thanks!
is this still a solution? rawBody is always undefined for me
Managed to solve?
Yes thanks! Raw body worked for me
@@aguerchu How can I obtain the raw body?
@@_newcodes I do not know your setup, but hope this helps:
on index I added this config
app.use(
bodyParser.json({
verify: function (req, res, buf, encoding) {
req.rawBody = buf;
},
})
);
app.use(
bodyParser.urlencoded({
extended: false,
verify: function (req, res, buf, encoding) {
req.rawBody = buf;
},
})
);
and on the specific endpoint where I was catching the body like this:
router.post(
"/stripe_webhooks",
express.raw({ type: "application/json" }),
async (req, res) => {
const sig = req.headers["stripe-signature"];
const body = req.rawBody;
const endpointSecret = XXXXXXXXXXXXXXXX;
let event;
try {
event = stripe.webhooks.constructEvent(body, sig, endpointSecret);
} catch (err) {
res.status(400).json({ success: false });
return;
}
your code with whatever you want to do using the event var
});