WaspW
Wasp9mo ago
46 replies
Obinna

Stripe webhook payload not a string/buffer

My OpenSaas application implements Stripe for payment processing. I've followed the steps in the docs, including setting up a middleware to handle calls to the webhook to return raw request (instead of parsed), but when I test it by running "stripe trigger payment_intent.succeeded", I always get the error

"StripeSignatureVerificationError: 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.
[ Server ] Signature verification is impossible without access to the original signed material."

Here's the webhook definition in main.wasp

api stripeWebhooks {
fn: import { stripeWebhooks } from "@src/zigozi/apis",
middlewareConfigFn: import { stripeMiddlewareConfigFn } from "@src/payment/stripe/webhook",
httpRoute: (POST, "/api/stripe-webhooks")
}

and here's the middleware function

middlewareConfig.delete('express.json');
middlewareConfig.set('express.raw', express.raw({ type: 'application/json' }));
console.log('>> stripeMiddlewareConfigFn called');
return middlewareConfig;

How do I fix this issue?
Was this page helpful?