0

I have read the stripe documentation regarding processing of payments and so on, but it doesn't work for me. Here is what I am trying to do:

const endpointSecret = 'whsec_*';

router.post('/webhook', bodyParser.raw({type: 'application/json'}), (request, response) => {
  const payload = request.body;
  const sig = request.headers['stripe-signature'];

  let event;

  try {
    event = stripe.webhooks.constructEvent(payload, sig, endpointSecret);
    console.log(event)
  } catch (err) {
    return response.status(400).send(`Webhook Error: ${err.message}`);
  }

  // Handle the checkout.session.completed event
  if (event.type === 'checkout.session.completed') {
    const session = event.data.object;

    // Fulfill the purchase...
    fulfillOrder(session);
  }

  response.status(200);
});

function that I am calling, just in case

const fulfillOrder = (session) => {
  // TODO: fill me in
  console.log("Fulfilling order", session);
}

But when I try to trigger an event, I don't see no messages in the Terminal of the server. This makes me unsecure if it is working or no, so I can't do any further actions. Here is a screenshot from the dashboard, just to prove that it is all running up as needed, in my opinion. enter image description here Stripe-CLI

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
  • To me it looks like your code is failing in the try...catch block, and issues a 400 response, which we can see in your logs. So I guess stripe.webhooks.constructEvent is generating an error. Can you log it and find out what it is? – James Jul 05 '22 at 20:06
  • please telp me what should i write in the terminal to make it run? – Cristian Babalau Jul 05 '22 at 20:09
  • @James send the command pls – Cristian Babalau Jul 05 '22 at 20:14
  • in your `catch(err)` block you could try `console.log(err.message)` – James Jul 05 '22 at 20:22
  • oh, cool, i see. No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing – Cristian Babalau Jul 05 '22 at 20:55
  • Now you have the error, you can search it, for example https://stackoverflow.com/questions/53899365/stripe-error-no-signatures-found-matching-the-expected-signature-for-payload – James Jul 05 '22 at 21:01

0 Answers0