#shrey

1 messages · Page 1 of 1 (latest)

trim stagBOT
sharp pendant
#

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?

unborn panther
#

Nope, just normal nextjs stuff

sharp pendant
#

Hm are you running a vpn on your computer?

unborn panther
#

No

sharp pendant
#

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?

unborn panther
#

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 ...

sharp pendant
#

One problem at a time

#

Can you try this:

unborn panther
#

yes please wait

sharp pendant
#

No rush. We have many threads we're juggling on here

unborn panther
#

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

sharp pendant
#

Can you share the failed to post error?

#

Like the error message json

unborn panther
#

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)
sharp pendant
#

Oh

#

Can you try hitting /api/stripe-hooks with postman?

#

Curious about that endpoint specifically since that's the one causing issues

unborn panther
#

There is no response, postman is stuck on the "Sending request..." screen

sharp pendant
#

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

unborn panther
#
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

sharp pendant
#

Can you share the code for your /api/stripe-hooks endpoint?

unborn panther
#
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;
sharp pendant
#

What is that buffer for?

#

Assuming that's modify the body

unborn panther
#

Yes, according to the article I'm following, we need to get the req.body in buffer format before sending it

sharp pendant
#

I've never seen it done that way

#

I would follow our official docs

unborn panther
#

You guys don't have code for nextjs

sharp pendant
#

Ah I see

#

Are you using the webhook signing secret from the cli?

unborn panther
#

Ahhhh shitttt. No. I'm using the one I got for a live URL

sharp pendant
#

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)

unborn panther
#

Yea, THANK YOU SOOO MUCHHHHHH

#

WORKED

sharp pendant
#

No problem. Glad you got it figured out