OccultSlolemO
Convex Communityโ€ข3y agoโ€ข
3 replies
OccultSlolem

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;
  }
})
Was this page helpful?