Giter Site home page Giter Site logo

Comments (2)

Sky-FE avatar Sky-FE commented on June 12, 2024

@JustDenP
Hey, I encountered the same issue as well. Could you please let me know how you resolved it?

from nestjs.

JustDenP avatar JustDenP commented on June 12, 2024

@Sky-FE Hi, the issue is related to undefined rawBody in request, make sure you set rawBody for these webhooks properly.

I use middleware for the specific endpoints:
raw-body.middleware.ts

import { RawBodyRequest } from '@nestjs/common';
import { json, Request, Response } from 'express';

export interface RawBodyMiddlewareOptions {
  limit: string;
  rawBodyUrls: string[];
}

export function rawBodyMiddleware(options: RawBodyMiddlewareOptions): unknown {
  const rawBodyUrls = new Set(options.rawBodyUrls);

  return json({
    ...options,
    verify: (request: RawBodyRequest<Request>, _: Response, buffer: Buffer) => {
      if (rawBodyUrls.has(request.url) && Buffer.isBuffer(buffer)) {
        request.rawBody = Buffer.from(buffer);
      }

      return true;
    },
  });
}

Then in your main.ts file you can use it before body parser if you have it

  app.use(
    rawBodyMiddleware({
      limit: '5mb',
      rawBodyUrls: ['/stripe/webhook', '/payment/test'],
    }),
  );
  app.use(bodyParser.json({ limit: '5mb' }));
  app.use(bodyParser.urlencoded({ limit: '5mb', extended: true }));

You can create any post endpoint to test it and make sure it is working and rawBody is there.

After that, if you will face another error "No signatures found matching the expected signature for payload", make sure to set up accountTest if you are using local stripe cli. I have it like this

webhookConfig: {
    decorators: [SkipThrottle()],
    requestBodyProperty: 'rawBody',
    stripeSecrets: {
      account: configService.get('stripe.account', { infer: true }),
      accountTest: configService.get('stripe.account', { infer: true }),
    },
  },

If you still have issues, you can write here, I also spent the whole day so set it right haha

from nestjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.