0

Tried 2 Node.js packages:
https://www.npmjs.com/package/payumoney_nodejs
https://www.npmjs.com/package/payumoney-node

Debugging on localhost.
Debugged in the index.js file under the node_modules in each package.

params {
  key: 'x1FanfbP',
  salt: 'Vs2GrDyaMQ',
  service_provider: 'payu_paisa',
  hash: '65f75ced566e2d76dbc6153a277c25f591fc3c0a00a8f51a0699f609d5cbbc94dc7acd5d3be5fe0c0a855c4c6dc7faef49d8b6a1d77dd09398058f800bab068d',
  firstname: '',
  lastname: '',
  email: 'xxxxxxxx@xxxxx.xxx',
  phone: XXXXXXXXXX,
  amount: '100',
  productinfo: '',
  txnid: '5b51d253-5d6e-4512-951a-cd6d05bf9e6b',
  surl: 'http://localhost:3000/member/contribution/success',
  furl: 'http://localhost:3000/member/contribution/failure'
}

request.post(this.payUmoneyURL, form: params, headers: this.headers }, 
    function(error, response, body) {
        if (!error) {
            var result = response.headers.location;
            callback(error, result);
        }
});


request.post(payment_url[this.mode] + API.makePayment, { form: params, headers: this.headers }, function(error, response, body) {
        if (!error) {
            var result = response.headers.location;
            callback(error, result);
        }
});

Response of response.headers:

response.headers {
    date: 'Fri, 28 Jun 2019 12:06:35 GMT',
    server: 'Apache',
    'x-powered-by': 'PHP/7.2.14',
    p3p: 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"',
    'set-cookie': [ 'PHPSESSID=naopga57qf58vl0hdfj5krq4n5; path=/; domain=.payu.in' ],
    expires: 'Thu, 19 Nov 1981 08:52:00 GMT',
    'cache-control': 'no-store, no-cache, must-revalidate',
    pragma: 'no-cache',
    vary: 'Accept-Encoding',
    'content-length': '3129',
    connection: 'close',
    'content-type': 'text/html; charset=UTF-8'
}

The above does not have location key like response.headers.location

Can someone help to know why location is not returned? Is it because of development on local machine? If yes, then how to test it on localhost?

Any help is appreciated.

Kunal Dethe
  • 1,254
  • 1
  • 18
  • 38
  • why do you need a location? – narayansharma91 Jun 28 '19 at 12:34
  • In the package urls provided in the question says the API is suppose to return a URL which needs to be sent to the UI (Angular in my case) and then redirect to that URL. – Kunal Dethe Jun 28 '19 at 13:11
  • In request body have you set surl and furl as per the documentation? – user269867 Jul 02 '19 at 16:20
  • @user269867 Yes, have set those values. Give me some time, will provide the `requestBody` data sent to the `payUMoney.pay()` and `payumoney.makePayment()` call. – Kunal Dethe Jul 03 '19 at 09:24
  • 1
    also if you can share the output of ```console.log(response)``` – user269867 Jul 03 '19 at 16:55
  • @user269867 I have updated the question with `params` value that is sent to the API call. The log of `response` key is very big and so I have only provided the value of `response.headers`. – Kunal Dethe Jul 03 '19 at 17:13
  • 1
    It say "You will get a link in response to redirect to payUMoney" , you are checking in headers but it might be in the response itself. refer article - https://medium.com/@swapnilnakhate/payumoney-payment-gateway-integration-with-nodejs-f715e5fc25a – user269867 Jul 03 '19 at 17:18
  • I have searched in the `response` but there is no such key as `location`. – Kunal Dethe Jul 03 '19 at 17:28
  • Check this out https://stackoverflow.com/questions/39020385/fetch-api-not-returning-the-location-header – Shubham Sharma Jul 03 '19 at 20:15
  • @KunalDethe do you see "payulink" in response? – user269867 Jul 05 '19 at 19:16
  • @user269867 Yes, its working now. The issue was with the missing parameters data. Have mentioned it in detail in the answer below. Thank you for all the replies. Helped to look around the entire `response` object searching for the error. – Kunal Dethe Jul 06 '19 at 13:55
  • glad it worked !may be you can upvote the comment – user269867 Jul 08 '19 at 04:20

1 Answers1

0

It seems like a very silly mistake made but didn't know the area as where to look for the error in the response key before.

After going through the entire response object found that there is a body key sent at the very end of the response object which has HTML string. This HTML specifies if any error has occurred and what exactly it is.

In my case it were the missing mandatory fields:

Error Reason
One or more mandatory parameters are missing in the transaction request.

Corrective Action
Please ensure that you send all mandatory parameters in the transaction request to PayU.

Mandatory parameters which must be sent in the transaction are: 
key, txnid, amount, productinfo, firstname, email, phone, surl, furl, hash.

The parameters which you have actually sent in the transaction are: 
key, txnid, amount, surl, hash, email, phone.

Mandatory parameter missing from your transaction request are: 
productinfo, firstname.

Please re-initiate the transaction with all the mandatory parameters.

After passing data for the missing parameters, received the url in the response.headers.location key as expected.

Integration is working as expected now.

Kunal Dethe
  • 1,254
  • 1
  • 18
  • 38