How to get the notificationCode from the Pagseguro notification URL?

Asked

Viewed 52 times

0

In the details of the notification I have:

The following parameters were sent via POST:

notificationType=transaction

notificationCode=D666218281808180F60334A66F8340B434F9

{
  "request": {
    "url": "https://brunoiglesias.eng.br/notification",
    "parameters": {
      "notificationType": "transaction",
      "notificationCode": "D666218281808180F60334A66F8340B434F9"
    },
    "headers": {},
    "method": "POST"
  },
....

In my Nodejs API I have the following route:

routes.post('/notification', PagSeguro.notification);

With the following function:

    notification(request, response){
        console.log("notificação de mudança de status");
        console.log("request");
        console.log(request.parameters);
        console.log("request body");
        console.log(request.body);
        console.log("request query");
        console.log(request.query);
        console.log("request params");
        console.log(request.params);
        return response.status(200).json({});
    }

However I have as output the log:



Feb 05 22:18:13   {}
Feb 05 22:18:13   request params
Feb 05 22:18:13   {}
Feb 05 22:18:13   request query
Feb 05 22:18:13   {}
Feb 05 22:18:13   request body
Feb 05 22:18:13   undefined
Feb 05 22:18:13   request
Feb 05 22:18:13   notificação de mudança de status

1 answer

0


You will need to use the body-parser to read the body of a request POST

var bodyParser = require('body-parser')
app.use(bodyParser.json())

Browser other questions tagged

You are not signed in. Login or sign up in order to post.