#satyra1_code
1 messages ¡ Page 1 of 1 (latest)
đ 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/1277961152588025977
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi there!
what are you trying to do? and what's the exact error message you see?
note that your code was truncated, so I can only see the beginning.
or ```HTTP status code
401 (Unauthorized)
Unauthorized```
or ```HTTP status code
400 (Bad Request)
Webhook Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
If a webhook request is being forwarded by a third-party tool, ensure that the exact request body, including JSON formatting and new line style, is preserved.
Learn more about webhook signing and explore webhook integration examples for various frameworks at https://github.com/stripe/stripe-node#webhook-signing```
import express, { Request, Response, NextFunction } from "express";
import morgan from "morgan";
import routes from "./src/routes";
import "./src/setup/mongoo";
import stripe from "./src/utils/stripe";
const app = express();
const port = process.env.PAYMENT_PORT ?? 3004;
// Use JSON parser for all non-webhook routes
app.use((req, res, next) => {
if (req.originalUrl === '/api/v1/webhook') {
console.log('Webhook route detected');
express.raw({ type: 'application/json' })(req, res, next); // Use raw body parser for Stripe webhooks
} else {
express.json()(req, res, next); // Use JSON parser for all other routes
}
});
app.use(morgan("dev"));
// Routes
app.use("/api/v1/", routes);
app.post('/webhook', express.raw({ type: 'application/json' }), async (request, response) => {
const event = request.body;
// await stripe.webhooks.constructEvent(request.body, request.headers['stripe-signature'], process.env.SPLIT_COSTS_STRIPE_WEBHOOK_SECRET)
// Handle the event
switch (event.type) {
case 'payment_intent.created':
const paymentIntentCreated = event.data.object;
// Then define and call a method to handle the successful payment intent.
// handlePaymentIntentSucceeded(paymentIntent);
break;
case 'payment_intent.succeeded':
const paymentIntentSucceeded = event.data.object;
console.log(paymentIntentSucceeded)
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handlePaymentMethodAttached(paymentMethod);
break;
// ... handle other event types
default:
console.log(`Unhandled event type ${event.type}`);
}
// Return a response to acknowledge receipt of the event
response.json({ received: true });
});```
getting a signature error is quite common. please go though this guide: