OccultSlolem
OccultSlolem•2y ago

Stripe webhooks

For the life of me I cannot verify the webhook secret on my Stripe webhook. I've tried console logging the relevant environment variables and they do match. I tried running this action in both the regular Convex runtime and the node.js runtime. I'm really lost 😅
export const verifyStripeWebhookAction = internalAction({
args: {
payload: v.string(),
sig: v.string(),
endpointSecret: v.string(),
},
handler: async (ctx, args): Promise<stripe.Event> => {
const stripeClient = new stripe(process.env.STRIPE_SECRET_KEY!, {
apiVersion: '2022-11-15',
});

let event: stripe.Event;

try {
event = stripeClient.webhooks.constructEvent(args.payload, args.sig, args.endpointSecret);
console.log(event.type);
}
catch {
console.error(`Invalid signature: ${args.sig}`);
console.error(`Expected secret: ${args.endpointSecret}`);
throw new Error('Invalid signature'); // This error keeps getting thrown
}

return event;
}
})
export const verifyStripeWebhookAction = internalAction({
args: {
payload: v.string(),
sig: v.string(),
endpointSecret: v.string(),
},
handler: async (ctx, args): Promise<stripe.Event> => {
const stripeClient = new stripe(process.env.STRIPE_SECRET_KEY!, {
apiVersion: '2022-11-15',
});

let event: stripe.Event;

try {
event = stripeClient.webhooks.constructEvent(args.payload, args.sig, args.endpointSecret);
console.log(event.type);
}
catch {
console.error(`Invalid signature: ${args.sig}`);
console.error(`Expected secret: ${args.endpointSecret}`);
throw new Error('Invalid signature'); // This error keeps getting thrown
}

return event;
}
})
2 Replies
Michal Srb
Michal Srb•2y ago
What does the error thrown by stripe SDK say? (do catch (error) { and log it Also make sure that STRIPE_PAYMENT_ENDPOINT_SECRET is the webhook secret. It should start with whsec_
OccultSlolem
OccultSlolemOP•2y ago
Turned out I accidentally forgot that I had stripe listen forwarding to a different endpoint oops

Did you find this page helpful?