title: Paytm payment gateway java web integration - jsp sample inside servlet call not working sometimes because of javascript from submission
body: <p>I am using Paytm for payment gateway integration, and I am using the sample kit which is an example of the <a href="https://github.com/Paytm-Payments/Paytm_Web_Sample_Kit_Java/tree/master/Sample%20Kit" rel="nofollow noreferrer">JSP implementation</a>.</p>
  
  <p><strong>What I am doing is putting this code inside my servlet method as follows:</strong></p>
  
  <pre><code>int appointmentId = rst_appnt.getInt(1);//unique id 
  TreeMap&lt; String, String&gt; parameters = new TreeMap&lt;String, String&gt;();
  parameters.put("ORDER_ID", String.valueOf(appointmentId));
  parameters.put("CUST_ID", "CUST001");
  parameters.put("INDUSTRY_TYPE_ID", "Retail");
  parameters.put("CHANNEL_ID", "WEB");
  //parameters.put("TXN_AMOUNT", String.valueOf(rst_appnt.getDouble(3)));
  parameters.put("TXN_AMOUNT", "10");
  parameters.put("MID", "WorldP64425807474247");
  parameters.put("CHANNEL_ID", "WEB");
  parameters.put("INDUSTRY_TYPE_ID", "Retail");
  parameters.put("WEBSITE", "worldpressplg");
  parameters.put("MOBILE_NO", "9876543210");
  parameters.put("EMAIL", "test@gmail.com");
  parameters.put("CALLBACK_URL", "http://localhost:8080/Test/pgResponse.jsp");
  String checkSum = CheckSumServiceHelper.getCheckSumServiceHelper().genrateCheckSum(PaytmConstants.MERCHANT_KEY, parameters);
  
  StringBuilder outputHtml = new StringBuilder();
  outputHtml.append("&lt;!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'&gt;");
  outputHtml.append("&lt;html&gt;");
  outputHtml.append("&lt;head&gt;");
  outputHtml.append("&lt;title&gt;Merchant Check Out Page&lt;/title&gt;");
  outputHtml.append("&lt;/head&gt;");
  outputHtml.append("&lt;body&gt;");
  outputHtml.append("&lt;center&gt;&lt;h1&gt;Please do not refresh this page...&lt;/h1&gt;&lt;/center&gt;");
  outputHtml.append("&lt;form method='post' action='https://pguat.paytm.com/oltp-web/processTransaction' name='f1'&gt;");
  outputHtml.append("&lt;table border='1'&gt;");
  outputHtml.append("&lt;tbody&gt;");
  
  for (Map.Entry&lt;String, String&gt; entry : parameters.entrySet()) {
      String key = entry.getKey();
      String value = entry.getValue();
      outputHtml.append("&lt;input type='hidden' name='" + key + "' value='" + value + "'&gt;");
  }
  
  outputHtml.append("&lt;input type='hidden' name='CHECKSUMHASH' value='" + checkSum + "'&gt;");
  
  outputHtml.append("&lt;/tbody&gt;");
  outputHtml.append("&lt;/table&gt;");
  outputHtml.append("&lt;script type='text/javascript'&gt;");
  outputHtml.append("document.f1.submit();");
  outputHtml.append("&lt;/script&gt;");
  outputHtml.append("&lt;/form&gt;");
  
  out.print(outputHtml);
  </code></pre>
  
  <p><strong>Here it is submitting using form submission in JavaScript as seen in the below code:</strong></p>
  
  <pre><code>outputHtml.append("&lt;script type='text/javascript'&gt;");
  outputHtml.append("document.f1.submit();");
  outputHtml.append("&lt;/script&gt;");
  </code></pre>
  
  <p>But it seems to be not executing the script sometimes inside the servlet.</p>
  
  <p>So I referred to the <a href="https://github.com/Paytm-Payments/Paytm_Web_Sample_Kit_Java/tree/master/Java%20Kit%201.7" rel="nofollow noreferrer">Paytm Java example</a>.</p>
  
  <p>But, unfortunately, it does not have any code to call service to Paytm.</p>
  
  <p><strong>Am I doing correct by using JavaScript inside the servlet, or should I use Java API instead of the sample JSP kit?</strong></p>