#Zetsuman
1 messages · Page 1 of 1 (latest)
hi! what's your exact question?
I'm using this API
return this.stripe.webhooks.constructEvent( payload, signature, webhookSecret, );
Should I use it if I already have body in request object?
not sure what "already have body in request object" means
I'd suggest reading the docs linked in the error message!
and/or share your full code here. And check the reply someone else posted to you in the main channel.
If you are using expressjs you either have an expressjson middleware or body parser middleware, you need to disable the middleware for the stripe webhook route or pass in an object in there that creates a new variable on the request that you can use
I'm using Nest JS
where I can attach code parts?
It depends on your code structure but look for a json middleware for nextjs- you should be able to modify the request where you can add additional property to the request object like rawBody (which is the buffer stripe is expecting) that you would be able to use
Or depending on how your controllers are setup in nestjs- you may be able to disable there parsing for that request
Give me a minute, i'll create codesanbox
Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).
raw-body.middleware.ts
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response } from 'express';
import * as bodyParser from 'body-parser';
@Injectable()
export class RawBodyMiddleware implements NestMiddleware {
use(req: Request, res: Response, next: () => any) {
bodyParser.raw({type: '/'})(req, res, next);
}
}