braintree / braintree_node

Braintree Node.js library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
334 stars 104 forks source link

Not able to parse webhook notification in nodejs #184

Closed sohambarc closed 3 years ago

sohambarc commented 3 years ago

I have trying to test the webhook notification in node js.I have tried with the below code.However the req.body I am getting undefined. I am using ngrok to generate the https webhook link.

app.post("/webhooks", (req, res) => {
  gateway.webhookNotification.parse(
    req.body.bt_signature,
    req.body.bt_payload,
  ).then(webhookNotification => {
      console.log("[Webhook Received " + webhookNotification.timestamp + "] | Kind: " + webhookNotification.kind);

      // Example values for webhook notification properties
      console.log(webhookNotification.kind); // "subscriptionWentPastDue"
      console.log(webhookNotification.timestamp); // Sun Jan 1 00:00:00 UTC 2012
      res.status(200).send();
  });
});

General information

crookedneighbor commented 3 years ago

Please reach out to our support team so we can help you debug your integration: https://help.braintreepayments.com/

(though my guess is that you're missing the body parser middleware for your express app)

sohambarc commented 3 years ago

@crookedneighbor I had body-parser already .But I forgot to add the url encoded format in the middleware. By default it accept only application/json format I guess.

@UseBefore(urlencoded({ extended: false }))

Thanks for the suggestion,it saved my day.