0

This is my redirect/callback URL: http://localhost:3000/users/servicespage/callback?payment_id=MOJO7717005A25534569&payment_request_id=378e45f1a7d944299a5185a9eea29c83

I want to have values of:

payment_id : MOJO7717005A25534569

payment_request_id : 378e45f1a7d944299a5185a9eea29c83

I am new to Nodejs and trying to use below approach, but it works only for 1st value when '?' sign is not there, so basically below approach is not giving any result:

router.get('/callback/:payment_id',function(req,res)
{
console.log(req.params.payment_id);
return;
}

2 Answers2

1

/callback/:payment_id route means all the url with /callback/ANY.

but you want to query string data and /callback url

const url = require('url');
router.get('/callback',function(req,res)
{     
   const query = (url.parse(req.url, true)).query; // get query string data
   console.log(query);
   // ......
}

https://scotch.io/tutorials/learn-to-use-the-new-router-in-expressjs-4

Tushar Gupta - curioustushar
  • 54,013
  • 22
  • 95
  • 103
1

What you want is query string but not URL matching.

router.get('/callback',function(req,res)
{
console.log(req.query.payment_id);
console.log(req.query.payment_request_id );
return;
}
subaru710
  • 507
  • 3
  • 3
  • Hi subaru710, thanks for your help, can you provide me some links/resources where I can read more about them. – santoshkhembram Jul 17 '17 at 15:39
  • Hi killmal, if you're using express, here is the API reference: http://expressjs.com/en/4x/api.html, which includes the information about req.query. And you can also find some tutorial on that website. – subaru710 Jul 17 '17 at 15:53