#tungtn1099
1 messages ยท Page 1 of 1 (latest)
I did try it in my controller class, it returns undefined
This means your request body is not provided to you. I don't know how your framework works, but you will need to check how to get the request body yourself.
That traces back to one of my old error.
I got Webhook payload must be provided as a string or a Buffer (https://nodejs.org/api/buffer.html) instance representing the _raw_ request body.Payload was provided as a parsed JavaScript object instead.
Seems like the request is parsed before getting to .constructEvent
I tried Buffer.from(req.body), getRawBody(req) from raw-body package, and @UseBefore(express.raw()) from routing-controllers
Sorry, I think Discord had some issues, we're back now.
What framework are you using?
I'm using nodejs with typescript
I mean, what web framework? Like express
oh yeah express
Are you sure this condition is executed: req.originalUrl === '/api/premium/stripe-handler'?
You might need to handle your webhook at the top of your file, so no middleware affects the payload.
like this?
private initializeMiddlewares() {
this.app.use((req: any, res: any, next: any) =>{
if(req.originalUrl === '/api/premium/stripe-handler'){
console.log(123);
next();
}
else{
express.json()(req, res, next);
express.urlencoded({ extended: true })(req, res, next);
}
});
this.app.use(morgan(config.get('log.format'), { stream }));
this.app.use(hpp());
this.app.use(compression());
// this.app.use(express.json());
// this.app.use(express.urlencoded({ extended: true }));
this.app.use(cookieParser());
this.app.use(express.static('public'));
this.app.use(cors());
this.app.use(helmet());
this.app.use(
session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: { secure: true },
}),
);
}
because this one is in a different file from the controller
looks reasonable
it still returns undefined when i console.log(req.body)
generally I'd suggest downloading and using the sample project from https://github.com/stripe/stripe-node/tree/master/examples/webhook-signing, confirming that works, and then adding your own code to it .
alright i'll try
i got the same problem here ๐
did you update the STRIPE_WEBHOOK_SECRET in the .env file to be the correct one for your endpoint(it's printed whsec_xxx from where you are running stripe listen ... )?