#shrey
1 messages · Page 1 of 1 (latest)
So when you trigger the events via the cli, you don't get the StripeSignatureVerificationError in your server logs?
Do you see anything in your server logs when you get those context deadline exceeded errors?
Nope, just normal nextjs stuff
I was following along this article, if it helps:
https://www.codedaily.io/tutorials/Stripe-Webhook-Verification-with-NextJS
Hm are you running a vpn on your computer?
No
Can you try hitting that same local endpoint with Postman or some other local http client on your computer to see if that also times out?
the error it gives when i trigger thru stripe cli, is the card_not_supported error. I need to use an Indian card, how do I specify which card to use while triggering?
and also the Failed to POST errors ...
yes please wait
No rush. We have many threads we're juggling on here
okay 🙂
When I hit the /create-checkout-session route, I got payment_intent.created on my console, and after a few seconds I also got the same Failed to Post error
yes wait
2023-04-14 19:59:15 --> payment_intent.created [evt_1MwnckJZ5SfvqGzXsq3apGuZ]
2023-04-14 19:59:45 [ERROR] Failed to POST: Post "http://localhost:3000/api/stripe-hooks": context deadline exceeded (Client.Timeout exceeded while awaiting headers)
Oh
Can you try hitting /api/stripe-hooks with postman?
Curious about that endpoint specifically since that's the one causing issues
There is no response, postman is stuck on the "Sending request..." screen
Ah
So it's not a problem with stripe then
The timeout error we throw is because of the same issue
A response isn't returned in a timely manner from your endpoint
Likely a localhost connectivity/firewall issue
StripeSignatureVerificationError: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
How do I convert the req.body in the correct format? I tried various functions which I found as solutions over the internet but everytime I'm getting this error
Can you share the code for your /api/stripe-hooks endpoint?
import Stripe from "stripe";
async function buffer(readable) {
const chunks = [];
for await (const chunk of readable) {
chunks.push(typeof chunk === "string" ? Buffer.from(chunk) : chunk);
}
return Buffer.concat(chunks);
}
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY, {
apiVersion: "2020-08-27",
});
const webhookSecret = process.env.STRIPE_SIGNING_SECRET;
export const config = { api: { bodyParser: false } };
const handler = async (req, res) => {
if (req.method === "POST") {
console.log(req.body);
const buf = await buffer(req);
const sig = req.headers["stripe-signature"];
let event;
console.log(buf, sig, webhookSecret);
try {
event = stripe.webhooks.constructEvent(buf, sig, webhookSecret);
} catch (err) {
console.log("invisible error");
console.log(err);
res.status(400).send(`Webhook Error: ${err.message}`);
return;
}
res.json({ received: true });
} else {
res.setHeader("Allow", "POST");
res.status(405).end("Method Not Allowed");
}
};
export default handler;
Yes, according to the article I'm following, we need to get the req.body in buffer format before sending it
You guys don't have code for nextjs
Ahhhh shitttt. No. I'm using the one I got for a live URL
Ah
Yeah you need to use the test endpoint's secret if it's a deployed test version and the cli's webhook secret if it's local (with stripe listen)
No problem. Glad you got it figured out