Set up Stripe Webhook Signature Checking with React and Express

Поделиться
HTML-код
  • Опубликовано: 5 сен 2024
  • How to set up stripe webhooks with React on the front and Node (Express) on the back.
    base code set up: github.com/Vuk...
    finished code: github.com/Vuk...
    Flask Version: • Set up Stripe Payment ...
    ---------------------------------------------------------------------------------------------------
    stripe: stripe.com/

Комментарии • 9

  • @muneebwaqas400
    @muneebwaqas400 10 месяцев назад +1

    But the error is still there

  • @dj0078966
    @dj0078966 3 года назад

    thanks man!

  • @bilawalhussain7777
    @bilawalhussain7777 7 месяцев назад

    How to resolve No signature match error

    • @_newcodes
      @_newcodes 6 месяцев назад

      Managed to solve?

  • @aguerchu
    @aguerchu 2 года назад

    Hi and thanks!
    is this still a solution? rawBody is always undefined for me

    • @_newcodes
      @_newcodes 6 месяцев назад +1

      Managed to solve?

    • @aguerchu
      @aguerchu 6 месяцев назад

      Yes thanks! Raw body worked for me

    • @_newcodes
      @_newcodes 6 месяцев назад

      @@aguerchu How can I obtain the raw body?

    • @aguerchu
      @aguerchu 6 месяцев назад

      ​@@_newcodes I do not know your setup, but hope this helps:
      on index I added this config
      app.use(
      bodyParser.json({
      verify: function (req, res, buf, encoding) {
      req.rawBody = buf;
      },
      })
      );
      app.use(
      bodyParser.urlencoded({
      extended: false,
      verify: function (req, res, buf, encoding) {
      req.rawBody = buf;
      },
      })
      );
      and on the specific endpoint where I was catching the body like this:
      router.post(
      "/stripe_webhooks",
      express.raw({ type: "application/json" }),
      async (req, res) => {
      const sig = req.headers["stripe-signature"];
      const body = req.rawBody;
      const endpointSecret = XXXXXXXXXXXXXXXX;
      let event;

      try {
      event = stripe.webhooks.constructEvent(body, sig, endpointSecret);
      } catch (err) {
      res.status(400).json({ success: false });
      return;
      }
      your code with whatever you want to do using the event var
      });