i want to integrate paytm payment gateway with aws lambda serverless

Viewed 21

everthing is working fine just return callback is throwing internal server error

i tried same same code with node js and it's working perfectly.

i think the problem is payment gateway is trying to get the data from html which i am sending in callback but because of some reason it is not able to read that data.

const https = require("https");
const qs = require("querystring");

const checksum_lib = require("./paytm/checksum");
const config = require("./paytm/config");

const path = require("path");

let hello = async (event, _context, callback) => {
  let response;
  if (!JSON.parse(event.body).amount || !JSON.parse(event.body).email || !JSON.parse(event.body).phone) {
    callback(null, { "msg": "Payment failed" });
  } else {
    var params = {};
    params["MID"] = config.PaytmConfig.mid;
    params["WEBSITE"] = config.PaytmConfig.website;
    params["CHANNEL_ID"] = "WEB";
    params["INDUSTRY_TYPE_ID"] = "ECommerce";
    params["ORDER_ID"] = "TEST" + new Date().getTime();
    params["CUST_ID"] = "customer_001";
    params["TXN_AMOUNT"] = JSON.parse(event.body).amount.toString();
    params["CALLBACK_URL"] = "http://localhost:3000/callback";
    params["EMAIL"] = JSON.parse(event.body).email;
    params["MOBILE_NO"] = JSON.parse(event.body).phone.toString();

    checksum_lib.genchecksum(params, config.PaytmConfig.key, function (
      err,
      checksum
    ) {
      // var txn_url = "https://securegw-stage.paytm.in/theia/processTransaction"; // for staging
      var txn_url = "https://securegw.paytm.in/theia/processTransaction"; // for production

      var form_fields = "";
      for (var x in params) {
        form_fields +=
          "<input type='hidden' name='" + x + "' value='" + params[x] + "' >";
      }
      form_fields +=
        "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "' >";

    
      let html = '<html><head><title>Merchant Checkout Page</title></head><body><center><h1>Please do not refresh this page...</h1></center><form method="post" action="' +
        txn_url +
        '" name="f1">' +
        form_fields +
        '</form><script type="text/javascript">document.f1.submit();</script></body></html>';
        

       response = {
        statusCode: 200,
        headers: {
          'Content-Type': 'text/html',
        },
        body: html,
      };
      console.log(response);
      return callback(null, response);
      // return response
    });
  }
  // return callback(null, response);
};

module.exports = { hello };
0 Answers
Related