PayUMoney integration with nodejs

1.1k Views Asked by At

I am trying to integrate payumoney payment gateway with nodeJs . I am not able to redirect the user to payment page it shows some error occurred page . There is no error in console . Keys are stored in different file . enter image description here

Here is my code for payment gateway

router.post("/payment_gateway/payumoney", isLoggedIn, (req, res) => {
  req.body.txnid = uniqid.process();
  req.body.email = req.user.email;
  req.body.firstname = req.user.username;
  //Here save all the details in pay object
  const pay = req.body;
  const hashString =
    process.env.MERCHANT_KEY + //store in in different file
    "|" +
    pay.txnid +
    "|" +
    pay.amount +
    "|" +
    pay.productinfo +
    "|" +
    pay.firstname +
    "|" +
    pay.email +
    "|" +
    "||||||||||" +
    process.env.MERCHANT_SALT; //store in in different file

  const sha = new jsSHA("SHA-512", "TEXT");
  sha.update(hashString);
  //Getting hashed value from sha module
  const hash = sha.getHash("HEX");

  //We have to additionally pass merchant key to API

  pay.key = process.env.MERCHANT_KEY; //store in in different file;
  pay.surl = "http://localhost:3000/payment/success";
  pay.furl = "http://localhost:3000/payment/fail";
  pay.hash = hash;
  //Making an HTTP/HTTPS call with request
  request.post(
    {
      headers: {
        Accept: "application/json",
        "Content-Type": "application/json",
      },
      url: "https://sandboxsecure.payu.in/_payment", //Testing url
      form: pay,
    },
    function (error, httpRes, body) {
      if (error) {
        console.log(error);
        res.send({
          status: false,
          message: error.toString(),
        });
      }

      if (httpRes.statusCode === 200) {
        res.send(body);
      } else if (httpRes.statusCode >= 300 && httpRes.statusCode <= 400) {
        res.redirect(httpRes.headers.location.toString());
      }
    }
  );
});

1

There are 1 best solutions below

0
On

It works for me after change the url.

test url: https://test.payu.in/_payment live ur: https://secure.payu.in/_payment;