paytm / Paytm_Node_Checksum

https://developer.paytm.com/docs/checksum/#node
14 stars 66 forks source link

Whenever the Merchant Key is parsed in the checksum.js in the getStringByParams() function the segement params[key].toLowerCase() function throws a type error. Is there any need of that, seems not needed there. After removing the fragmnet the code snippet runs. Any insights? #4

Open dasgupta002 opened 3 years ago

dasgupta002 commented 3 years ago

paytm_checksum

shamssahal commented 2 years ago

Most likely you are there is property in your paytm object which is not String. Check your txnAmount property.

bvsk279 commented 2 years ago

Kindly pass the body / paytmParams object to generateSignature Method as a String

So for example, If you're using Node / JS just pass the body object as PaytmChecksum.generateSignature(JOSN.stringify(body), Your_Merchent_KEY)

sameerjoshi commented 1 year ago

Hi There,

This is still an in issue in the case there is a nested object. Although JSON.stringify() solves the checksum generation issue, but the checksum does not match when the request is sent to the API.

function collectRequest(amount) {
  const head = {
    version,
    requestTimeStamp: time,
    channelId,
    checksum: "",
  };

  const body = {
    paytmMid,
    paytmTid,
    transactionDateTime: time,
    merchantTransactionId: moment().unix().toString(),
    transactionAmount: (amount * 100).toString(),
    merchantExtendedInfo: {
      autoAccept: true,
    },
  };

  var paytmChecksum = PaytmChecksum.generateSignature(
    JSON.stringify(body),
    merchantKey
  );
  paytmChecksum
    .then(function (result) {
      head.checksum = result;
      const request = {
        head: {
          ...head,
        },
        body: {
          ...body,
        },
      };
      axios
        .post(`${url}/request`, request, {
          headers: {
            "Content-Type": "application/json",
          },
        })
        .then(function (response) {
          console.log(response.data.body);
        })
        .catch(function (error) {
          console.log(error);
        });
    })
    .catch(function (error) {
      console.log(error);
    });
}
collectRequest(100);

The above code produces the following response

{
  merchantTransactionId: '1674033160',
  paytmMid: 'XXXXXXXXXXX',
  paytmTid: 'XXXXXXX',
  resultInfo: {
    resultStatus: 'FAIL',
    resultCode: 'F',
    resultMsg: 'Invalid checksum',
    resultCodeId: '0330'
  }
}