#gan_webhooks

1 messages ¡ Page 1 of 1 (latest)

visual matrixBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1283746152033816649

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

vague horizon
#

What does your webhook code look like?

analog turtle
#

hi, Hope you having a do day

analog turtle
vague horizon
#

Not here I'm afraid

analog turtle
#

sure let me share it to you

#

//router.js
router.post('/webhook',express.raw({ type:'application/json' }), paymentUpdation);

vague horizon
#

Where are you getting your whsec_xxx from?

analog turtle
#

wait i send you the controller wait ahh

#

const paymentUpdation = async (req, res) => {
try {
const sig = req.headers['stripe-signature'];

    let event;

    const storeId = req.body.data.object.metadata.storeId;
    let stripeKey = "";
    const store = await Store.findOne({ _id: storeId, isDeleted: 0 });
    if (!store) {
        return res
            .status(400)
            .send({ message: "Store not found", success: false });
    }
    if (
        store.generalSettings &&
        store.generalSettings.Integrations &&
        store.generalSettings.Integrations.enableStripe === true
    ) {
        stripeKey = store.generalSettings.Integrations.stripeSecretKey;
    } else {
        return res.status(400).send({
            message:
                "Stripe secret key not found or Stripe integration not enabled for the store",
            success: false,
        });
    }

    const stripe = Stripe(stripeKey);
    const endpointSecret = store.generalSettings.Integrations.stripeEndPointKey;
    try {
        // Verify the signature of the event
        event = stripe.webhooks.constructEvent(req.body, sig, endpointSecret);
    } catch (err) {
        console.error('Webhook signature verification failed.', err.message);
        return res.status(400).send(`Webhook Error: ${err.message}`);
    }
analog turtle
vague horizon
#

Right, but where did you get that value? Is it the correct secret for the webhook from the Dashboard?

vague horizon
#

Can you share the last 4 digits?

analog turtle
#

jbda

vague horizon
#

Are you using any other middleware (app.use()) in your Express app?

analog turtle
#

yes

vague horizon
#

Can you share the details

analog turtle
#

app.use("/v1/api/online/payment",onlinePaymentRoutes);

app.use(express.json({ limit: "4mb" }));

#

both on Index.js

vague horizon
#

Yeah I suspect that global middleware is the issue

#

It'll be malforming the event payload which will break the constructEvent method

analog turtle
#

anyother possibilites?

vague horizon
#

Can you try and remove that global middleware? Or at least refactor your code to it doesn't apply to your webhook route